Accessing Thunderbird message when closing message tab / window

We have developed a Thunderbird plugin (11) that allows us to save the contents of a message to disk. We are now extending this extension to allow automatic message handling when it is closed. We face a number of problems:

We cannot find a way to connect to the "close tab" event. We're also having trouble getting message URIs from currently open tabs (we're currently trying to catch click and keyboard events). This information doesn't seem to be available in the DOM of the tab container.

Is there a way to detect the closure of a bookmark or mailing window in a generic way, along with getting the URI of the closed mailing for further processing?

We've looked at the tab container documentation NsIWindowMediator

, tried various event listeners, but no luck so far.

Edit: We're getting some results using the latest closed tabs list. Not a very neat solution, but at least we have a tab link. Now we only need to get the URI for the message contained within the tab.

+3


source to share


2 answers


We cannot find a way to connect to the "close tab" event.

( poorly documented ) Element <tabmail>

allows you to register tab monitors. Something like this should work:

var tabmail = document.getElementById("tabmail");
var monitor = {
  onTabClosing: function(tab)
  {
    ...
  }
};
tabmail.registerTabMonitor(monitor);

      

We're also having trouble getting the message URIs of the currently open tabs



The element <tabmail>

has a property tabInfo

containing information about the currently open tabs. You probably only want to look at the tabs where it mode.name

is "message"

(there are also many other modes, such as "folder"

or "contentTab"

). This mode has a method getBrowser()

, so something like this should do:

var tabmail = document.getElementById("tabmail");
for (var i = 0; i < tabmail.tabInfo.length; i++)
{
  var tab = tabmail.tabInfo[i];
  if (tab.mode.name == "message")
    alert(tab.mode.getBrowser().currentURI.spec);
}

      

Edit . As Peter points out in the comments, the approach to getting the URI for a message will only work with the currently loaded message - all tabs reuse the same browser element for mail messages. Getting the correct URI is more complicated, you have to get an nsIMsgDBHdr

instance
to post through TabInfo.folderDisplay.selectedMessage

and then use nsIMsgFolder.getUriForMsg()

to build a URI for it:

var tabmail = document.getElementById("tabmail");
for (var i = 0; i < tabmail.tabInfo.length; i++)
{
  var tab = tabmail.tabInfo[i];
  if (tab.mode.name != "message")
    continue;
  var message = tab.folderDisplay.selectedMessage;
  alert(message.folder.getUriForMsg(message));
}

      

+4


source


For the second part of the question:

The following example code will give you the msgDBHdr objects of all open tabs. You have to do some type checks to avoid accessing the message in the calendar tab.):

tabInfos = window.document.getElementById("tabmail").tabInfo;
for (i = 0; i < tabInfos.length; i++) {      
  msgHdr = tabInfos[i].folderDisplay.selectedMessage;
  alert(
    msgHdr.mime2DecodedSubject+"\n"
   +msgHdr.messageId+"\n"
   +"in view type "+tabInfos[i].mode.type
  );
}

      



The tabinfo entries contain additional interesting information. Just open ErrorConsole and run

top.opener.window.document.getElementById("tabmail").tabInfo[0].toSource()

      

and read it carefully.

0


source







All Articles