Bug 742238 - Unified view loses some folders and does not allow reset, r+a=bienvenu.
authorFlorian Quèze <florian@queze.net>
Mon, 23 Apr 2012 17:13:11 +0200
changeset 11245 ef0b70ed8c0e2f6ece7818be01dbe0d9acf73bbc
parent 11244 b07948bdab69320f50777a536bb48b6ffc6b70a1
child 11246 88ca33153d6aec52c9db181f3ecffb2723692cf9
push id463
push userbugzilla@standard8.plus.com
push dateTue, 24 Apr 2012 17:34:51 +0000
treeherdercomm-beta@e53588e8f7b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs742238
Bug 742238 - Unified view loses some folders and does not allow reset, r+a=bienvenu.
mail/base/content/folderPane.js
mail/base/content/mailWindowOverlay.js
mailnews/base/content/folderWidgets.xml
mailnews/base/prefs/content/amUtils.js
mailnews/base/public/nsIMsgAccountManager.idl
mailnews/base/src/nsMsgAccountManager.cpp
--- a/mail/base/content/folderPane.js
+++ b/mail/base/content/folderPane.js
@@ -1711,28 +1711,25 @@ let gFolderTreeView = {
    */
   get _enumerateFolders() {
     const Cc = Components.classes;
     const Ci = Components.interfaces;
     let folders = [];
 
     let acctMgr = Cc["@mozilla.org/messenger/account-manager;1"]
                      .getService(Ci.nsIMsgAccountManager);
-    for each (let acct in fixIterator(acctMgr.accounts, Ci.nsIMsgAccount)) {
+    for each (let server in fixIterator(acctMgr.allServers, Ci.nsIMsgIncomingServer)) {
       // Skip deferred accounts
-      if (acct.incomingServer instanceof Ci.nsIPop3IncomingServer &&
-          acct.incomingServer.deferredToAccount)
+      if (server instanceof Ci.nsIPop3IncomingServer &&
+          server.deferredToAccount)
         continue;
 
-      // Skip IM accounts
-      if (acct.incomingServer.type == "im")
-        continue;
-
-      folders.push(acct.incomingServer.rootFolder);
-      this.addSubFolders(acct.incomingServer.rootFolder, folders);
+      let rootFolder = server.rootFolder;
+      folders.push(rootFolder);
+      this.addSubFolders(rootFolder, folders);
     }
     return folders;
   },
 
   /**
    * This is a recursive function to add all subfolders to the array. It
    * assumes that the passed in folder itself has already been added.
    *
--- a/mail/base/content/mailWindowOverlay.js
+++ b/mail/base/content/mailWindowOverlay.js
@@ -2295,18 +2295,17 @@ function IsMailFolderSelected()
 }
 
 function IsGetNewMessagesEnabled()
 {
   let allServers = accountManager.allServers;
   for (let i = 0; i < allServers.Count(); ++i) {
     let server = allServers.GetElementAt(i)
                            .QueryInterface(Components.interfaces.nsIMsgIncomingServer);
-    let type = server.type;
-    if (type == "im" || type == "none")
+    if (server.type == "none")
       continue;
     return true;
   }
   return false;
 }
 
 function IsGetNextNMessagesEnabled()
 {
--- a/mailnews/base/content/folderWidgets.xml
+++ b/mailnews/base/content/folderWidgets.xml
@@ -273,72 +273,65 @@
         <body><![CDATA[
           if (this._initialized)
             return;
 
           // I really wish they'd just make this global...
           const Cc = Components.classes;
           const Ci = Components.interfaces;
 
-          var folders = new Array();
+          var folders = [];
 
           // Figure out which folders to build.  If we don't have a parent, then
           // we assume we should build the top-level accounts.  (Actually we
           // build the fake root folders for those accounts.)
           if (!this._parentFolder) {
             var acctMgr = Cc["@mozilla.org/messenger/account-manager;1"].
                           getService(Ci.nsIMsgAccountManager);
-            var count = acctMgr.accounts.Count();
+            var allServers = acctMgr.allServers;
+            var count = allServers.Count();
 
             // Sadly, the accountMgr doesn't provide us we a sorted list of
-            // accounts.  We have to get them in the right order on our own. To
+            // servers.  We have to get them in the right order on our own. To
             // Do this, we'll stick them in an array, and then sort that array.
-            var accounts = new Array();
-            for (var i = 0; i < count; i++) {
-              var acct = acctMgr.accounts.GetElementAt(i).QueryInterface(Ci.nsIMsgAccount);
-
-              // This is a HACK to work around bug 41133. If we have one of the
-              // dummy "news" accounts there, that account won't have an
-              // incomingServer attached to it, and everything will blow up.
-              if (acct.incomingServer && acct.incomingServer.type != "im")
-                accounts.push(acct);
-            }
+            var servers = [];
+            for (var i = 0; i < count; i++)
+              servers.push(allServers.QueryElementAt(i, Ci.nsIMsgIncomingServer));
 
             /**
-             * This is our actual function for sorting accounts.  Accounts go
+             * This is our actual function for sorting servers.  Servers go
              * in the following order: (1) default account (2) other mail
              * accounts (3) Local Folders (4) news
              */
-            function accountCompare(a, b) {
-              if (a.key == acctMgr.defaultAccount.key)
+            var defaultServerKey = acctMgr.defaultAccount.incomingServer.key;
+            function serverCompare(a, b) {
+              if (a.key == defaultServerKey)
                 return -1;
-              if (b.key == acctMgr.defaultAccount.key)
+              if (b.key == defaultServerKey)
                 return 1;
-              var aIsNews = a.incomingServer.type == "nntp";
-              var bIsNews = b.incomingServer.type == "nntp";
+              var aIsNews = a.type == "nntp";
+              var bIsNews = b.type == "nntp";
               if (aIsNews && !bIsNews)
                 return 1;
               if (bIsNews && !aIsNews)
                 return -1;
 
-              var aIsLocal = a.incomingServer.type == "none";
-              var bIsLocal = b.incomingServer.type == "none";
+              var aIsLocal = a.type == "none";
+              var bIsLocal = b.type == "none";
               if (aIsLocal && !bIsLocal)
                 return 1;
               if (bIsLocal && !aIsLocal)
                 return -1;
               return 0;
             }
-            accounts = accounts.sort(accountCompare);
+            servers.sort(serverCompare);
 
             // Now generate our folder-list.  Note that we'll special case this
             // situation below, to avoid destroying the sort order we just made
-            for each (var acct in accounts) {
-              folders.push(acct.incomingServer.rootFolder);
-            }
+            folders = servers.map(function(s) s.rootFolder);
           } else {
             // If we do have a parent folder, then we just build based on those
             // subFolders for that parent
             var myenum = this._parentFolder.subFolders;
             while (myenum.hasMoreElements()) {
               folders.push(myenum.getNext().QueryInterface(Ci.nsIMsgFolder));
             }
           }
@@ -601,25 +594,22 @@
               recentFolders.sort(sorter);
               recentFolders.pop();
               oldestTime = recentFolders[recentFolders.length-1].getStringProperty("MRMTime");
             }
             recentFolders.push(aFolder);
           }
 
           // Start iterating at the top of the hierarchy, that is, with the root
