How do you insert email headers with a Thunderbird extension?

孤街醉人 提交于 2019-12-09 16:43:17

问题


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!


回答1:


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.




回答2:


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.

Here's another link that might be helpful



来源:https://stackoverflow.com/questions/162057/how-do-you-insert-email-headers-with-a-thunderbird-extension

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!