Bug 436089 - Convert nsIMsgFolder::ListDescendents() from nsISupportsArray to nsIArray descendants attribute - backend conversions. r=Neil
authoraceman <acelists@atlas.sk>
Thu, 07 Feb 2013 12:37:51 -0500
changeset 14823 4d0efe2291c3801ca2445857503709b2e85cae2e
parent 14822 e115ce65ca20b710c368137277d237ccb153e374
child 14824 e98ade781a3b90361c7085609deb73bb448b9442
push id867
push userbugzilla@standard8.plus.com
push dateMon, 01 Apr 2013 20:44:27 +0000
treeherdercomm-beta@797726b8d244 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil
bugs436089
Bug 436089 - Convert nsIMsgFolder::ListDescendents() from nsISupportsArray to nsIArray descendants attribute - backend conversions. r=Neil
mailnews/base/src/nsMessengerOSXIntegration.mm
mailnews/base/src/nsMessengerUnixIntegration.cpp
mailnews/base/src/nsMessengerWinIntegration.cpp
mailnews/base/src/nsMsgAccountManager.cpp
mailnews/base/src/nsMsgFolderDataSource.cpp
mailnews/base/src/nsMsgPurgeService.cpp
mailnews/base/util/nsMsgDBFolder.cpp
mailnews/imap/src/nsAutoSyncManager.cpp
mailnews/imap/src/nsImapMailFolder.cpp
mailnews/imap/src/nsImapOfflineSync.cpp
mailnews/imap/src/nsImapOfflineSync.h
mailnews/local/src/nsLocalMailFolder.cpp
mailnews/local/src/nsRssIncomingServer.cpp
mailnews/news/src/nsNewsDownloader.cpp
mailnews/news/src/nsNewsDownloader.h
--- a/mailnews/base/src/nsMessengerOSXIntegration.mm
+++ b/mailnews/base/src/nsMessengerOSXIntegration.mm
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nscore.h"
 #include "nsMsgUtils.h"
+#include "nsArrayUtils.h"
 #include "nsMessengerOSXIntegration.h"
 #include "nsIMsgMailSession.h"
 #include "nsIMsgIncomingServer.h"
 #include "nsIMsgIdentity.h"
 #include "nsIMsgAccount.h"
 #include "nsIMsgFolder.h"
 #include "nsCOMPtr.h"
 #include "nsMsgBaseCID.h"
@@ -704,41 +705,39 @@ nsMessengerOSXIntegration::GetNewMailAut
 nsresult
 nsMessengerOSXIntegration::GetFirstFolderWithNewMail(nsIMsgFolder* aFolder, nsCString& aFolderURI)
 {
   // Find the subfolder in aFolder with new mail and return the folderURI
   if (aFolder)
   {
     nsCOMPtr<nsIMsgFolder> msgFolder;
     // enumerate over the folders under this root folder till we find one with new mail....
-    nsCOMPtr<nsISupportsArray> allFolders;
-    NS_NewISupportsArray(getter_AddRefs(allFolders));
-    nsresult rv = aFolder->ListDescendents(allFolders);
+    nsCOMPtr<nsIArray> allFolders;
+    nsresult rv = aFolder->GetDescendants(getter_AddRefs(allFolders));
     NS_ENSURE_SUCCESS(rv, rv);
 
-    nsCOMPtr<nsIEnumerator> enumerator;
-    allFolders->Enumerate(getter_AddRefs(enumerator));
-    if (enumerator)
+    nsCOMPtr<nsISimpleEnumerator> enumerator;
+    rv = allFolders->Enumerate(getter_AddRefs(enumerator));
+    if (NS_SUCCEEDED(rv) && enumerator)
     {
       nsCOMPtr<nsISupports> supports;
       int32_t numNewMessages = 0;
-      nsresult more = enumerator->First();
-      while (NS_SUCCEEDED(more))
+      bool hasMore = false;
+      while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMore)) && hasMore)
       {
-        rv = enumerator->CurrentItem(getter_AddRefs(supports));
-        if (supports)
+        rv = enumerator->GetNext(getter_AddRefs(supports));
+        if (NS_SUCCEEDED(rv) && supports)
         {
           msgFolder = do_QueryInterface(supports, &rv);
           if (msgFolder)
           {
             numNewMessages = 0;
             msgFolder->GetNumNewMessages(false, &numNewMessages);
             if (numNewMessages)
               break; // kick out of the while loop
-            more = enumerator->Next();
           }
         } // if we have a folder
       }  // if we have more potential folders to enumerate
     }  // if enumerator
 
     if (msgFolder)
       msgFolder->GetURI(aFolderURI);
   }
--- a/mailnews/base/src/nsMessengerUnixIntegration.cpp
+++ b/mailnews/base/src/nsMessengerUnixIntegration.cpp
@@ -43,16 +43,17 @@
 #include "nsIWeakReferenceUtils.h"
 
 #include "nsNativeCharsetUtils.h"
 #include "nsToolkitCompsCID.h"
 #include "nsMsgUtils.h"
 #include "msgCore.h"
 #include "nsCOMArray.h"
 #include "nsIMutableArray.h"
+#include "nsArrayUtils.h"
 #include "nsMemory.h"
 #include "mozilla/Services.h"
 
 #define ALERT_CHROME_URL "chrome://messenger/content/newmailalert.xul"
 #define NEW_MAIL_ALERT_ICON "chrome://messenger/skin/icons/new-mail-alert.png"
 #define SHOW_ALERT_PREF "mail.biff.show_alert"
 #define SHOW_ALERT_PREVIEW_LENGTH "mail.biff.alert.preview_length"
 #define SHOW_ALERT_PREVIEW_LENGTH_DEFAULT 40
@@ -231,21 +232,21 @@ nsMessengerUnixIntegration::BuildNotific
     return false;
 
   nsCString msgURI;
   folder->GetUriForMsg(aHdr, msgURI);
 
   bool localOnly;
 
   uint32_t msgURIIndex = mFetchingURIs.IndexOf(msgURI);
-  if (msgURIIndex == -1)
+  if (msgURIIndex == mFetchingURIs.NoIndex)
   {
     localOnly = false;
     mFetchingURIs.AppendElement(msgURI);
-  } 
+  }
   else
     localOnly = true;
 
   uint32_t messageKey;
   if (NS_FAILED(aHdr->GetMessageKey(&messageKey)))
     return false;
 
   bool asyncResult = false;
@@ -255,17 +256,17 @@ nsMessengerUnixIntegration::BuildNotific
   // If we're still waiting on getting the message previews,
   // bail early.  We'll come back later when the async operation
   // finishes.
   if (NS_FAILED(rv) || asyncResult)
     return false;
 
   // If we got here, that means that we've retrieved the message preview,
   // so we can stop tracking it with our mFetchingURIs array.
-  if (msgURIIndex != -1)
+  if (msgURIIndex != mFetchingURIs.NoIndex)
     mFetchingURIs.RemoveElementAt(msgURIIndex);
 
   nsCString utf8previewString;
   if (showPreview &&
       NS_FAILED(aHdr->GetStringProperty("preview", getter_Copies(utf8previewString))))
     return false;
 
   // need listener that mailbox is remote such as IMAP
@@ -594,23 +595,22 @@ nsresult nsMessengerUnixIntegration::Get
     rv = GetMRUTimestampForFolder(folder, &lastMRUTime);
     if (NS_FAILED(rv))
       lastMRUTime = 0;
 
     if (!folder)
       continue;
     // enumerate over the folders under this root folder till we find one with new mail....
     nsCOMPtr<nsIMsgFolder> msgFolder;
-    nsCOMPtr<nsISupportsArray> allFolders;
-    NS_NewISupportsArray(getter_AddRefs(allFolders));
-    rv = folder->ListDescendents(allFolders);
+    nsCOMPtr<nsIArray> allFolders;
+    rv = folder->GetDescendants(getter_AddRefs(allFolders));
     NS_ENSURE_SUCCESS(rv, rv);
 
     uint32_t subfolderCount = 0;
