This is my code :
var newMailListener = {
msgAdded: function(aMsgHdr) {
if(!aMsgHdr.isRead) {
gFolderDisplay.selectMessage(aMsgHdr);
var uri = gFolderDisplay.selectedMessageUris;
alert(uri);
msgHdr = messenger.messageServiceFromURI(uri).messageURIToMsgHdr(uri);
alert(getMessageBody(msgHdr,uri));
goDoCommand("cmd_markAsRead");
}
}
};
function init() {
var ancienmsg = null;
var notificationService = Components.classes["@mozilla.org/messenger/msgnotificationservice;1"]
.getService(Components.interfaces.nsIMsgFolderNotificationService);
notificationService.addListener(newMailListener, notificationService.msgAdded);
}
addEventListener("load", init, true);
function getMessageBody(aMessageHeader, uri)
{
let messenger = Components.classes["@mozilla.org/messenger;1"] .createInstance(Components.interfaces.nsIMessenger);
alert("charge messenger");
let listener = Components.classes["@mozilla.org/network/sync-stream-listener;1"].createInstance(Components.interfaces.nsISyncStreamListener);
alert("charge listener");
messenger.messageServiceFromURI(uri)
.streamMessage(uri, listener, null, null, false, "");
let folder = aMessageHeader.folder;
alert("initialise messenger");
return folder.getMsgTextFromStream(listener.inputStream,
aMessageHeader.Charset,
65536,
32768,
false,
true,
{ });
}
It is supposed, according to the mozilla's documentation, to display, in an alert, the body of the mail received. But, every time during the return of the getMessageBody method, thunderbird crash and I need to restart it. Does anybody have an idea of why and how to display it ?
In another Stackoverflow question, I find this and it works for me.
But you only get the text and not the HTML.