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()");
                    }
                  }
            }
        }
    } 

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

4

1 回答 1

0

不要mail.accountmanager.accounts直接使用首选项,nsIMsgAccountService.accounts而是使用(nsISupportsArray实例)。实际上有一个关于如何遍历所有帐户的代码示例。您应该查看的属性nsIMsgAccount.incomingServernsIMsgIncomingServer实例并具有所有必要的信息。您可能需要属性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)
}
于 2011-10-18T11:21:26.537 回答