如何插入带有Thunderbird扩展名的电子邮件标题?
时间:2020-03-06 15:01:25 来源:igfitidea点击:
我正在构建Thunderbird扩展程序,并希望将自己的标头添加到所有传出电子邮件中(例如<myext-version:1.0>)。任何想法如何做到这一点?我知道这是可能的,因为这是在OpenPGP Enigmail扩展中完成的。谢谢!
解决方案
我不知道答案,只是一些想法...
我认为雷鸟扩展通常只是xul和js。从enigmail网站:
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.
查看Enigmail源代码,这可能是相关的部分(用c ++编写)
因此,我们可能需要将他们所做的事情翻译成js(!)或者继续寻找其他示例。
这是另一个可能有用的链接
这是我正在处理的一个扩展中的代码:
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进行检查,因为我想进行用户交互,但是我们可以将其忽略。