I'm building a Thunderbird extension and would like to add my own header to all outgoing email (e.g. <myext-version: 1.0> ). Any idea how to do this? I know it's possible since this is done in the OpenPGP Enigmail extension. Thanks!
I don't know the answer but just some thoughts...
I think thunderbird extensions are usually just xul and js. From the enigmail site:
Unlike most Mozilla AddOns, Enigmail contains platform dependent parts: it depends on the CPU, the compiler, libraries of the operating system and the email application it shall integrate into.
Looking at the Enigmail source code, this might be the relevant section (written in c++)
So you might need to either translate what they've done into js(!) or keep looking for a different example.
Hi, I copy&pasted relevant parts of TB header extension plugin that modifies the headers in plain xul/js.
Here is the code from one extension i'm working on:
function SendObserver() { this.register(); } SendObserver.prototype = { observe: function(subject, topic, data) { /* thunderbird sends a notification even when it's only saving the message as a draft. * We examine the caller chain to check for valid send notifications */ var f = this.observe; while (f) { if(/Save/.test(f.name)) { print("Ignoring send notification because we're probably autosaving or saving as a draft/template"); return; } f = f.caller; } // add your headers here, separated by \r\n subject.gMsgCompose.compFields.otherRandomHeaders += "x-test: test\r\n"; } }, register: function() { var observerService = Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService); observerService.addObserver(this, "mail:composeOnSend", false); }, unregister: function() { var observerService = Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService); observerService.removeObserver(this, "mail:composeOnSend"); } }; /* * Register observer for send events. Check for event target to ensure that the * compose window is loaded/unloaded (and not the content of the editor). * * Unregister to prevent memory leaks (as per MDC documentation). */ var sendObserver; window.addEventListener('load', function (e) {if (e.target == document) sendObserver = new SendObserver(); }, true); window.addEventListener('unload', function (e) { if (e.target == document) sendObserver.unregister();}, true);
put this inside a .js file that is loaded by the compose window (for example by overlaying chrome://messenger/content/messengercompose/messengercompose.xul).
The check in SendObserver.observe was necessary in my case because i wanted to do a user interaction, but you could probably leave it out.