在 Thunderbird 中创建包含主机名和用户名的帐户列表

发布于 2024-12-10 15:53:55 字数 2192 浏览 0 评论 0 原文

我正在开发一个附加组件,需要创建带有主机名和用户名的帐户列表。我可以使用 nsIMsgAccountManager 来做到这一点,但是当我使用手动设置创建新帐户时,主机名会为我提供默认的 imap 服务器名称,即 imap.googlemail.com即使我已将其更改为 192.168.0.25。理想情况下,我应该将主机名设置为 192.168.0.25,但它给了我 imap.googlemail.com。这是我使用的代码:

    var originalAccounts = PrefValue("mail.accountmanager.accounts");
    var allServers = accountManager.allServers;
    var accounts = originalAccounts.split(",");
    var flagFirstItemIsSelected=false;

    for (var i = 0; i < accounts.length; ++i) {
        for (var ii=0; ii < allServers.Count(); ii++) {
            var currentServer = allServers.GetElementAt(ii).QueryInterface(Components.interfaces.nsIMsgIncomingServer);
            var type = currentServer.type;

          alert(accounts[i]);
            if ( accounts[i] == accountManager.FindAccountForServer(currentServer).key) {
                //          if (type == "none" || type == "pop3" || type == "imap" || type == "rss") {
              if(type != "none")
                  {
                    if((currentServer.username.toLowerCase().search("Yahoo".toLowerCase()))==-1&&(currentServer.username.toLowerCase().search("Gmail".toLowerCase()))==-1&&(currentServer.username.toLowerCase().search("Rediffmail".toLowerCase()))==-1)
                    {
                        var theListitem = accountList.appendItem("[" + type + "] - " + currentServer.prettyName, accounts[i]);
                        if(flagFirstItemIsSelected==false)
                        {
                            //accountList.selectItem( theListitem );
                            flagFirstItemIsSelected=true;
                        }
                        theListitem.setAttribute("class", "folderMenuItem listitem-iconic")
                        theListitem.setAttribute("ServerType",type);
                        theListitem.setAttribute("IsServer",true);
                        theListitem.setAttribute("IsSecure",currentServer.isSecure);
                        theListitem.setAttribute("onclick","listClicked()");
                    }
                  }
            }
        }
    } 

请任何人告诉我哪里错了。

I am developing an add-on which needs to create the list of accounts with their host name and username. I am able to do that using nsIMsgAccountManager but when I am creating new account using manual setup the host name appears is giving me the default imap server name i.e. imap.googlemail.com even if i have changed it to 192.168.0.25. Ideally I should get the host name as 192.168.0.25 but it's giving me imap.googlemail.com. This is the code I use:

    var originalAccounts = PrefValue("mail.accountmanager.accounts");
    var allServers = accountManager.allServers;
    var accounts = originalAccounts.split(",");
    var flagFirstItemIsSelected=false;

    for (var i = 0; i < accounts.length; ++i) {
        for (var ii=0; ii < allServers.Count(); ii++) {
            var currentServer = allServers.GetElementAt(ii).QueryInterface(Components.interfaces.nsIMsgIncomingServer);
            var type = currentServer.type;

          alert(accounts[i]);
            if ( accounts[i] == accountManager.FindAccountForServer(currentServer).key) {
                //          if (type == "none" || type == "pop3" || type == "imap" || type == "rss") {
              if(type != "none")
                  {
                    if((currentServer.username.toLowerCase().search("Yahoo".toLowerCase()))==-1&&(currentServer.username.toLowerCase().search("Gmail".toLowerCase()))==-1&&(currentServer.username.toLowerCase().search("Rediffmail".toLowerCase()))==-1)
                    {
                        var theListitem = accountList.appendItem("[" + type + "] - " + currentServer.prettyName, accounts[i]);
                        if(flagFirstItemIsSelected==false)
                        {
                            //accountList.selectItem( theListitem );
                            flagFirstItemIsSelected=true;
                        }
                        theListitem.setAttribute("class", "folderMenuItem listitem-iconic")
                        theListitem.setAttribute("ServerType",type);
                        theListitem.setAttribute("IsServer",true);
                        theListitem.setAttribute("IsSecure",currentServer.isSecure);
                        theListitem.setAttribute("onclick","listClicked()");
                    }
                  }
            }
        }
    } 

Please any one tell me where I am wrong.

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

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

发布评论

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

评论(1

霊感 2024-12-17 15:53:55

不要直接使用 mail.accountmanager.accounts 首选项,而是使用 nsIMsgAccountService.accounts (nsISupportsArray 实例)。实际上有一个关于如何迭代所有帐户的代码示例。您应该查看的属性是 nsIMsgAccount.incomingServer ,它是一个 nsIMsgIncomingServer 实例并具有所有必要的信息。您可能需要属性 realHostNamerealUsername

var accountManager = Components.classes["@mozilla.org/messenger/account-manager;1"]
                               .getService(Components.interfaces.nsIMsgAccountManager);
var accounts = accountManager.accounts;
for (var i = 0; i < accounts.Count(); i++) {
  var account = accounts.QueryElementAt(i, Components.interfaces.nsIMsgAccount);
  var server = account.incomingServer;
  if (server.type == "pop3" || server.type == "imap")
    alert(server.realHostName + " " + server.realUsername)
}

Don't use mail.accountmanager.accounts preference directly, use nsIMsgAccountService.accounts instead (nsISupportsArray instance). There is actually a code example on how one would iterate over all accounts. The property you should look at is nsIMsgAccount.incomingServer which is an nsIMsgIncomingServer instance and has all the necessary information. You probably want the properties realHostName and realUsername:

var accountManager = Components.classes["@mozilla.org/messenger/account-manager;1"]
                               .getService(Components.interfaces.nsIMsgAccountManager);
var accounts = accountManager.accounts;
for (var i = 0; i < accounts.Count(); i++) {
  var account = accounts.QueryElementAt(i, Components.interfaces.nsIMsgAccount);
  var server = account.incomingServer;
  if (server.type == "pop3" || server.type == "imap")
    alert(server.realHostName + " " + server.realUsername)
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文