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

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


I made a note of this on MDN:

https://developer.mozilla.org/en/Extensions/Thunderbird/HowTos/Common_Thunderbird_Use_Cases/View_Message#Get_MIME_Header_for_any_message

Thanks protz!


jen.

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.
>
> 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
>
>
> _______________________________________________
> tb-planning mailing list
> tb-planning at mozilla.org
> https://mail.mozilla.org/listinfo/tb-planning

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/tb-planning/attachments/20111115/add1a873/attachment.html>


More information about the tb-planning mailing list