Every PDF files has a document action called "Document Will Close", which
is executed just before the document is closed. You might be able to use
that to do the "clean up" you want to do, although it might be tricky
getting a reference to the main document.
So I was looking if attachment can signal mail document somehow that it is closing
You can try to use a global object to pass a reference of the main doc
object to the attached file, and then use it in the WillClose event.
yes it worked. I have passed mail document to attachment and did all cleanup process in attachment script.