7

Thunderbird 拡張機能を作成していて、すべての送信メールに独自のヘッダーを追加したいと考えています (例: <myext-version: 1.0> )。これを行う方法はありますか?これは OpenPGP Enigmail 拡張機能で行われるため、可能であることはわかっています。ありがとう!

4

2 に答える 2

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 のチェックは必要でした。ユーザー インタラクションを実行したかったからですが、省略してもかまいません。

于 2009-03-26T14:49:02.177 に答える
1

答えはわかりませんが、少し考えてみます...

Thunderbird の拡張機能は通常 xul と js だけだと思います。enigmail サイトから:

ほとんどの Mozilla AddOn とは異なり、Enigmail にはプラットフォームに依存する部分が含まれています。つまり、CPU、コンパイラ、オペレーティング システムのライブラリ、および統合する電子メール アプリケーションに依存します。

Enigmail のソース コードを見ると、これが関連するセクションである可能性があります(c++ で記述)。

したがって、彼らが行ったことを js(!) に変換するか、別の例を探し続ける必要があるかもしれません。

ここに役立つかもしれない別のリンクがあります

于 2008-10-23T12:40:05.947 に答える