-          // folders for each account.
-          var acctMgr = Cc["@mozilla.org/messenger/account-manager;1"].
-                        getService(Ci.nsIMsgAccountManager);
-          var count = acctMgr.accounts.Count();
+          // folders for each incoming server.
+          var servers = Cc["@mozilla.org/messenger/account-manager;1"].
+                        getService(Ci.nsIMsgAccountManager).allServers;
+          var count = servers.Count();
           for (var i = 0; i < count; i++) {
-            var acct = acctMgr.accounts.GetElementAt(i).QueryInterface(Ci.nsIMsgAccount);
-            var incomingServer = acct.incomingServer;
-            if (incomingServer.type == "im")
-              continue;
+            var incomingServer = servers.QueryElementAt(i, Ci.nsIMsgIncomingServer);
             addIfRecent(incomingServer.rootFolder);
             checkSubFolders(incomingServer.rootFolder);
           }
 
           function sorter(a, b) {
              return a.getStringProperty("MRMTime") < b.getStringProperty("MRMTime");
           }
           recentFolders.sort(sorter);
--- a/mailnews/base/prefs/content/amUtils.js
+++ b/mailnews/base/prefs/content/amUtils.js
@@ -65,18 +65,17 @@ function BrowseForLocalFolders()
   // Retrieve the selected folder.
   let selectedFolder = fp.file;
 
   // check that no other account/server has this same local directory
   let allServers = MailServices.accounts.allServers;
   for (let i = allServers.Count(); --i >= 0;) {
     let currentServer = allServers
       .QueryElementAt(i, Components.interfaces.nsIMsgIncomingServer);
-    // IM server type does not have a .localPath
-    if (currentServer.key == gServer.key || currentServer.type == "im")
+    if (currentServer.key == gServer.key)
       continue;
 
     if (currentServer.localPath.equals(selectedFolder)) {
       let dirAlreadyUsed = top.document.getElementById("bundle_prefs")
                               .getFormattedString("directoryUsedByOtherAccount",
                                                   [currentServer.prettyName]);
       Services.prompt.alert(window, null, dirAlreadyUsed);
       return;
--- a/mailnews/base/public/nsIMsgAccountManager.idl
+++ b/mailnews/base/public/nsIMsgAccountManager.idl
@@ -111,17 +111,17 @@ interface nsIMsgAccountManager : nsISupp
    */
   readonly attribute nsISupportsArray accounts;
 
   /* list of all identities in all accounts
    * array of nsIMsgIdentity
    */
   readonly attribute nsISupportsArray allIdentities;
 
-  /* list of all servers in all accounts, except for hidden servers
+  /* list of all servers in all accounts, except for hidden and IM servers
    * array of nsIMsgIncomingServer
    */
   readonly attribute nsISupportsArray allServers;
 
   /* summary of summary files folder cache */
   readonly attribute nsIMsgFolderCache folderCache;
 
   /* are we shutting down */
--- a/mailnews/base/src/nsMsgAccountManager.cpp
+++ b/mailnews/base/src/nsMsgAccountManager.cpp
@@ -1174,17 +1174,23 @@ nsMsgAccountManager::getIdentitiesToArra
 
 static PLDHashOperator
 hashGetNonHiddenServersToArray(nsCStringHashKey::KeyType aKey,
                                nsCOMPtr<nsIMsgIncomingServer>& aServer,
                                void* aClosure)
 {
   bool hidden = false;
   aServer->GetHidden(&hidden);
-  if (!hidden)
+  if (hidden)
+    return PL_DHASH_NEXT;
+
+  nsCString type;
+  NS_ENSURE_SUCCESS(aServer->GetType(type), PL_DHASH_NEXT);
+
+  if (!type.EqualsLiteral("im"))
   {
     nsISupportsArray *array = (nsISupportsArray*) aClosure;
     nsCOMPtr<nsISupports> serverSupports = do_QueryInterface(aServer);
     array->AppendElement(aServer);
   }
   return PL_DHASH_NEXT;
 }