2011-10-18 17 views
0

ホスト名とユーザー名でアカウントのリストを作成する必要があるアドオンを開発しています。私はnsIMsgAccountManagerを使用してこれを行うことができますが、手動設定を使用して新しいアカウントを作成しているときに、ホスト名が表示されると、192.168.0.25に変更した場合でもデフォルトのIMAPサーバ名がimap.googlemail.comになります。理想的には、ホスト名を192.168.0.25として取得する必要がありますが、それは私にimap.googlemail.comを与えています。これは私が使用しているコードです:Thunderbirdでホスト名とユーザー名を持つアカウントリストを作成する

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

私が間違っている場所を教えてください。

+0

HIすべて私はそれが起こっている理由ANSを発見しました。これは起こっている私は、incommingserver.hosthostnameこれは、ホスト名の変更された値を与える必要があります。 – Rohit

+0

あなたのコードにはそれ以上の問題があります。私の答えを見てください。 –

答えて

0

mail.accountmanager.accountsを直接使用しないでください。代わりにnsIMsgAccountService.accountsnsISupportsArrayインスタンス)を使用してください。実際にはcode example on how one would iterate over all accountsがあります。ご覧になるプロパティは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) 
} 
+0

ありがとうございましたウラジミール私はそれに応じて変更します。 – Rohit

+0

私は1つのことを追加したいと思います:accountManager.accountsを反復処理すると、Thunderbirdの作成エディタとは異なる順序でアカウントとIDを受け取ります。あなたのアドオンではこれは問題ではないかもしれませんが、それはただ知っておくべきことです。 – speedball2001

関連する問題