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.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)
}
于 2011-10-18T11:21:26.537 に答える