Useful code snippet: getting the headers of an email (nsIMsgDBHdr)

Jennifer Zickerman jzickerman at
Wed Nov 16 01:20:34 UTC 2011

I made a note of this on MDN:

Thanks protz!


On 11-11-10 1:26 AM, Jonathan Protzenko wrote:
> Hi all,
> I'm posting this here in the hope that it's useful to other addon 
> developers, and that it shows up in search results.
> Recently (Thunderbird 10), David Bienvenu kindly implemented a new 
> function that allows one to quickly grab the headers part of a given 
> message body. This is very useful: if the message has attachments, we 
> won't be downloading the entire body just to get the headers.
> I wrote a function on top of that that does the dirty work to *get the 
> MIME headers of an email* in Thunderbird. It provides a nice API on 
> top of David's function, and is also able to work with older versions 
> of Thunderbird.
> (I'm not copy/pasting the whole code here because there's a stream 
> listener involved and some other stuff. As usual, you can grab my 
> thunderbird-stdlib project to use the function right away.)
> *Here's how you use it:*
>     msgHdrGetHeaders(gFolderDisplay.selectedMessage, function (aHeaders) {
>       if (aHeaders.has("reply-to"))
>         dump("This message has a reply-to header; its value is
>     "+aHeaders.get("reply-to")+"\n");
>     });
> This allows you to get the headers of any message (not just the one 
> that's displayed, like in the example). It's particularly useful when 
> you have an nsIMsgDBHdr, and you want to inspect it.
> Let me know if you have any suggestions / bug reports / ideas :)
> Cheers,
> jonathan
> _______________________________________________
> tb-planning mailing list
> tb-planning at

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the tb-planning mailing list