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
var attachmentList = document.getElementById( 'attachmentList' ) // returns attachment list
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
var msg = messenger.messageServiceFromURI(uri); // get message object
var hdr = msg.messageURIToMsgHdr(uri); // get header object
var subject = hdr.mime2DecodedSubject; // get Subject
var from = hdr.mime2DecodedAuthor; // get From
var to = hdr.mime2DecodedRecipients; // get To
var msgdate = new Date( hdr.date/1000); // turn epoch into date
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.
attachments = this.getSelectedAttachments();
for( i=0;i
var attachment = attachments[i];
/* Create a file interface object */
var file = Components.classes["@mozilla.org/file/local;1"].
createInstance(Components.interfaces.nsILocalFile);
var fullfilepath = 'C:/test/' + attachment.displayName;
file.initWithPath(fullfilepath);
if(!file.exists()) {
file.create(0x00,0644);
}
messenger.saveAttachmentToFile( file, attachment.url, attachment.uri, attachment.contentType, null );
}
6 comments:
Thank you kindly for this summary. Do you have a minor error on Line 10 where fullfile should really be fullfilePath. I wonder if you could venture an opinion on how difficult it would be to save an attachment, process that attachment using a local script then suck up the text output of the script into an edit or reply window for further annotation by the TB user.
Thank you very much for this!
I went to the same conclusion as you:
- FF tutorial stuff is pretty big, but TB stuff = 0 (almost)
- I was looking for these specific functions too without finding them
Thanx again and keep this blog working with future good remarks or ideas as you do
@JosephSant Not really sure...as you would have to have some type of delay in opening the reply window...but where there is a will there is a way. I know you can open local files....so maybe once the attachment is downloaded do the processing by the plugin itself and not a local script and then you'll know when to open the reply window.
@Anonymous That is the exact reason I posted this. I havent done too much more TB plugin dev work but If you have questions you can always post them and I can see if I can find an answer.
Hello,
thank you very much for this documentation. I would like to automatically save attachments of new messages. Because of that I think I need another source for the attachment array than this.getElementById(). Can you please help me.
thx
Thank sir! I'm Wisuttipong from Thailand
Post a Comment