-    allFolders->Count(&subfolderCount);
+    allFolders->GetLength(&subfolderCount);
     uint32_t j;
     for (j = 0; j < subfolderCount; j++)
     {
       nsCOMPtr<nsIMsgFolder> msgFolder = do_QueryElementAt(allFolders, j);
 
       if (!msgFolder)
         continue;
 
--- a/mailnews/base/src/nsMessengerWinIntegration.cpp
+++ b/mailnews/base/src/nsMessengerWinIntegration.cpp
@@ -777,40 +777,38 @@ nsresult nsMessengerWinIntegration::GetF
 
   weakReference = do_QueryElementAt(mFoldersWithNewMail, 0);
   folder = do_QueryReferent(weakReference);
 
   if (folder)
   {
     nsCOMPtr<nsIMsgFolder> msgFolder;
     // enumerate over the folders under this root folder till we find one with new mail....
-    nsCOMPtr<nsISupportsArray> allFolders;
-    NS_NewISupportsArray(getter_AddRefs(allFolders));
-    rv = folder->ListDescendents(allFolders);
+    nsCOMPtr<nsIArray> allFolders;
+    rv = folder->GetDescendants(getter_AddRefs(allFolders));
     NS_ENSURE_SUCCESS(rv, rv);
 
-    nsCOMPtr<nsIEnumerator> enumerator;
-    allFolders->Enumerate(getter_AddRefs(enumerator));
-    if (enumerator)
+    nsCOMPtr<nsISimpleEnumerator> enumerator;
+    rv = allFolders->Enumerate(getter_AddRefs(enumerator));
+    if (NS_SUCCEEDED(rv) && enumerator)
     {
       nsCOMPtr<nsISupports> supports;
-      nsresult more = enumerator->First();
-      while (NS_SUCCEEDED(more))
+      bool hasMore = false;
+      while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMore)) && hasMore)
       {
-        rv = enumerator->CurrentItem(getter_AddRefs(supports));
-        if (supports)
+        rv = enumerator->GetNext(getter_AddRefs(supports));
+        if (NS_SUCCEEDED(rv) && supports)
         {
           msgFolder = do_QueryInterface(supports, &rv);
           if (msgFolder)
           {
             numNewMessages = 0;
             msgFolder->GetNumNewMessages(false, &numNewMessages);
             if (numNewMessages)
               break; // kick out of the while loop
-            more = enumerator->Next();
           }
         } // if we have a folder
       }  // if we have more potential folders to enumerate
     }  // if enumerator
 
     if (msgFolder)
       msgFolder->GetURI(aFolderURI);
   }
--- a/mailnews/base/src/nsMsgAccountManager.cpp
+++ b/mailnews/base/src/nsMsgAccountManager.cpp
@@ -526,38 +526,36 @@ nsMsgAccountManager::RemoveIncomingServe
 
   // invalidate the FindServer() cache if we are removing the cached server
   if (m_lastFindServerResult == aServer)
     SetLastServerFound(nullptr, EmptyCString(), EmptyCString(), 0, EmptyCString());
 
   m_incomingServers.Remove(serverKey);
 
   nsCOMPtr<nsIMsgFolder> rootFolder;
-  nsCOMPtr<nsISupportsArray> allDescendents;
+  nsCOMPtr<nsIArray> allDescendants;
 
   rv = aServer->GetRootFolder(getter_AddRefs(rootFolder));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = NS_NewISupportsArray(getter_AddRefs(allDescendents));
+  rv = rootFolder->GetDescendants(getter_AddRefs(allDescendants));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rootFolder->ListDescendents(allDescendents);
-
   uint32_t cnt = 0;
