Wednesday, February 11, 2009

Thunderbird Extension Development

I've spent the last two weeks developing a thunderbird(tb) extension and I must say trying to find information specific to tb development is very hard to come by. Firefox plugin development information is all over the place. But tb resources are hard to come by. I have put together a quick reference that will hopefull get crawled by google and maybe give some help to others that are trying to do the same thing. Please not that this is just a qucik reference, of things I foudn to get the job done...they might not be the best method of doing things but it gets the job done.

Thunderbird Extension Development


Overlay Reference:

  • chrome://messenger/content/messenger.xul- statusbar

  • chrome://messenger/content/mailWindowOverlay.xul- Toolbar Menu (taskPopup), Message Context Menu (threadPaneContext)

  • chrome://messenger/content/msgHdrViewOverlay.xul- Attachment Context Menu (attachmentListContext)

Accessing Attachments

  1. var attachmentList = document.getElementById( 'attachmentList' ) // returns attachment list

  2. var selectedAttachments = attachmentList.selectedItems; //Get selected attachments


Getting Message Information

var MessageUri = GetFirstSelectedMessage(); // Get Message URI


/* Get message body as it appears in preview window */

body = document.getElementById("messagepane").contentDocument.body.innerHTML;


Accessing Limited Message Header information

  1. var msg = messenger.messageServiceFromURI(uri); // get message object

  2. var hdr = msg.messageURIToMsgHdr(uri); // get header object

  3. var subject = hdr.mime2DecodedSubject; // get Subject

  4. var from = hdr.mime2DecodedAuthor; // get From

  5. var to = hdr.mime2DecodedRecipients; // get To

  6. var msgdate = new Date( hdr.date/1000); // turn epoch into date

  7. var messageid = hdr.messageId; // get message ID



Downloading Attachments

This piece of code will take all selected attachments and download them to C:\ with their original filenames.


  1. attachments = this.getSelectedAttachments();

  2. for( i=0;i

  3. var attachment = attachments[i];


  4. /* Create a file interface object */

  5. var file = Components.classes["@mozilla.org/file/local;1"].

  6. createInstance(Components.interfaces.nsILocalFile);

  7. var fullfilepath = 'C:/test/' + attachment.displayName;

  8. file.initWithPath(fullfilepath);

  9. if(!file.exists()) {

  10. file.create(0x00,0644);

  11. }

  12. messenger.saveAttachmentToFile( file, attachment.url, attachment.uri, attachment.contentType, null );

  13. }

Post a Comment