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

Jonathan Protzenko jonathan.protzenko at gmail.com
Thu Nov 10 12:55:17 UTC 2011


Yes, absolutely. My code uses the newer function if available, or 
resorts to a less efficient version (i.e. streaming the entirety of the 
message) if it's not there. It's compatible with Thunderbird 3+ :).

Thanks for asking,

jonathan

On Thu 10 Nov 2011 11:28:00 AM CET, Guenter Wahl wrote:
> Hi Jonathan,
>
> once more EXCELLENT, thanks.
>
>
> One question: you say ".. a function on top of that .." on top of Davids code which is for TB10. But you also say your code runs for older TB versions. So, I'm confused .. does your code work with TB6/7 as well?
>
> Günter
>
> -------- Original-Nachricht --------
>> Datum: Thu, 10 Nov 2011 10:26:51 +0100
>> Von: Jonathan Protzenko<jonathan.protzenko at gmail.com>
>> An: tb-planning at mozilla.org, dev-apps-thunderbird at lists.mozilla.org, dev-extensions at lists.mozilla.org
>> Betreff: Useful code snippet: getting the headers of an email (nsIMsgDBHdr)
>
>> 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.
>>
>> https://github.com/protz/thunderbird-stdlib/blob/master/msgHdrUtils.js#L428
>>
>> (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
>



More information about the tb-planning mailing list