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

发布于 2024-07-06 17:46:10 字数 156 浏览 4 评论 0原文

我正在构建 Thunderbird 扩展,并希望将我自己的标头添加到所有传出电子邮件中(例如)。 知道如何做到这一点吗? 我知道这是可能的,因为这是在 OpenPGP Enigmail 扩展中完成的。 谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁吢 2024-07-13 17:46:10

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

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 中的检查是必要的,因为我想要进行用户交互,但您可能可以将其省略。

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.

半山落雨半山空 2024-07-13 17:46:10

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

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

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

查看 Enigmail 源代码, 这可能是相关部分(用 c++ 编写)

因此您可能需要将他们所做的事情翻译成 js(!) 或继续寻找不同的示例。

这是另一个可能有用的链接

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文