Thunderbird - 获取用户电子邮件地址

Thunderbird - Get the user email address

我正在开发一个 Mozilla Thunderbird 插件,需要获取用户的电子邮件地址。

问题:如何找回这个地址?

我会在 JavaScript 中使用它。

您首先应该记住,一个用户可以有多个电子邮件地址(来自多个帐户,甚至一个帐户有多个身份),您必须决定您对哪一个感兴趣。

注意:可能存在比下面描述的更简单的方法,例如现有 Thunderbird 代码中的辅助函数。您可以尝试搜索 comm-central

您必须以某种方式获得您感兴趣的身份的 nsIMsgIdentity。它有一个 email 属性,电子邮件地址是一个字符串。

获取所有身份的一种方法应该是通过 nsIMsgAccountManagerallIdentities(未测试)。

使用以下代码获取nsIMsgAccountManager

Components.utils.import("resource:///modules/mailServices.js");
let accountManager = MailServices.accounts

如果您有 nsIMsgIdentitynsIArray,您可以使用以下代码循环遍历它们:

for (let identity in fixIterator(identities, Components.interfaces.nsIMsgIdentity)) {
}

可能有用的参考资料:

一些有趣的界面概述: https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Account_interfaces

一些账户示例代码: https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Account_examples