The Deep End

go to graworks.com! email!

Thursday, February 24, 2005

Thunderbird Extensions: Opening a Compose Window

Previous posts have made vague and mysterious allusions to "opening a compose window" and to clear that up, here's how:

There are actually a multitude of ways to open a compose window, but most of them will have nsIMsgComposeParams and nsIMsgComposeService.

The way I found it done was in the DictionarySearch extension (this is a little bit different from his version but not much):

function composeMessageWithText(subject,text,type,format){
var msgComposeType = Components.interfaces.nsIMsgCompType;
var msgComposFormat = Components.interfaces.nsIMsgCompFormat;
var msgComposeService = Components.classes['@mozilla.org/messengercompose;1'].getService();
msgComposeService = msgComposeService.QueryInterface(Components.interfaces.nsIMsgComposeService);

gAccountManager = Components.classes['@mozilla.org/messenger/account-manager;1'].
getService(Components.interfaces.nsIMsgAccountManager);

var params = Components.classes['@mozilla.org/messengercompose/composeparams;1'].
createInstance(Components.interfaces.nsIMsgComposeParams);
if (params)
{
params.type = msgComposeType.Template;
params.format = format;
var composeFields = Components.classes['@mozilla.org/messengercompose/composefields;1'].
createInstance(Components.interfaces.nsIMsgCompFields);
if (composeFields)
{
composeFields.to = "foo@foo.net"
text = trimAll(text);
composeFields.body = text;
composeFields.subject = subject;


params.composeFields = composeFields;

msgComposeService.OpenComposeWindowWithParams(null, params);
}
}
}

The other ways are all through msgComposeService; for the nsIMsgWindow parameter, type msgWindow. This works because...msgWindow is always the right menu? At any rate, it always works. Which is nice, even if it is complicated.

0 Comments:

Post a Comment

<< Home