-  rv = allDescendents->Count(&cnt);
+  rv = allDescendants->GetLength(&cnt);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIMsgFolderNotificationService> notifier =
            do_GetService(NS_MSGNOTIFICATIONSERVICE_CONTRACTID);
   nsCOMPtr<nsIFolderListener> mailSession =
            do_GetService(NS_MSGMAILSESSION_CONTRACTID);
 
   for (uint32_t i = 0; i < cnt; i++)
   {
-    nsCOMPtr<nsIMsgFolder> folder = do_QueryElementAt(allDescendents, i);
+    nsCOMPtr<nsIMsgFolder> folder = do_QueryElementAt(allDescendants, i);
     if (folder)
     {
       folder->ForceDBClosed();
       if (notifier)
         notifier->NotifyFolderDeleted(folder);
       if (mailSession)
       {
         nsCOMPtr<nsIMsgFolder> parentFolder;
@@ -3294,56 +3292,43 @@ nsresult nsMsgAccountManager::RemoveVFLi
     }
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgAccountManager::GetAllFolders(nsIArray **aAllFolders)
 {
   NS_ENSURE_ARG_POINTER(aAllFolders);
+
   nsCOMPtr<nsIArray> servers;
   nsresult rv = GetAllServers(getter_AddRefs(servers));
   NS_ENSURE_SUCCESS(rv, rv);
 
   uint32_t numServers = 0;
   rv = servers->GetLength(&numServers);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsISupportsArray> allDescendents;
-  rv = NS_NewISupportsArray(getter_AddRefs(allDescendents));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIMutableArray> folderArray(do_CreateInstance(NS_ARRAY_CONTRACTID, &rv));
+  nsCOMPtr<nsIMutableArray> allFolders(do_CreateInstance(NS_ARRAY_CONTRACTID, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   uint32_t i;
   for (i = 0; i < numServers; i++)
   {
     nsCOMPtr<nsIMsgIncomingServer> server = do_QueryElementAt(servers, i);
     if (server)
     {
-      nsCOMPtr <nsIMsgFolder> rootFolder;
+      nsCOMPtr<nsIMsgFolder> rootFolder;
       server->GetRootFolder(getter_AddRefs(rootFolder));
       if (rootFolder)
-        rootFolder->ListDescendents(allDescendents);
+        rootFolder->ListDescendants(allFolders);
     }
   }
-  uint32_t folderCount;
-  rv = allDescendents->Count(&folderCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  // Create an nsIMutableArray from the nsISupportsArray
-  nsCOMPtr<nsIMsgFolder> folder;
-  for (i = 0; i < folderCount; i++)
-  {
-    folder = do_QueryElementAt(allDescendents, i);
-    folderArray->AppendElement(folder, false);
-  }
-  NS_ADDREF(*aAllFolders = folderArray);
-  return rv;
+
+  allFolders.forget(aAllFolders);
+  return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgAccountManager::OnItemAdded(nsIMsgFolder *parentItem, nsISupports *item)
 {
   nsCOMPtr<nsIMsgFolder> folder = do_QueryInterface(item);
   // just kick out with a success code if the item in question is not a folder
   if (!folder)
     return NS_OK;
@@ -3423,28 +3408,28 @@ NS_IMETHODIMP nsMsgAccountManager::OnIte
             searchURI.Cut(0, 1);
             searchURI.Append(folderURI);
             dbFolderInfo->SetCharProperty(kSearchFolderUriProp, searchURI);
             break;
           }
           // New sent or archive folder, need to add sub-folders to smart folder.
           if (vfFolderFlag & (nsMsgFolderFlags::Archive | nsMsgFolderFlags::SentMail))
           {
-            nsCOMPtr<nsISupportsArray> allDescendents;
-            rv = NS_NewISupportsArray(getter_AddRefs(allDescendents));
+            nsCOMPtr<nsIArray> allDescendants;
+            rv = folder->GetDescendants(getter_AddRefs(allDescendants));
             NS_ENSURE_SUCCESS(rv, rv);
-            folder->ListDescendents(allDescendents);
+
             uint32_t cnt = 0;
-            rv = allDescendents->Count(&cnt);
+            rv = allDescendants->GetLength(&cnt);
             NS_ENSURE_SUCCESS(rv, rv);
 
             nsCOMPtr<nsIMsgFolder> parent;
             for (uint32_t j = 0; j < cnt; j++)
             {
-              nsCOMPtr<nsIMsgFolder> subFolder = do_QueryElementAt(allDescendents, j);
+              nsCOMPtr<nsIMsgFolder> subFolder = do_QueryElementAt(allDescendants, j);
               if (subFolder)
               {
                 subFolder->GetParent(getter_AddRefs(parent));
                 OnItemAdded(parent, subFolder);
               }
             }
           }
         }
@@ -3580,28 +3565,28 @@ nsMsgAccountManager::OnItemIntPropertyCh
         nsCOMPtr<nsIMsgFolder> parent;
         aFolder->GetParent(getter_AddRefs(parent));
         return OnItemAdded(parent, aFolder);
       }
       RemoveFolderFromSmartFolder(aFolder, smartFlagsChanged);
       // sent|archive flag removed, remove sub-folders from smart folder.
       if (smartFlagsChanged & (nsMsgFolderFlags::Archive | nsMsgFolderFlags::SentMail))
       {
-        nsCOMPtr<nsISupportsArray> allDescendents;
-        nsresult rv = NS_NewISupportsArray(getter_AddRefs(allDescendents));
+        nsCOMPtr<nsIArray> allDescendants;
+        nsresult rv = aFolder->GetDescendants(getter_AddRefs(allDescendants));
         NS_ENSURE_SUCCESS(rv, rv);
-        aFolder->ListDescendents(allDescendents);
+
         uint32_t cnt = 0;
-        rv = allDescendents->Count(&cnt);
+        rv = allDescendants->GetLength(&cnt);
         NS_ENSURE_SUCCESS(rv, rv);
 
         nsCOMPtr<nsIMsgFolder> parent;
         for (uint32_t j = 0; j < cnt; j++)
         {
-          nsCOMPtr<nsIMsgFolder> subFolder = do_QueryElementAt(allDescendents, j);
+          nsCOMPtr<nsIMsgFolder> subFolder = do_QueryElementAt(allDescendants, j);
           if (subFolder)
             RemoveFolderFromSmartFolder(subFolder, smartFlagsChanged);
         }
       }
     }
   }
   return NS_OK;
 }
--- a/mailnews/base/src/nsMsgFolderDataSource.cpp
+++ b/mailnews/base/src/nsMsgFolderDataSource.cpp
@@ -2159,66 +2159,39 @@ NS_IMETHODIMP nsMsgFlatFolderDataSource:
     EnsureFolders();
     return NS_NewArrayEnumerator(targets, m_folders);
   }
   return NS_NewSingletonEnumerator(targets, property);
 }
 
 void nsMsgFlatFolderDataSource::EnsureFolders()
 {
-  if (!m_builtFolders)
-  {
-    m_builtFolders = true; // in case something goes wrong
+  if (m_builtFolders)
+    return;
 
-    // need an enumerator that gives all folders with unread
-    nsresult rv;
-    nsCOMPtr <nsIMsgAccountManager> accountManager = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
-    if (NS_FAILED(rv))
-      return;
+  m_builtFolders = true; // in case something goes wrong
 
-    nsCOMPtr<nsIArray> allServers;
-    rv = accountManager->GetAllServers(getter_AddRefs(allServers));
-    if (NS_FAILED(rv))
-      return;
+  nsresult rv;
+  nsCOMPtr<nsIMsgAccountManager> accountManager = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
+  NS_ENSURE_SUCCESS_VOID(rv);
 
-    nsCOMPtr <nsISupportsArray> allFolders = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv);
-    if (NS_SUCCEEDED(rv) && allServers)
-    {
-      uint32_t count = 0;
-      allServers->GetLength(&count);
-      uint32_t i;
-      for (i = 0; i < count; i++)
-      {
-        nsCOMPtr<nsIMsgIncomingServer> server = do_QueryElementAt(allServers, i);
-        if (server)
-        {
-          nsCOMPtr <nsIMsgFolder> rootFolder;
-          server->GetRootFolder(getter_AddRefs(rootFolder));
-          if (rootFolder)
-          {
-            nsCOMPtr<nsISimpleEnumerator> subFolders;
-            rv = rootFolder->GetSubFolders(getter_AddRefs(subFolders));
+  nsCOMPtr<nsIArray> allFolders;
+  rv = accountManager->GetAllFolders(getter_AddRefs(allFolders));
+  if (NS_FAILED(rv) || !allFolders)
+    return;
 
-            uint32_t lastEntry;
-            allFolders->Count(&lastEntry);
-            rv = rootFolder->ListDescendents(allFolders);
-            uint32_t newLastEntry;
-            allFolders->Count(&newLastEntry);
-            for (uint32_t newEntryIndex = lastEntry; newEntryIndex < newLastEntry; newEntryIndex++)
-            {
-              nsCOMPtr <nsIMsgFolder> curFolder = do_QueryElementAt(allFolders, newEntryIndex);
-              if (WantsThisFolder(curFolder))
-              {
-                m_folders.AppendObject(curFolder);
-              }
-            }
-          }
-        }
-      }
-    }
+  uint32_t count;
+  rv = allFolders->GetLength(&count);
+  NS_ENSURE_SUCCESS_VOID(rv);
+
+  for (uint32_t i = 0; i < count; i++)
+  {
+    nsCOMPtr<nsIMsgFolder> curFolder = do_QueryElementAt(allFolders, i);
+    if (WantsThisFolder(curFolder))
+      m_folders.AppendObject(curFolder);
   }
 }
 
 
 NS_IMETHODIMP nsMsgFlatFolderDataSource::GetURI(char* *aUri)
 {
   nsAutoCString uri("rdf:");
   uri.Append(m_dsName);
@@ -2362,115 +2335,92 @@ void nsMsgRecentFoldersDataSource::Clean
 {
   m_cutOffDate = 0;
   nsMsgFlatFolderDataSource::Cleanup();
 }
 
 
 void nsMsgRecentFoldersDataSource::EnsureFolders()
 {
-  if (!m_builtFolders)
-  {
-    m_builtFolders = true;
+  if (m_builtFolders)
+    return;
 
-    nsresult rv;
-    nsCOMPtr <nsIMsgAccountManager> accountManager = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
-    if (NS_FAILED(rv))
-      return;
+  m_builtFolders = true; // in case something goes wrong
 
-    nsCOMPtr<nsIArray> allServers;
-    rv = accountManager->GetAllServers(getter_AddRefs(allServers));
-    if (NS_FAILED(rv))
-      return;
+  nsresult rv;
+  nsCOMPtr<nsIMsgAccountManager> accountManager = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
+  NS_ENSURE_SUCCESS_VOID(rv);
 
-    nsCOMPtr <nsISupportsArray> allFolders = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv);
-    if (NS_SUCCEEDED(rv) && allServers)
-    {
-      uint32_t count = 0;
-      allServers->GetLength(&count);
-      uint32_t i;
-      for (i = 0; i < count; i++)
-      {
-        nsCOMPtr<nsIMsgIncomingServer> server = do_QueryElementAt(allServers, i);
-        if (server)
-        {
-          nsCOMPtr <nsIMsgFolder> rootFolder;
-          server->GetRootFolder(getter_AddRefs(rootFolder));
-          if (rootFolder)
-          {
-            nsCOMPtr<nsISimpleEnumerator> subFolders;
-            rv = rootFolder->GetSubFolders(getter_AddRefs(subFolders));
+  nsCOMPtr<nsIArray> allFolders;
+  rv = accountManager->GetAllFolders(getter_AddRefs(allFolders));
+  if (NS_FAILED(rv) || !allFolders)
+    return;
+
+  uint32_t count;
+  rv = allFolders->GetLength(&count);
+  NS_ENSURE_SUCCESS_VOID(rv);
+
+  for (uint32_t i = 0; i < count; i++)
+  {
+    nsCOMPtr<nsIMsgFolder> curFolder = do_QueryElementAt(allFolders, i);
+    nsCString dateStr;
+    curFolder->GetStringProperty(MRU_TIME_PROPERTY, dateStr);
+    uint32_t curFolderDate = (uint32_t) dateStr.ToInteger(&rv);
+    if (NS_FAILED(rv))
+      curFolderDate = 0;
 
-            uint32_t lastEntry;
-            allFolders->Count(&lastEntry);
-            rv = rootFolder->ListDescendents(allFolders);
-            uint32_t newLastEntry;
-            allFolders->Count(&newLastEntry);
-            for (uint32_t newEntryIndex = lastEntry; newEntryIndex < newLastEntry; newEntryIndex++)
-            {
-              nsCOMPtr <nsIMsgFolder> curFolder = do_QueryElementAt(allFolders, newEntryIndex);
-              nsCString dateStr;
-              nsresult err;
-              curFolder->GetStringProperty(MRU_TIME_PROPERTY, dateStr);
-              uint32_t curFolderDate = (uint32_t) dateStr.ToInteger(&err);
-              if (NS_FAILED(err))
-                curFolderDate = 0;
-              if (curFolderDate > m_cutOffDate)
-              {
-                // if m_folders is "full", replace oldest folder with this folder,
-                // and adjust m_cutOffDate so that it's the mrutime
-                // of the "new" oldest folder.
-                uint32_t curFaveFoldersCount = m_folders.Count();
-                if (curFaveFoldersCount > m_maxNumFolders)
-                {
-                  uint32_t indexOfOldestFolder = 0;
-                  uint32_t oldestFaveDate = 0;
-                  uint32_t newOldestFaveDate = 0;
-                  for (uint32_t index = 0; index < curFaveFoldersCount; )
-                  {
-                    nsCString curFaveFolderDateStr;
-                    m_folders[index]->GetStringProperty(MRU_TIME_PROPERTY, curFaveFolderDateStr);
-                    uint32_t curFaveFolderDate = (uint32_t) curFaveFolderDateStr.ToInteger(&err);
-                    if (!oldestFaveDate || curFaveFolderDate < oldestFaveDate)
-                    {
-                      indexOfOldestFolder = index;
-                      newOldestFaveDate = oldestFaveDate;
-                      oldestFaveDate = curFaveFolderDate;
-                    }
-                    if (!newOldestFaveDate || (index != indexOfOldestFolder
-                                                && curFaveFolderDate < newOldestFaveDate))
-                      newOldestFaveDate = curFaveFolderDate;
-                    index++;
-                  }
-                  if (curFolderDate > oldestFaveDate && m_folders.IndexOf(curFolder) == kNotFound)
-                    m_folders.ReplaceObjectAt(curFolder, indexOfOldestFolder);
+    if (curFolderDate > m_cutOffDate)
+    {
+      // if m_folders is "full", replace oldest folder with this folder,
+      // and adjust m_cutOffDate so that it's the mrutime
+      // of the "new" oldest folder.
+      uint32_t curFaveFoldersCount = m_folders.Count();
+      if (curFaveFoldersCount > m_maxNumFolders)
+      {
+        uint32_t indexOfOldestFolder = 0;
+        uint32_t oldestFaveDate = 0;
+        uint32_t newOldestFaveDate = 0;
+        for (uint32_t index = 0; index < curFaveFoldersCount; )
+        {
+          nsCString curFaveFolderDateStr;
+          m_folders[index]->GetStringProperty(MRU_TIME_PROPERTY, curFaveFolderDateStr);
+          uint32_t curFaveFolderDate = (uint32_t) curFaveFolderDateStr.ToInteger(&rv);
+          if (!oldestFaveDate || curFaveFolderDate < oldestFaveDate)
+          {
+            indexOfOldestFolder = index;
+            newOldestFaveDate = oldestFaveDate;
+            oldestFaveDate = curFaveFolderDate;
+          }
+          if (!newOldestFaveDate || (index != indexOfOldestFolder
+              && curFaveFolderDate < newOldestFaveDate)) {
+            newOldestFaveDate = curFaveFolderDate;
+          }
+          index++;
+        }
+        if (curFolderDate > oldestFaveDate && m_folders.IndexOf(curFolder) == kNotFound)
+          m_folders.ReplaceObjectAt(curFolder, indexOfOldestFolder);
 
-                  NS_ASSERTION(newOldestFaveDate >= m_cutOffDate, "cutoff date should be getting bigger");
-                  m_cutOffDate = newOldestFaveDate;
-                }
-                else if (m_folders.IndexOf(curFolder) == kNotFound)
-                  m_folders.AppendObject(curFolder);
-              }
+        NS_ASSERTION(newOldestFaveDate >= m_cutOffDate, "cutoff date should be getting bigger");
+        m_cutOffDate = newOldestFaveDate;
+      }
+      else if (m_folders.IndexOf(curFolder) == kNotFound)
+        m_folders.AppendObject(curFolder);
+    }
 #ifdef DEBUG_David_Bienvenu
-              else
-              {
-                for (uint32_t index = 0; index < m_folders.Count(); index++)
-                {
-                  nsCString curFaveFolderDateStr;
-                  m_folders[index]->GetStringProperty(MRU_TIME_PROPERTY, curFaveFolderDateStr);
-                  uint32_t curFaveFolderDate = (uint32_t) curFaveFolderDateStr.ToInteger(&err);
-                  NS_ASSERTION(curFaveFolderDate > curFolderDate, "folder newer then faves but not added");
-                }
-              }
-#endif
-            }
-          }
-        }
+    else
+    {
+      for (uint32_t index = 0; index < m_folders.Count(); index++)
+      {
+        nsCString curFaveFolderDateStr;
+        m_folders[index]->GetStringProperty(MRU_TIME_PROPERTY, curFaveFolderDateStr);
+        uint32_t curFaveFolderDate = (uint32_t) curFaveFolderDateStr.ToInteger(&rv);
+        NS_ASSERTION(curFaveFolderDate > curFolderDate, "folder newer then faves but not added");
       }
     }
+#endif
   }
 }
 
 NS_IMETHODIMP nsMsgRecentFoldersDataSource::OnItemAdded(nsIMsgFolder *parentItem, nsISupports *item)
 {
   // if we've already built the recent folder array, we should add this item to the array
   // since just added items are by definition new.
   // I think this means newly discovered imap folders (ones w/o msf files) will
--- a/mailnews/base/src/nsMsgPurgeService.cpp
+++ b/mailnews/base/src/nsMsgPurgeService.cpp
@@ -163,22 +163,22 @@ nsresult nsMsgPurgeService::PerformPurge
       if (NS_SUCCEEDED(rv) && server)
       {
         if (keepApplyingRetentionSettings)
         {
           nsCOMPtr <nsIMsgFolder> rootFolder;
           rv = server->GetRootFolder(getter_AddRefs(rootFolder));
           NS_ENSURE_SUCCESS(rv, rv);
 
-          nsCOMPtr <nsISupportsArray> childFolders = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv);
+          nsCOMPtr<nsIArray> childFolders;
+          rv = rootFolder->GetDescendants(getter_AddRefs(childFolders));
           NS_ENSURE_SUCCESS(rv, rv);
-          rv = rootFolder->ListDescendents(childFolders);
 
           uint32_t cnt = 0;
-          childFolders->Count(&cnt);
+          childFolders->GetLength(&cnt);
 
           nsCOMPtr<nsISupports> supports;
           nsCOMPtr<nsIUrlListener> urlListener;
           nsCOMPtr<nsIMsgFolder> childFolder;
 
           for (uint32_t index = 0; index < cnt; index++)
           {
             childFolder = do_QueryElementAt(childFolders, index);
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -1852,21 +1852,20 @@ nsresult nsMsgDBFolder::HandleAutoCompac
         if (!supportsCompaction)
           continue;
         nsCOMPtr<nsIMsgFolder> rootFolder;
         rv = server->GetRootFolder(getter_AddRefs(rootFolder));
         if(NS_SUCCEEDED(rv) && rootFolder)
         {
           rv = server->GetOfflineSupportLevel(&offlineSupportLevel);
           NS_ENSURE_SUCCESS(rv, rv);
-          nsCOMPtr<nsISupportsArray> allDescendents;
-          NS_NewISupportsArray(getter_AddRefs(allDescendents));
-          rootFolder->ListDescendents(allDescendents);
+          nsCOMPtr<nsIArray> allDescendents;
+          rootFolder->GetDescendants(getter_AddRefs(allDescendents));
           uint32_t cnt = 0;
-          rv = allDescendents->Count(&cnt);
+          rv = allDescendents->GetLength(&cnt);
           NS_ENSURE_SUCCESS(rv, rv);
           uint32_t expungedBytes=0;
           if (offlineSupportLevel > 0)
           {
             uint32_t flags;
             for (uint32_t i = 0; i < cnt; i++)
             {
               nsCOMPtr<nsIMsgFolder> folder = do_QueryElementAt(allDescendents, i);
--- a/mailnews/imap/src/nsAutoSyncManager.cpp
+++ b/mailnews/imap/src/nsAutoSyncManager.cpp
@@ -768,37 +768,36 @@ nsresult nsAutoSyncManager::AutoUpdateFo
 
     // if we haven't logged onto this server yet, then skip this server.
     bool passwordRequired;
     incomingServer->GetServerRequiresPasswordForBiff(&passwordRequired);
     if (passwordRequired)
       continue;
 
     nsCOMPtr<nsIMsgFolder> rootFolder;
-    nsCOMPtr<nsISupportsArray> allDescendents;
+    nsCOMPtr<nsIArray> allDescendants;
 
     rv = incomingServer->GetRootFolder(getter_AddRefs(rootFolder));
     if (rootFolder)
     {
-      allDescendents = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv);
       if (NS_FAILED(rv))
         continue;
 
-      rv = rootFolder->ListDescendents(allDescendents);
-      if (!allDescendents)
+      rv = rootFolder->GetDescendants(getter_AddRefs(allDescendants));
+      if (!allDescendants)
         continue;
 
       uint32_t cnt = 0;
-      rv = allDescendents->Count(&cnt);
+      rv = allDescendants->GetLength(&cnt);
       if (NS_FAILED(rv))
         continue;
 
       for (uint32_t i = 0; i < cnt; i++)
       {
-        nsCOMPtr<nsIMsgFolder> folder(do_QueryElementAt(allDescendents, i, &rv));
+        nsCOMPtr<nsIMsgFolder> folder(do_QueryElementAt(allDescendants, i, &rv));
         if (NS_FAILED(rv))
           continue;
 
         uint32_t folderFlags;
         rv = folder->GetFlags(&folderFlags);
         // Skip this folder if not offline or is a saved search or is no select.
         if (NS_FAILED(rv) || !(folderFlags & nsMsgFolderFlags::Offline) ||
             folderFlags & (nsMsgFolderFlags::Virtual |
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -1350,25 +1350,23 @@ NS_IMETHODIMP nsImapMailFolder::Expunge(
 NS_IMETHODIMP nsImapMailFolder::CompactAll(nsIUrlListener *aListener,
                                                nsIMsgWindow *aMsgWindow,
                                                bool aCompactOfflineAlso)
 {
   nsresult rv;
   nsCOMPtr<nsIMutableArray> folderArray, offlineFolderArray;
 
   nsCOMPtr<nsIMsgFolder> rootFolder;
-  nsCOMPtr<nsISupportsArray> allDescendents;
+  nsCOMPtr<nsIArray> allDescendents;
   rv = GetRootFolder(getter_AddRefs(rootFolder));
   if (NS_SUCCEEDED(rv) && rootFolder)
   {
-    allDescendents = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv);
-    NS_ENSURE_TRUE(allDescendents, rv);
-    rootFolder->ListDescendents(allDescendents);
+    rootFolder->GetDescendants(getter_AddRefs(allDescendents));
     uint32_t cnt = 0;
-    rv = allDescendents->Count(&cnt);
+    rv = allDescendents->GetLength(&cnt);
     NS_ENSURE_SUCCESS(rv, rv);
     folderArray = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
     NS_ENSURE_TRUE(folderArray, rv);
     if (aCompactOfflineAlso)
     {
       offlineFolderArray = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
       NS_ENSURE_TRUE(offlineFolderArray, rv);
     }
--- a/mailnews/imap/src/nsImapOfflineSync.cpp
+++ b/mailnews/imap/src/nsImapOfflineSync.cpp
@@ -103,133 +103,137 @@ nsImapOfflineSync::OnStopRunningUrl(nsIU
   {
     ClearCurrentOps();
     rv = ProcessNextOperation();
   }
   // else if it's a non-stop error, and we're doing multiple folders,
   // go to the next folder.
   else if (!m_singleFolderToUpdate)
   {
-    rv = AdvanceToNextFolder();
-    if (NS_SUCCEEDED(rv))
+    if (AdvanceToNextFolder())
       rv = ProcessNextOperation();
     else if (m_listener)
       m_listener->OnStopRunningUrl(url, rv);
   }
 
   return rv;
 }
 
-// leaves m_currentServer at the next imap or local mail "server" that
-// might have offline events to playback. If no more servers,
-// m_currentServer will be left at nullptr.
-// Also, sets up m_serverEnumerator to enumerate over the server
-nsresult nsImapOfflineSync::AdvanceToNextServer()
+/**
+ * Leaves m_currentServer at the next imap or local mail "server" that
+ * might have offline events to playback. If no more servers,
+ * m_currentServer will be left at nullptr and the function returns false.
+ * Also, sets up m_serverEnumerator to enumerate over the server.
+ */
+bool nsImapOfflineSync::AdvanceToNextServer()
 {
   nsresult rv = NS_OK;
 
   if (!m_allServers)
   {
     NS_ASSERTION(!m_currentServer, "this shouldn't be set");
     m_currentServer = nullptr;
     nsCOMPtr<nsIMsgAccountManager> accountManager = 
              do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
     NS_ASSERTION(accountManager && NS_SUCCEEDED(rv), "couldn't get account mgr");
-    if (!accountManager || NS_FAILED(rv)) return rv;
+    if (!accountManager || NS_FAILED(rv))
+      return false;
 
     rv = accountManager->GetAllServers(getter_AddRefs(m_allServers));
-    NS_ENSURE_SUCCESS(rv, rv);
+    NS_ENSURE_SUCCESS(rv, false);
   }
   uint32_t serverIndex = 0;
   if (m_currentServer)
   {
     rv = m_allServers->IndexOf(0, m_currentServer, &serverIndex);
     if (NS_FAILED(rv))
       serverIndex = -1;
 
     // Move to the next server
     ++serverIndex;
   }
   m_currentServer = nullptr;
-  uint32_t numServers; 
+  uint32_t numServers;
   m_allServers->GetLength(&numServers);
   nsCOMPtr <nsIMsgFolder> rootFolder;
 
   while (serverIndex < numServers)
   {
     nsCOMPtr<nsIMsgIncomingServer> server(do_QueryElementAt(m_allServers, serverIndex));
     serverIndex++;
 
-    nsCOMPtr <nsINntpIncomingServer> newsServer = do_QueryInterface(server);
+    nsCOMPtr<nsINntpIncomingServer> newsServer = do_QueryInterface(server);
     if (newsServer) // news servers aren't involved in offline imap
       continue;
+
     if (server)
     {
       m_currentServer = server;
       server->GetRootFolder(getter_AddRefs(rootFolder));
       if (rootFolder)
       {
-        m_allFolders = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv);
-        NS_ENSURE_TRUE(m_allFolders, rv);
-        rv = rootFolder->ListDescendents(m_allFolders);
+        rv = rootFolder->GetDescendants(getter_AddRefs(m_allFolders));
         if (NS_SUCCEEDED(rv))
-          m_allFolders->Enumerate(getter_AddRefs(m_serverEnumerator));
-        if (NS_SUCCEEDED(rv) && m_serverEnumerator)
         {
-          rv = m_serverEnumerator->First();
-          if (NS_SUCCEEDED(rv))
-            break;
+          rv = m_allFolders->Enumerate(getter_AddRefs(m_serverEnumerator));
+          if (NS_SUCCEEDED(rv) && m_serverEnumerator)
+          {
+            bool hasMore = false;
+            rv = m_serverEnumerator->HasMoreElements(&hasMore);
+            if (NS_SUCCEEDED(rv) && hasMore)
+              return true;
+          }
         }
       }
     }
   }
-  return rv;
+  return false;
 }
 
-nsresult nsImapOfflineSync::AdvanceToNextFolder()
+/**
+ * Sets m_currentFolder to the next folder to process.
+ *
+ * @return  True if next folder to process was found, otherwise false.
+ */
+bool nsImapOfflineSync::AdvanceToNextFolder()
 {
-  nsresult rv;
   // we always start by changing flags
   mCurrentPlaybackOpType = nsIMsgOfflineImapOperation::kFlagsChanged;
 
   if (m_currentFolder)
   {
     m_currentFolder->SetMsgDatabase(nullptr);
     m_currentFolder = nullptr;
   }
 
-  if (!m_currentServer)
-     rv = AdvanceToNextServer();
-  else
-    rv = m_serverEnumerator->Next();
-  if (NS_FAILED(rv))
-    rv = AdvanceToNextServer();
+  bool hasMore = false;
+  if (m_currentServer)
+    m_serverEnumerator->HasMoreElements(&hasMore);
+  if (!hasMore)
+    hasMore = AdvanceToNextServer();
 
-  if (NS_SUCCEEDED(rv) && m_serverEnumerator)
+  if (hasMore)
   {
-    nsCOMPtr <nsISupports> supports;
-    rv = m_serverEnumerator->CurrentItem(getter_AddRefs(supports));
-    m_currentFolder = do_QueryInterface(supports);
+    nsCOMPtr<nsISupports> supports;
+    nsresult rv = m_serverEnumerator->GetNext(getter_AddRefs(supports));
+    if (NS_SUCCEEDED(rv))
+      m_currentFolder = do_QueryInterface(supports);
   }
   ClearDB();
-  return rv;
+  return m_currentFolder;
 }
 
 void nsImapOfflineSync::AdvanceToFirstIMAPFolder()
 {
-  nsresult rv;
   m_currentServer = nullptr;
-  nsCOMPtr <nsIMsgImapMailFolder> imapFolder;
-  do
+  nsCOMPtr<nsIMsgImapMailFolder> imapFolder;
+  while (!imapFolder && AdvanceToNextFolder())
   {
-    rv = AdvanceToNextFolder();
-    if (m_currentFolder)
-      imapFolder = do_QueryInterface(m_currentFolder);
+    imapFolder = do_QueryInterface(m_currentFolder);
   }
-  while (NS_SUCCEEDED(rv) && m_currentFolder && !imapFolder);
 }
 
 void nsImapOfflineSync::ProcessFlagOperation(nsIMsgOfflineImapOperation *op)
 {
   nsCOMPtr <nsIMsgOfflineImapOperation> currentOp = op;
   nsTArray<nsMsgKey> matchingFlagKeys;
   uint32_t currentKeyIndex = m_KeyIndex;
 
@@ -1103,18 +1107,17 @@ nsresult nsImapOfflineDownloader::Proces
     if (NS_FAILED(rv)) return rv;
 
     nsCOMPtr<nsIArray> servers;
     rv = accountManager->GetAllServers(getter_AddRefs(servers));
     if (NS_FAILED(rv)) return rv;
   }
   if (!m_mailboxupdatesFinished)
   {
-    AdvanceToNextServer();
-    if (m_currentServer)
+    if (AdvanceToNextServer())
     {
       nsCOMPtr <nsIMsgFolder> rootMsgFolder;
       m_currentServer->GetRootFolder(getter_AddRefs(rootMsgFolder));
       nsCOMPtr<nsIMsgFolder> inbox;
       if (rootMsgFolder)
       {
           rootMsgFolder->GetFolderWithFlags(nsMsgFolderFlags::Inbox,
                                             getter_AddRefs(inbox));
@@ -1159,19 +1162,18 @@ nsresult nsImapOfflineDownloader::Proces
       return ProcessNextOperation(); // recurse and do next server.
     }
     else
     {
       m_allServers = nullptr;
       m_mailboxupdatesFinished = true;
     }
   }
-  AdvanceToNextFolder();
 
-  while (m_currentFolder)
+  while (AdvanceToNextFolder())
   {
     uint32_t folderFlags;
 
     ClearDB();
     nsCOMPtr <nsIMsgImapMailFolder> imapFolder;
     if (m_currentFolder)
       imapFolder = do_QueryInterface(m_currentFolder);
     m_currentFolder->GetFlags(&folderFlags);
@@ -1179,17 +1181,16 @@ nsresult nsImapOfflineDownloader::Proces
     if (imapFolder && folderFlags & nsMsgFolderFlags::Offline &&
       ! (folderFlags & nsMsgFolderFlags::Virtual))
     {
       rv = m_currentFolder->DownloadAllForOffline(this, m_window);
       if (NS_SUCCEEDED(rv) || rv == NS_BINDING_ABORTED)
         return rv;
       // if this fails and the user didn't cancel/stop, fall through to code that advances to next folder
     }
-    AdvanceToNextFolder();
   }
   if (m_listener)
     m_listener->OnStopRunningUrl(nullptr, NS_OK);
   return rv;
 }
 
 
 NS_IMETHODIMP nsImapOfflineSync::OnStartCopy()
--- a/mailnews/imap/src/nsImapOfflineSync.h
+++ b/mailnews/imap/src/nsImapOfflineSync.h
@@ -38,18 +38,18 @@ public: // set to one folder to playback
   void      SetPseudoOffline(bool pseudoOffline) {m_pseudoOffline = pseudoOffline;}
   bool      ProcessingStaleFolderUpdate() { return m_singleFolderToUpdate != nullptr; }
 
   bool      CreateOfflineFolder(nsIMsgFolder *folder);
   void      SetWindow(nsIMsgWindow *window);
 protected:
   bool      CreateOfflineFolders();
   bool      DestFolderOnSameServer(nsIMsgFolder *destFolder);
-  nsresult  AdvanceToNextServer();
-  nsresult  AdvanceToNextFolder();
+  bool      AdvanceToNextServer();
+  bool      AdvanceToNextFolder();
   void      AdvanceToFirstIMAPFolder();
   void      DeleteAllOfflineOpsForCurrentDB();
   void      ClearCurrentOps();
   // Clears m_currentDB, and unregister listener.
   void      ClearDB();
   void      ProcessFlagOperation(nsIMsgOfflineImapOperation *currentOp);
   void      ProcessKeywordOperation(nsIMsgOfflineImapOperation *op);
   void      ProcessMoveOperation(nsIMsgOfflineImapOperation *currentOp);
@@ -57,21 +57,21 @@ protected:
   void      ProcessEmptyTrash();
   void      ProcessAppendMsgOperation(nsIMsgOfflineImapOperation *currentOp,
                                       nsOfflineImapOperationType opType);
 
   nsCOMPtr <nsIMsgFolder> m_currentFolder;
   nsCOMPtr <nsIMsgFolder> m_singleFolderToUpdate;
   nsCOMPtr <nsIMsgWindow> m_window;
   nsCOMPtr <nsIArray> m_allServers;
-  nsCOMPtr <nsISupportsArray> m_allFolders;
+  nsCOMPtr <nsIArray> m_allFolders;
   nsCOMPtr <nsIMsgIncomingServer> m_currentServer;
-  nsCOMPtr <nsIEnumerator> m_serverEnumerator;
+  nsCOMPtr <nsISimpleEnumerator> m_serverEnumerator;
   nsCOMPtr <nsIFile> m_curTempFile;
-  
+
   nsTArray<nsMsgKey> m_CurrentKeys;
   nsCOMArray<nsIMsgOfflineImapOperation> m_currentOpsToClear;
   uint32_t      m_KeyIndex;
   nsCOMPtr <nsIMsgDatabase> m_currentDB;
   nsCOMPtr <nsIUrlListener> m_listener;
   int32_t	mCurrentUIDValidity;
   int32_t	mCurrentPlaybackOpType;	// kFlagsChanged -> kMsgCopy -> kMsgMoved
   bool	m_mailboxupdatesStarted;
--- a/mailnews/local/src/nsLocalMailFolder.cpp
+++ b/mailnews/local/src/nsLocalMailFolder.cpp
@@ -586,31 +586,31 @@ nsMsgLocalMailFolder::CreateSubfolderInt
 
 NS_IMETHODIMP nsMsgLocalMailFolder::CompactAll(nsIUrlListener *aListener,
                                                nsIMsgWindow *aMsgWindow,
                                                bool aCompactOfflineAlso)
 {
   nsresult rv = NS_OK;
   nsCOMPtr<nsIMutableArray> folderArray;
   nsCOMPtr<nsIMsgFolder> rootFolder;
-  nsCOMPtr<nsISupportsArray> allDescendents;
+  nsCOMPtr<nsIArray> allDescendents;
   rv = GetRootFolder(getter_AddRefs(rootFolder));
   nsCOMPtr<nsIMsgPluggableStore> msgStore;
   GetMsgStore(getter_AddRefs(msgStore));
   bool storeSupportsCompaction;
   msgStore->GetSupportsCompaction(&storeSupportsCompaction);
   if (!storeSupportsCompaction)
     return NotifyCompactCompleted();
 
   if (NS_SUCCEEDED(rv) && rootFolder)
   {
-    NS_NewISupportsArray(getter_AddRefs(allDescendents));
-    rootFolder->ListDescendents(allDescendents);
-    uint32_t cnt =0;
-    rv = allDescendents->Count(&cnt);
+    rv = rootFolder->GetDescendants(getter_AddRefs(allDescendents));
+    NS_ENSURE_SUCCESS(rv, rv);
+    uint32_t cnt = 0;
+    rv = allDescendents->GetLength(&cnt);
     NS_ENSURE_SUCCESS(rv, rv);
     folderArray = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
     uint32_t expungedBytes = 0;
     for (uint32_t i = 0; i < cnt; i++)
     {
       nsCOMPtr<nsIMsgFolder> folder = do_QueryElementAt(allDescendents, i, &rv);
       NS_ENSURE_SUCCESS(rv, rv);
 
@@ -655,17 +655,16 @@ NS_IMETHODIMP nsMsgLocalMailFolder::Empt
   if (NS_SUCCEEDED(rv))
   {
     uint32_t flags;
     nsCString trashUri;
     trashFolder->GetURI(trashUri);
     trashFolder->GetFlags(&flags);
     int32_t totalMessages = 0;
     rv = trashFolder->GetTotalMessages(true, &totalMessages);
-
     if (totalMessages <= 0)
     {
       nsCOMPtr<nsISimpleEnumerator> enumerator;
       rv = trashFolder->GetSubFolders(getter_AddRefs(enumerator));
       NS_ENSURE_SUCCESS(rv,rv);
       // Any folders to deal with?
       bool hasMore;
       rv = enumerator->HasMoreElements(&hasMore);
--- a/mailnews/local/src/nsRssIncomingServer.cpp
+++ b/mailnews/local/src/nsRssIncomingServer.cpp
@@ -9,16 +9,17 @@
 #include "nsMsgBaseCID.h"
 #include "nsIFile.h"
 #include "nsIMsgFolderNotificationService.h"
 
 #include "nsIMsgLocalMailFolder.h"
 #include "nsIDBFolderInfo.h"
 #include "nsServiceManagerUtils.h"
 #include "nsComponentManagerUtils.h"
+#include "nsArrayUtils.h"
 #include "nsMsgUtils.h"
 
 nsrefcnt nsRssIncomingServer::gInstanceCount    = 0;
 
 NS_IMPL_ISUPPORTS_INHERITED3(nsRssIncomingServer,
                              nsMsgIncomingServer,
                              nsIRssIncomingServer,
                              nsIMsgFolderListener,
@@ -245,30 +246,29 @@ nsresult nsRssIncomingServer::FolderChan
     NS_ENSURE_SUCCESS(rv, rv);
     rssDownloader->UpdateSubscriptionsDS(aFolder, aUnsubscribe);
 
     if (!aUnsubscribe)
     {
       // If the user was moving a set of nested folders, we only
       // get a single notification, so we need to iterate over all of the
       // descedent folders of the folder whose location has changed.
-      nsCOMPtr<nsISupportsArray> allDescendents;
-      NS_NewISupportsArray(getter_AddRefs(allDescendents));
-      rv = aFolder->ListDescendents(allDescendents);
+      nsCOMPtr<nsIArray> allDescendents;
+      rv = aFolder->GetDescendants(getter_AddRefs(allDescendents));
       NS_ENSURE_SUCCESS(rv, rv);
 
       uint32_t cnt = 0;
-      allDescendents->Count(&cnt);
+      allDescendents->GetLength(&cnt);
 
       nsCOMPtr<nsIMsgFolder> rssFolder;
 
       for (uint32_t index = 0; index < cnt; index++)
       {
         rssFolder = do_QueryElementAt(allDescendents, index, &rv);
-        if (rssFolder)
+        if (NS_SUCCEEDED(rv) && rssFolder)
           rssDownloader->UpdateSubscriptionsDS(rssFolder, aUnsubscribe);
       }
     }
   }
   return rv;
 }
 
 NS_IMETHODIMP
--- a/mailnews/news/src/nsNewsDownloader.cpp
+++ b/mailnews/news/src/nsNewsDownloader.cpp
@@ -373,37 +373,37 @@ nsMsgDownloadAllNewsgroups::OnStopRunnin
     }
   }
   else if (m_listener)  // notify main observer.
     m_listener->OnStopRunningUrl(url, exitCode);
 
   return rv;
 }
 
-// leaves m_currentServer at the next nntp "server" that
-// might have folders to download for offline use. If no more servers,
-// m_currentServer will be left at nullptr.
-// Also, sets up m_serverEnumerator to enumerate over the server
-// If no servers found, m_serverEnumerator will be left at null,
-nsresult nsMsgDownloadAllNewsgroups::AdvanceToNextServer(bool *done)
+/**
+ * Leaves m_currentServer at the next nntp "server" that
+ * might have folders to download for offline use. If no more servers,
+ * m_currentServer will be left at nullptr and the function returns false.
+ * Also, sets up m_serverEnumerator to enumerate over the server.
+ * If no servers found, m_serverEnumerator will be left at null.
+ */
+bool nsMsgDownloadAllNewsgroups::AdvanceToNextServer()
 {
   nsresult rv;
 
-  NS_ENSURE_ARG(done);
-
-  *done = true;
   if (!m_allServers)
   {
     nsCOMPtr<nsIMsgAccountManager> accountManager =
              do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
     NS_ASSERTION(accountManager && NS_SUCCEEDED(rv), "couldn't get account mgr");
-    if (!accountManager || NS_FAILED(rv)) return rv;
+    if (!accountManager || NS_FAILED(rv))
+      return false;
 
     rv = accountManager->GetAllServers(getter_AddRefs(m_allServers));
-    NS_ENSURE_SUCCESS(rv, rv);
+    NS_ENSURE_SUCCESS(rv, false);
   }
   uint32_t serverIndex = 0;
   if (m_currentServer)
   {
     rv = m_allServers->IndexOf(0, m_currentServer, &serverIndex);
     if (NS_FAILED(rv))
       serverIndex = -1;
 
@@ -417,46 +417,49 @@ nsresult nsMsgDownloadAllNewsgroups::Adv
   while (serverIndex < numServers)
   {
     nsCOMPtr<nsIMsgIncomingServer> server = do_QueryElementAt(m_allServers, serverIndex);
     serverIndex++;
 
     nsCOMPtr <nsINntpIncomingServer> newsServer = do_QueryInterface(server);
     if (!newsServer) // we're only looking for news servers
       continue;
+
     if (server)
     {
       m_currentServer = server;
       server->GetRootFolder(getter_AddRefs(rootFolder));
       if (rootFolder)
       {
-        NS_NewISupportsArray(getter_AddRefs(m_allFolders));
-        rv = rootFolder->ListDescendents(m_allFolders);
+        rv = rootFolder->GetDescendants(getter_AddRefs(m_allFolders));
         if (NS_SUCCEEDED(rv))
-          m_allFolders->Enumerate(getter_AddRefs(m_serverEnumerator));
-        if (NS_SUCCEEDED(rv) && m_serverEnumerator)
         {
-          rv = m_serverEnumerator->First();
-          if (NS_SUCCEEDED(rv))
+          rv = m_allFolders->Enumerate(getter_AddRefs(m_serverEnumerator));
+          if (NS_SUCCEEDED(rv) && m_serverEnumerator)
           {
-            *done = false;
-            break;
+            bool hasMore = false;
+            rv = m_serverEnumerator->HasMoreElements(&hasMore);
+            if (NS_SUCCEEDED(rv) && hasMore)
+              return true;
           }
         }
       }
     }
   }
-  return rv;
+  return false;
 }
 
-nsresult nsMsgDownloadAllNewsgroups::AdvanceToNextGroup(bool *done)
+/**
+ * Sets m_currentFolder to the next usable folder.
+ *
+ * @return  False if no more folders found, otherwise true.
+ */
+bool nsMsgDownloadAllNewsgroups::AdvanceToNextGroup()
 {
-  nsresult rv;
-  NS_ENSURE_ARG(done);
-  *done = true;
+  nsresult rv = NS_OK;
 
   if (m_currentFolder)
   {
     nsCOMPtr <nsIMsgNewsFolder> newsFolder = do_QueryInterface(m_currentFolder);
     if (newsFolder)
       newsFolder->SetSaveArticleOffline(false);
 
     nsCOMPtr<nsIMsgMailSession> session =
@@ -468,33 +471,30 @@ nsresult nsMsgDownloadAllNewsgroups::Adv
       m_currentFolder->GetFlags(&folderFlags);
       session->IsFolderOpenInWindow(m_currentFolder, &folderOpen);
       if (!folderOpen && ! (folderFlags & (nsMsgFolderFlags::Trash | nsMsgFolderFlags::Inbox)))
         m_currentFolder->SetMsgDatabase(nullptr);
     }
     m_currentFolder = nullptr;
   }
 
-  *done = false;
-
-  if (!m_currentServer)
-     rv = AdvanceToNextServer(done);
-  else
-     rv = m_serverEnumerator->Next();
-  if (NS_FAILED(rv))
-    rv = AdvanceToNextServer(done);
+  bool hasMore = false;
+  if (m_currentServer)
+    m_serverEnumerator->HasMoreElements(&hasMore);
+  if (!hasMore)
+    hasMore = AdvanceToNextServer();
 
-  if (NS_SUCCEEDED(rv) && !*done && m_serverEnumerator)
+  if (hasMore)
   {
-    nsCOMPtr <nsISupports> supports;
-    rv = m_serverEnumerator->CurrentItem(getter_AddRefs(supports));
-    m_currentFolder = do_QueryInterface(supports);
-    *done = false;
+    nsCOMPtr<nsISupports> supports;
+    rv = m_serverEnumerator->GetNext(getter_AddRefs(supports));
+    if (NS_SUCCEEDED(rv))
+      m_currentFolder = do_QueryInterface(supports);
   }
-  return rv;
+  return m_currentFolder;
 }
 
 nsresult DownloadMatchingNewsArticlesToNewsDB::RunSearch(nsIMsgFolder *folder, nsIMsgDatabase *newsDB, nsIMsgSearchSession *searchSession)
 {
   m_folder = folder;
   m_newsDB = newsDB;
   m_searchSession = searchSession;
 
@@ -508,31 +508,30 @@ nsresult DownloadMatchingNewsArticlesToN
   nsresult rv = searchSession->AddScopeTerm(nsMsgSearchScope::localNews, folder);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return searchSession->Search(m_window);
 }
 
 nsresult nsMsgDownloadAllNewsgroups::ProcessNextGroup()
 {
-  nsresult rv = NS_OK;
   bool done = false;
 
-  while (NS_SUCCEEDED(rv) && !done)
+  while (!done)
   {
-    rv = AdvanceToNextGroup(&done);
-    if (m_currentFolder)
+    done = !AdvanceToNextGroup();
+    if (!done && m_currentFolder)
     {
       uint32_t folderFlags;
       m_currentFolder->GetFlags(&folderFlags);
       if (folderFlags & nsMsgFolderFlags::Offline)
         break;
     }
   }
-  if (NS_FAILED(rv) || done)
+  if (done)
   {
     if (m_listener)
       return m_listener->OnStopRunningUrl(nullptr, NS_OK);
   }
   m_downloadedHdrsForCurGroup = true;
   return m_currentFolder ? m_currentFolder->GetNewMessages(m_window, this) : NS_ERROR_NOT_INITIALIZED;
 }
 
--- a/mailnews/news/src/nsNewsDownloader.h
+++ b/mailnews/news/src/nsNewsDownloader.h
@@ -100,26 +100,26 @@ public:
   virtual ~nsMsgDownloadAllNewsgroups();
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIURLLISTENER
 
   nsresult ProcessNextGroup();
 
 protected:
-  nsresult AdvanceToNextServer(bool *done);
-  nsresult AdvanceToNextGroup(bool *done);
+  bool     AdvanceToNextServer();
+  bool     AdvanceToNextGroup();
   nsresult DownloadMsgsForCurrentGroup();
 
   DownloadMatchingNewsArticlesToNewsDB *m_downloaderForGroup;
 
   nsCOMPtr <nsIMsgFolder> m_currentFolder;
   nsCOMPtr <nsIMsgWindow> m_window;
   nsCOMPtr <nsIArray> m_allServers;
-  nsCOMPtr <nsISupportsArray> m_allFolders;
+  nsCOMPtr <nsIArray> m_allFolders;
   nsCOMPtr <nsIMsgIncomingServer> m_currentServer;
-  nsCOMPtr <nsIEnumerator> m_serverEnumerator;
+  nsCOMPtr <nsISimpleEnumerator> m_serverEnumerator;
   nsCOMPtr <nsIUrlListener> m_listener;
 
   bool m_downloadedHdrsForCurGroup;
 };
 
 #endif