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

Jonathan Protzenko jonathan.protzenko at
Thu Nov 10 09:26:51 UTC 2011

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 

(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

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 :)


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

More information about the tb-planning mailing list