2008-10-02 30 views
7

我正在構建一個Thunderbird擴展程序,並希望將我自己的標題添加到所有外發電子郵件(例如< myext-version:1.0 >)。任何想法如何做到這一點?我知道這是可能的,因爲這是在OpenPGP Enigmail擴展中完成的。謝謝!如何用Thunderbird擴展插入電子郵件標題?

+0

這不屬於superuser.com嗎? – 2011-06-01 15:08:59

回答

1

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

我認爲雷鳥擴展通常只是XUL和js。從的enigmail網站:

不像大多數的Mozilla插件,Enigmail中 包含平臺相關的部分:它 取決於CPU,編譯器,操作系統的 庫和 的電子郵件應用程序應當 融入。

望着Enigmail中的源代碼,this might be the relevant section(用C++)

所以,你可能需要或者翻譯他們做了什麼到JS(!),或不停地尋找不同的例子。

Here's another link that might be helpful

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

將這個由撰寫窗口(例如通過加載覆蓋chrome://messenger/content/messengercompose/messengercompose.xul) .js文件裏面。

在我的情況下,SendObserver.observe中的檢查是必要的,因爲我想做一個用戶交互,但你可能會把它留在外面。