Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[thunderbird] Replace displayed message in Message Pane

59 views
Skip to first unread message

Nicolas Lascombes

unread,
Apr 3, 2013, 9:40:11 AM4/3/13
to dev-ext...@lists.mozilla.org
Hello,
I am working on a Thunderbird extension for a HSM solution. The
solution archive mails on IMAP server by copying mail in a storage
other than cyrus and modify the existing mail to keep only a light
version.
The goal of the Thunderbird (10.0 at least) extension is when viewing
an archived mail to view instead the full version.
What know howto do:
- extend msgHdrViewOverlay.xul to detect the specific header saying
that the mail is light version of archived mail
- get the original full source of mail from archive server
- create the original mail in a tbird folder: injecting source in a
temp file and using nsIMsgCopyService.CopyFileMessage
What I don't know how to do:
- replace the currently viewed mail in Message Pane by the original content.

Thanks for your guidelines or tips.

--
Nicolas Lascombes - http://blue-mind.net

Nicolas Froidure

unread,
Apr 4, 2013, 7:29:43 AM4/4/13
to dev-ext...@lists.mozilla.org
Hi Nicolas,

I recently had a similar work to do. You can add an onload listener
to the TB main window and replace DOM elements on the fly. Here is a
sample code from CapsKiller :
https://github.com/nfroidure/CapsKiller/blob/master/thunderbird/chrome/capskiller/content/content.js#L111

Have a nice day.
> _______________________________________________
> dev-extensions mailing list
> dev-ext...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-extensions
>
>

Nicolas Lascombes

unread,
Apr 8, 2013, 5:07:13 AM4/8/13
to Nicolas Froidure, dev-ext...@lists.mozilla.org
On Thu, Apr 4, 2013 at 1:29 PM, Nicolas Froidure
<froidure...@yahoo.fr> wrote:
> Hi Nicolas,
>
> I recently had a similar work to do. You can add an onload listener to
> the TB main window and replace DOM elements on the fly. Here is a sample
> code from CapsKiller :
> https://github.com/nfroidure/CapsKiller/blob/master/thunderbird/chrome/capskiller/content/content.js#L111
>
> Have a nice day.
>
Thank you for the method to replace the DOM on the fly (I also learned
howto use nsIMsgFilterService in your source code).
But I want to replace more. I want to completely replace the content
of MessagePane including headers and attachments overlay.
The scenario is:
- the user select an archived message in message list
- I fetch the original message from archive server in a temporary .eml file
- I want to render the eml message in Messagepane replacing the render
of selected message.

Jonathan Protzenko

unread,
Apr 8, 2013, 5:34:27 AM4/8/13
to Nicolas Lascombes, dev-ext...@lists.mozilla.org, Nicolas Froidure
You could use the multimessage pane, which is basically an HTML
document, then inject into it whatever you need.

gMessageDisplay.singleMessageDisplay = false; // makes the multimessage
pane visible
let w = document.getElementById("multimessage").contentDocument;
w.body.innerHTML = "<h1>Hello, world</h1>";

This is the method used by the thread summary and the multimessage
summaryu.

Nicolas Lascombes

unread,
Apr 8, 2013, 4:16:08 PM4/8/13
to Jonathan Protzenko, dev-ext...@lists.mozilla.org, Nicolas Froidure
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
0 new messages