[Discuss] Extension dev : adding custom headers to email before
sending it
Yoann Babel
yoann.babel at aliacom.fr
Wed Aug 2 11:04:31 EDT 2006
Hi,
I'm new to Thunderbird dev !
I'm trying to write an extension. I would like to add custom headers
before sending an email. I know "enigmail" already does thing like that.
But, there's to many thing I don't know, and even by reading enigmail
source code, I'm lost. I've been programming for many years, but I'm new
to Javascript. And I don't know where to begin.
I have installed DOM instpector and "Dev extension". It work pretty good.
For the moment I would like to add an hard coded header like this one :
X-MyHeader: customeheadervalue.
I tried this little script in the JavaScript Environement of the
"Extension Developper" menu :
*Code:*
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 = "*yoann*.babel at aliacom.fr"
composeFields.body = text;
composeFields.otherRandomHeaders = "X-MyHeader: customeheadervalue";
composeFields.subject = subject;
params.composeFields = composeFields;
msgComposeService.OpenComposeWindowWithParams(null, params);
}
}
}
composeMessageWithText("test JS compose","avec un champ
supplémentaire","type","format")
It nearly works, I see my special extension in the composer, but, the
Send button won't work any more.
I tried to go further in the code and hook "GenericSendMessage" but I
don't know how to get the composer window (And I spent lot of time
searching a sample code to do that).
I tried to observe "mail:composeOnSend" but, for the moment I would like
to avoid writing a full extension an use the "JavaScript Environement"
to toy and test things !
Because, even if I write a full extension, I still don't know where
should I plugg...
regards,
Yoann
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mozdev.org/pipermail/discuss/attachments/20060802/35fe8d65/attachment.htm
More information about the Discuss
mailing list