0

i am developing a thunderbird extension.i want to get the mailitem content in home window and compose mail window.How can i achieve this?

Regards Sanju

Arjun babu
  • 607
  • 2
  • 13
  • 42

1 Answers1

1

When you are interested in how something is done in one of the Thunderbird windows, the way to figure out how it is implemented in the XUL DOM is to install the [add-on][2] [DOM Inspector][3] and use it to investigate what the contents of the DOM looks like. You probably also want, the [Element Inspector][4] add-on which is a very useful addition to the DOM Inspector (shift-right-click opens the DOM Inspector to the element clicked). You might also find [Stacked Inspector][5] helpful.

The other thing to do is find an extension that does something in the same general area in which you are wanting to work. Then download that extension and see how they did the thing you are interested in.

Your question does not provide enough information to give you an exact, detailed response. We need to know the context in which you are running. Was the script that is being run launched as part of a UI event from the main window? A UI event from the compose window?

If the script was launched from a UI event in the compose window, you can get access to the message content with:

let editor = document.getElementById("content-frame");
let editorDocument = editor.contentDocument;
let messageBody = editorDocument.getElementsByTagName("body")[0];

This should work, but I have not verified it:

let messageBody = document.getElementById("content-frame").contentDocument.body;

As to the home window: The message content is located in a <browser id="messagepane"> element. Once you have the tab, you should be able to find the <browser> from there.

In Firefox, you can find the <browser> element with:

//Create some common variables if they do not exist.
//  This should work from any Firefox context.
//  Depending on the context in which the function is being run,
//  this could be simplified.
if (typeof window === "undefined") {
    //If there is no window defined, get the most recent.
    var window=Components.classes["@mozilla.org/appshell/window-mediator;1"]
                       .getService(Components.interfaces.nsIWindowMediator)
                       .getMostRecentWindow("navigator:browser");
}
if (typeof document === "undefined") {
    //If there is no document defined, get it
    var document = window.content.document;
}
if (typeof gBrowser === "undefined") {
    //If there is no gBrowser defined, get it
    var gBrowser = window.gBrowser;
}

//Get the current tab & browser.
let tab = gBrowser.selectedTab;
let browserForTab = gBrowser.getBrowserForTab( tab );

It should be similar in Thunderbird.

Makyen
  • 31,849
  • 12
  • 86
  • 121
  • Thanks for ur reply Makyen.the compose window sample not returns a content in alert box.it returns like [object XrayWrapper[object HTMLBodyElement]] and home window sample not working,i mean alert not displayed. – Arjun babu Sep 29 '14 at 07:05