We have developed a Thunderbird (11) plugin that allows us to save the content of a message to disk. Now we are extending this extension to allow automatic processing of a message when you close it. We run into a number of issues:
We cannot find a way to hook into a ‘close tab’ event. We are also having trouble getting the Message URI of the currently open tabs (we are trying catching click and keyboard events now). This information does not appear to be available in the DOM of the tab container.
Is there a way to detect closing of a mail message tab or window in a generic way, together with retrieving the URI of the closed mail message for further processing?
We have looked at the documentation of the tab container, the NsIWindowMediator, tried various event listeners, but no luck so far.
Edit: We are getting some results using the most recently closed tabs list. Not a very elegant solution but at least we have a reference to the tab. Now we only have to get the URI to the message that was contained inside the tab.
The (badly documented)
<tabmail>element allows registering tab monitors. Something like this should work:The
<tabmail>element has a propertytabInfocontaining information on the currently open tabs. You probably want to look only at the tabs wheremode.nameis"message"(there is a bunch of other modes as well, e.g."folder"or"contentTab"). This mode has agetBrowser()method, so something like this should do:Edit: As Peter points out in the comments, the approach to get the URI for a message will only work the currently loaded message – all tabs reuse the same browser element for the mail messages. Getting the URI properly is more complicated, you have to get the
nsIMsgDBHdrinstance for the message viaTabInfo.folderDisplay.selectedMessageand then usensIMsgFolder.getUriForMsg()to construct the URI for it: