After juggle with msgHdr, uri and reading source code of Thunderbird I
finally get the solution.
Here is the commented code:
// We are in onEndHeaders of a listener registered on
"messagepane-loaded" event in an overlay of msgHdrViewOverlay.xul
// an archived message is displayed, aContent is the full source of
original message fetched from HSM archive server.
let tempFile = Components.classes["@
mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get("TmpD", Components.interfaces.nsIFile);
tempFile.append("BM.eml");
tempFile.createUnique(0, 0600);
// Create a temp eml file an put the original full source within
let foStream = Components.classes["@
mozilla.org/network/file-output-stream;1"]
.createInstance(Components.interfaces.nsIFileOutputStream);
foStream.init(tempFile, 2, 0x200, false);
foStream.write(aContent, aContent.length);
foStream.close();
// Get a nsIURL from temp file
let fileSpec = Components.classes["@
mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
fileSpec.initWithPath(tempFile.path);
let uri = Services.io.newFileURI(fileSpec);
let url = uri.QueryInterface(Components.interfaces.nsIURL);
url.query = "type=application/x-message-display";
// Get a dummy nsIMsgDBHdr
let emlHdr = messenger.msgHdrFromURI(url.spec);
// Display message in replace of currently displayed
gMessageDisplay.aboutToLoadMessage = true;
gFolderDisplay.view.dbView.loadMessageByUrl(url.spec);
// Set new displayedMessage
gMessageDisplay.displayedMessage = emlHdr;
Full code here:
https://forge.blue-mind.net/redmine/projects/bluemind/repository/revisions/master/entry/mozilla/bm-connector-tb/src/chrome/content/msgHdrViewOverlay.js#L134