如何使用Thunderbird扩展插入电子邮件标头?

时间:2008-10-02 12:41:42

标签: thunderbird

我正在构建Thunderbird扩展程序,并希望将自己的标头添加到所有外发电子邮件中(例如< myext-version:1.0>)。知道怎么做吗?我知道这是可能的,因为这是在OpenPGP Enigmail扩展中完成的。谢谢!

2 个答案:

答案 0 :(得分:3)

以下是我正在处理的一个扩展程序的代码:

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);

将此内容放在由撰写窗口加载的.js文件中(例如,通过覆盖chrome://messenger/content/messengercompose/messengercompose.xul)

在我的情况下检查SendObserver.observe是必要的,因为我想进行用户交互,但你可能会把它留下来。

答案 1 :(得分:1)

我不知道答案,只是一些想法...

我认为thunderbird扩展通常只是xul和js。来自enigmail网站:

  

与大多数Mozilla AddOns,Enigmail不同   包含平台相关部分:它   取决于CPU,编译器,   操作系统和库的库   电子邮件应用程序   融入。

查看Enigmail源代码this might be the relevant section(用c ++编写)

所以你可能需要将他们所做的事情翻译成js(!)或者继续寻找不同的例子。

Here's another link that might be helpful