Backout bug 749200 / changeset eb8f507508d7 due to suspicion of breaking mozmill tests
authorMark Banner <bugzilla@standard8.plus.com>
Thu, 25 Oct 2012 08:59:02 +0100
changeset 11373 de0531591b521bd986f9a9e29fa71915c016ae79
parent 11372 d06d3a6e01fe2c334cb9195e3a4a6aeafe88b496
child 11374 76cb1dc61a143ed23f2a107f4fb7749e57e05099
push id8506
push userbugzilla@standard8.plus.com
push dateThu, 25 Oct 2012 08:00:07 +0000
treeherdercomm-central@76cb1dc61a14 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs749200
Backout bug 749200 / changeset eb8f507508d7 due to suspicion of breaking mozmill tests
mail/base/content/folderPane.js
mail/base/content/msgViewNavigation.js
mail/components/compose/content/MsgComposeCommands.js
mailnews/base/content/folderWidgets.xml
mailnews/base/prefs/content/AccountManager.js
mailnews/base/util/folderUtils.jsm
suite/mailnews/compose/MsgComposeCommands.js
suite/mailnews/msgViewNavigation.js
--- a/mail/base/content/folderPane.js
+++ b/mail/base/content/folderPane.js
@@ -1181,27 +1181,59 @@ let gFolderTreeView = {
       if (folder) {
         let index = this.getIndexOfFolder(folder);
         if (index != null)
           this.selection.toggleSelect(index);
       }
     }
   },
 
-  _sortedAccounts: function ftv_getSortedAccounts() {
-    let accounts = allAccountsSorted(true);
+  _sortedAccounts: function ftv_getSortedAccounts()
+  {
+      const Cc = Components.classes;
+      const Ci = Components.interfaces;
+      let acctMgr = Cc["@mozilla.org/messenger/account-manager;1"]
+                       .getService(Ci.nsIMsgAccountManager);
+      let accounts = [a for each
+                      (a in fixIterator(acctMgr.accounts, Ci.nsIMsgAccount))];
+      // Bug 41133 workaround
+      accounts = accounts.filter(function fix(a) { return a.incomingServer; });
+
+      // Don't show deferred pop accounts
+      accounts = accounts.filter(function isNotDeferred(a) {
+        let server = a.incomingServer;
+        return !(server instanceof Ci.nsIPop3IncomingServer &&
+                 server.deferredToAccount);
+      });
+
+      // Don't show IM accounts
+      accounts = accounts.filter(function(a) a.incomingServer.type != "im");
 
-    // Don't show deferred pop accounts.
-    accounts = accounts.filter(function isNotDeferred(a) {
-      let server = a.incomingServer;
-      return !(server instanceof Components.interfaces.nsIPop3IncomingServer &&
-               server.deferredToAccount);
-    });
+      function sortAccounts(a, b) {
+        if (a.key == acctMgr.defaultAccount.key)
+          return -1;
+        if (b.key == acctMgr.defaultAccount.key)
+          return 1;
+        let aIsNews = a.incomingServer.type == "nntp";
+        let bIsNews = b.incomingServer.type == "nntp";
+        if (aIsNews && !bIsNews)
+          return 1;
+        if (bIsNews && !aIsNews)
+          return -1;
 
-    return accounts;
+        let aIsLocal = a.incomingServer.type == "none";
+        let bIsLocal = b.incomingServer.type == "none";
+        if (aIsLocal && !bIsLocal)
+          return 1;
+        if (bIsLocal && !aIsLocal)
+          return -1;
+        return 0;
+      }
+      accounts.sort(sortAccounts);
+      return accounts;
   },
 
   /**
    * Contains the set of modes registered with the folder tree, initially those
    * included by default. This is a map from names of modes to their
    * implementations of |IFolderTreeMode|.
    */
   _modes: {
--- a/mail/base/content/msgViewNavigation.js
+++ b/mail/base/content/msgViewNavigation.js
@@ -1,17 +1,15 @@
 /* -*- 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/. */
 
 /*  This file contains the js functions necessary to implement view navigation within the 3 pane. */
 
-Components.utils.import("resource:///modules/folderUtils.jsm");
-
 function GetSubFoldersInFolderPaneOrder(folder)
 {
   var subFolders = folder.subFolders;
   var msgFolders = Array();
 
   // get all the subfolders
   while (subFolders.hasMoreElements()) {
     msgFolders[msgFolders.length] =
@@ -112,21 +110,65 @@ function FindNextFolder()
     if (folder)
       return folder;
   }
   return null;
 }
 
 function GetRootFoldersInFolderPaneOrder()
 {
-  let accounts = allAccountsSorted(false);
+  var acctMgr = Components.classes["@mozilla.org/messenger/account-manager;1"].
+                getService(Components.interfaces.nsIMsgAccountManager);
+  var acctEnum = acctMgr.accounts;
+  var count = acctEnum.Count();
+
+  var accounts = new Array();
+  for (var i = 0; i < count; i++) {
+    var acct = acctEnum.GetElementAt(i)
+                       .QueryInterface(Components.interfaces.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);
+  }
 
-  let serversMsgFolders = [];
-  for each (let account in accounts)
-    serversMsgFolders.push(account.incomingServer.rootMsgFolder);
+  /**
+   * This is our actual function for sorting accounts.  Accounts 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)
+      return -1;
+    if (b.key == acctMgr.defaultAccount.key)
+      return 1;
+    var aIsNews = a.incomingServer.type == "nntp";
+    var bIsNews = b.incomingServer.type == "nntp";
+    if (aIsNews && !bIsNews)
+      return 1;
+    if (bIsNews && !aIsNews)
+      return -1;
+
+    var aIsLocal = a.incomingServer.type == "none";
+    var bIsLocal = b.incomingServer.type == "none";
+    if (aIsLocal && !bIsLocal)
+      return 1;
+    if (bIsLocal && !aIsLocal)
+      return -1;
+    return 0;
+  }
+
+  // sort accounts, so they are in the same order as folder pane
+  accounts.sort(accountCompare)
+
+  var serversMsgFolders = new Array();
+  for each (var acct in accounts)
+    serversMsgFolders.push(acct.incomingServer.rootMsgFolder);
 
   return serversMsgFolders;
 }
 
 function CrossFolderNavigation(type)
 {
   // do cross folder navigation for next unread message/thread and message history
   if (type != nsMsgNavigationType.nextUnreadMessage &&
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -7,17 +7,16 @@
  */
 
 // Ensure the activity modules are loaded for this window.
 Components.utils.import("resource:///modules/activity/activityModules.js");
 Components.utils.import("resource://gre/modules/PluralForm.jsm");
 Components.utils.import("resource:///modules/attachmentChecker.js");
 
 Components.utils.import("resource:///modules/MailUtils.js");
-Components.utils.import("resource:///modules/folderUtils.jsm");
 Components.utils.import("resource:///modules/errUtils.js");
 Components.utils.import("resource:///modules/iteratorUtils.jsm");
 Components.utils.import("resource://gre/modules/InlineSpellChecker.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm")
 Components.utils.import("resource:///modules/mailServices.js");
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource:///modules/cloudFileAccounts.js");
 
@@ -3235,17 +3234,44 @@ function ClearIdentityListPopup(popup)
 {
   if (popup)
     while (popup.hasChildNodes())
       popup.removeChild(popup.lastChild);
 }
 
 function FillIdentityList(menulist)
 {
-  let accounts = allAccountsSorted(true);
+  var mgr = Components.classes["@mozilla.org/messenger/account-manager;1"]
+                      .getService(Components.interfaces.nsIMsgAccountManager);
+  var accounts = toArray(fixIterator(mgr.accounts,
+                                     Components.interfaces.nsIMsgAccount));
+
+  // Ugly hack to work around bug 41133. :-(
+  accounts = accounts.filter(function isNonSuckyAccount(a) { return !!a.incomingServer; });
+  function sortAccounts(a, b) {
+    if (a.key == mgr.defaultAccount.key)
+      return -1;
+    if (b.key == mgr.defaultAccount.key)
+      return 1;
+    var aIsNews = a.incomingServer.type == "nntp";
+    var bIsNews = b.incomingServer.type == "nntp";
+    if (aIsNews && !bIsNews)
+      return 1;
+    if (bIsNews && !aIsNews)
+      return -1;
+
+    var aIsLocal = a.incomingServer.type == "none";
+    var bIsLocal = b.incomingServer.type == "none";
+    if (aIsLocal && !bIsLocal)
+      return 1;
+    if (bIsLocal && !aIsLocal)
+      return -1;
+    return 0;
+  }
+  accounts.sort(sortAccounts);
 
   let accountHadSeparator = false;
   let firstAccountWithIdentities = true;
   for (let acc = 0; acc < accounts.length; acc++) {
     let account = accounts[acc];
     let identities = toArray(fixIterator(account.identities,
                                          Components.interfaces.nsIMsgIdentity));
 
--- a/mailnews/base/content/folderWidgets.xml
+++ b/mailnews/base/content/folderWidgets.xml
@@ -9,17 +9,16 @@
           xmlns:xbl="http://www.mozilla.org/xbl"
           xmlns:html="http://www.w3.org/1999/xhtml"
           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
   <binding id="folder-menupopup"
            extends="chrome://global/content/bindings/popup.xml#popup">
     <implementation>
       <constructor><![CDATA[
-        Components.utils.import("resource:///modules/folderUtils.jsm", this);
         // If we are a child of a menulist, and we aren't in a wrapper, we
         // need to build our content right away, otherwise the menulist
         // won't have proper sizing.
         let inWrapper = false;
         let node = this;
         while (node) {
           if (/wrapper-.*/.test(node.id)) {
             inWrapper = true;
@@ -253,20 +252,65 @@
 
           // I really wish they'd just make this global...
           const Cc = Components.classes;
           const Ci = Components.interfaces;
 
           let 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
+          // we assume we should build the top-level accounts.  (Actually we
           // build the fake root folders for those accounts.)
           if (!this._parentFolder) {
-            let accounts = this.allAccountsSorted(true);
+            let acctMgr = Cc["@mozilla.org/messenger/account-manager;1"].
+                          getService(Ci.nsIMsgAccountManager);
+            let count = acctMgr.accounts.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
+            // Do this, we'll stick them in an array, and then sort that array.
+            let accounts = [];
+            for (let i = 0; i < count; i++) {
+              let 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);
+            }
+
+            /**
+             * This is our actual function for sorting accounts.  Accounts go
+             * in the following order: (1) default account (2) other mail
+             * accounts (3) Local Folders (4) news
+             */
+            var defaultAccountKey = acctMgr.defaultAccount.key;
+            function accountCompare(a, b) {
+              if (a.key == defaultAccountKey)
+                return -1;
+              if (b.key == defaultAccountKey)
+                return 1;
+
+              let aIsNews = a.incomingServer.type == "nntp";
+              let bIsNews = b.incomingServer.type == "nntp";
+              if (aIsNews && !bIsNews)
+                return 1;
+              if (bIsNews && !aIsNews)
+                return -1;
+
+              let aIsLocal = a.incomingServer.type == "none";
+              let bIsLocal = b.incomingServer.type == "none";
+              if (aIsLocal && !bIsLocal)
+                return 1;
+              if (bIsLocal && !aIsLocal)
+                return -1;
+              return 0;
+            }
+            accounts = accounts.sort(accountCompare);
 
             // Now generate our folder-list.  Note that we'll special case this
             // situation below, to avoid destroying the sort order we just made
             folders = accounts.map(function(acct) acct.incomingServer.rootFolder);
           } else {
             // If we do have a parent folder, then we just build based on those
             // subFolders for that parent
             let myenum = this._parentFolder.subFolders;
@@ -613,19 +657,19 @@
          -
          - @param aFolder    the folder that corresponds to the menu/menuitem
          - @param aMenuNode  the actual DOM node to set attributes on
         -->
       <method name="_setCssSelectors">
         <parameter name="aFolder"/>
         <parameter name="aMenuNode"/>
         <body><![CDATA[
-
+          Components.utils.import("resource:///modules/folderUtils.jsm");
           // First set the SpecialFolder attribute
-          aMenuNode.setAttribute("SpecialFolder", this.getSpecialFolderString(aFolder));
+          aMenuNode.setAttribute("SpecialFolder", getSpecialFolderString(aFolder));
 
           // Now set the biffState
           let biffStates = ["NewMail", "NoMail", "UnknownMail"];
           for each (let state in biffStates) {
             if (aFolder.biffState ==
                 Components.interfaces.nsIMsgFolder["nsMsgBiffState_" + state]) {
               aMenuNode.setAttribute("BiffState", state);
               break;
--- a/mailnews/base/prefs/content/AccountManager.js
+++ b/mailnews/base/prefs/content/AccountManager.js
@@ -23,17 +23,16 @@
  * - in the IFRAME inside the page, if there is an onInit() method,
  *   it is called. The onInit method can further update this page based
  *   on values set in the previous step.
  */
 
 Components.utils.import("resource:///modules/iteratorUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource:///modules/mailServices.js");
-Components.utils.import("resource:///modules/folderUtils.jsm");
 
 var gSmtpHostNameIsIllegal = false;
 // If Local directory has changed the app needs to restart. Once this is set
 // a restart will be attempted at each attempt to close the Account manager with OK.
 var gRestartNeeded = false;
 
 // This is a hash-map for every account we've touched in the pane. Each entry
 // has additional maps of attribute-value pairs that we're going to want to save
@@ -1261,19 +1260,46 @@ var gAccountTree = {
     function get(aString) { return bundle.getString(aString); }
     var panels = [{string: get("prefPanel-server"), src: "am-server.xul"},
                   {string: get("prefPanel-copies"), src: "am-copies.xul"},
                   {string: get("prefPanel-synchronization"), src: "am-offline.xul"},
                   {string: get("prefPanel-diskspace"), src: "am-offline.xul"},
                   {string: get("prefPanel-addressing"), src: "am-addressing.xul"},
                   {string: get("prefPanel-junk"), src: "am-junk.xul"}];
 
-    let accounts = allAccountsSorted(false);
+    // Get our account list, and add the proper items
+    var mgr = MailServices.accounts;
+
+    var accounts = [a for each (a in fixIterator(mgr.accounts, Ci.nsIMsgAccount))];
+    // Stupid bug 41133 hack. Grr...
+    accounts = accounts.filter(function fix(a) { return a.incomingServer; });
 
-    let mainTree = document.getElementById("account-tree-children");
+    function sortAccounts(a, b) {
+      if (a.key == mgr.defaultAccount.key)
+        return -1;
+      if (b.key == mgr.defaultAccount.key)
+        return 1;
+      var aIsNews = a.incomingServer.type == "nntp";
+      var bIsNews = b.incomingServer.type == "nntp";
+      if (aIsNews && !bIsNews)
+        return 1;
+      if (bIsNews && !aIsNews)
+        return -1;
+
+      var aIsLocal = a.incomingServer.type == "none";
+      var bIsLocal = b.incomingServer.type == "none";
+      if (aIsLocal && !bIsLocal)
+        return 1;
+      if (bIsLocal && !aIsLocal)
+        return -1;
+      return 0;
+    }
+    accounts.sort(sortAccounts);
+
+    var mainTree = document.getElementById("account-tree-children");
     // Clear off all children...
     while (mainTree.firstChild)
       mainTree.removeChild(mainTree.firstChild);
 
     for each (let account in accounts) {
       let server = account.incomingServer;
 
       if (server.type == "im" && !Services.prefs.getBoolPref("mail.chat.enabled"))
@@ -1285,17 +1311,17 @@ var gAccountTree = {
       var treerow = document.createElement("treerow");
       treeitem.appendChild(treerow);
       var treecell = document.createElement("treecell");
       treerow.appendChild(treecell);
       treecell.setAttribute("label", server.rootFolder.prettyName);
 
       // Now add our panels
       var panelsToKeep = [];
-      let idents = MailServices.accounts.GetIdentitiesForServer(server);
+      var idents = mgr.GetIdentitiesForServer(server);
       if (idents.Count()) {
         panelsToKeep.push(panels[0]); // The server panel is valid
         panelsToKeep.push(panels[1]); // also the copies panel
         panelsToKeep.push(panels[4]); // and addresssing
       }
 
       // Everyone except News, RSS and IM has a junk panel
       // XXX: unextensible!
@@ -1347,17 +1373,17 @@ var gAccountTree = {
         treeitem.setAttribute("container", "true");
         treeitem.setAttribute("open", "true");
       }
       treeitem.setAttribute("PageTag", server ? server.accountManagerChrome
                                               : "am-main.xul");
       treeitem._account = account;
     }
 
-    markDefaultServer(MailServices.accounts.defaultAccount, null);
+    markDefaultServer(mgr.defaultAccount, null);
 
     // Now add the outgoing server node
     var treeitem = document.createElement("treeitem");
     mainTree.appendChild(treeitem);
     var treerow = document.createElement("treerow");
     treeitem.appendChild(treerow);
     var treecell = document.createElement("treecell");
     treerow.appendChild(treecell);
--- a/mailnews/base/util/folderUtils.jsm
+++ b/mailnews/base/util/folderUtils.jsm
@@ -2,20 +2,17 @@
  * 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/. */
 
 /**
  * This file contains helper methods for dealing with nsIMsgFolders.
  */
 
 var EXPORTED_SYMBOLS = ["setPropertyAtoms", "getSpecialFolderString",
-                        "getFolderFromUri", "allAccountsSorted"];
-
-Components.utils.import("resource:///modules/mailServices.js");
-Components.utils.import("resource:///modules/iteratorUtils.jsm");
+                        "getFolderFromUri"];
 
 /**
  * Returns a string representation of a folder's "special" type
  *
  * @param aFolder  the nsIMsgFolder whose special type should be returned
  */
 function getSpecialFolderString(aFolder) {
   const Ci = Components.interfaces;
@@ -105,61 +102,8 @@ function setPropertyAtoms(aFolder, aProp
  * @param aUri  the rdf uri of the folder to return
  */
 function getFolderFromUri(aUri) {
   const Cc = Components.classes;
   const Ci = Components.interfaces;
   return Cc["@mozilla.org/mail/folder-lookup;1"].
          getService(Ci.nsIFolderLookupService).getFolderById(aUri);
 }
-
-/**
- * Returns the sort order value based on the server type to be used for sorting.
- * The servers (accounts) go in the following order:
- * (0) default account, (1) other mail accounts, (2) Local Folders,
- * (3) IM accounts, (4) RSS, (5) News, (9) others (no server)
- * This ordering is encoded in the .sortOrder property of each server type.
- *
- * @param aServer  the server object to be tested
- */
-function getServerSortOrder(aServer) {
-  // If there is no server sort this object to the end.
-  if (!aServer)
-    return 999999999;
-
-  // Otherwise get the server sort order from the Account manager.
-  return MailServices.accounts.getSortOrder(aServer);
-}
-
-/**
- * Compares the passed in accounts according to their precedence.
- */
-function compareAccounts(aAccount1, aAccount2) {
-  return getServerSortOrder(aAccount1.incomingServer)
-           - getServerSortOrder(aAccount2.incomingServer);
-}
-
-/**
- * Returns a list of accounts sorted by server type.
- *
- * @param aExcludeIMAccounts  Remove IM accounts from the list?
- */
-function allAccountsSorted(aExcludeIMAccounts) {
-  // Get the account list, and add the proper items.
-  let accountList = toArray(fixIterator(MailServices.accounts.accounts,
-                                        Components.interfaces.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.
-  accountList = accountList.filter(function hasServer(a) {
-    return a.incomingServer;
-  });
-
-  // Remove IM servers.
-  if (aExcludeIMAccounts) {
-    accountList = accountList.filter(function(a) {
-      return a.incomingServer.type != "im";
-    });
-  }
-
-  return accountList.sort(compareAccounts);
-}
--- a/suite/mailnews/compose/MsgComposeCommands.js
+++ b/suite/mailnews/compose/MsgComposeCommands.js
@@ -1,15 +1,13 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * 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/. */
 
-Components.utils.import("resource:///modules/folderUtils.jsm");
-
 /**
  * interfaces
  */
 const nsIMsgCompDeliverMode = Components.interfaces.nsIMsgCompDeliverMode;
 const nsIMsgCompSendFormat = Components.interfaces.nsIMsgCompSendFormat;
 const nsIMsgCompConvertible = Components.interfaces.nsIMsgCompConvertible;
 const nsIMsgCompType = Components.interfaces.nsIMsgCompType;
 const nsIMsgCompFormat = Components.interfaces.nsIMsgCompFormat;
@@ -2252,17 +2250,42 @@ function ClearIdentityListPopup(popup)
 {
   if (popup)
     while (popup.hasChildNodes())
       popup.removeChild(popup.lastChild);
 }
 
 function FillIdentityList(menulist)
 {
-  var accounts = allAccountsSorted(true);
+  var accounts = queryISupportsArray(gAccountManager.accounts,
+                                     Components.interfaces.nsIMsgAccount);
+  // Ugly hack to work around bug 41133. :-(
+  accounts = accounts.filter(function IsNonSuckyAccount(a) {return !!a.incomingServer;});
+  function SortAccounts(a, b)
+  {
+    if (a.key == gAccountManager.defaultAccount.key)
+      return -1;
+    if (b.key == gAccountManager.defaultAccount.key)
+      return 1;
+    var aIsNews = a.incomingServer.type == "nntp";
+    var bIsNews = b.incomingServer.type == "nntp";
+    if (aIsNews && !bIsNews)
+      return 1;
+    if (bIsNews && !aIsNews)
+      return -1;
+
+    var aIsLocal = a.incomingServer.type == "none";
+    var bIsLocal = b.incomingServer.type == "none";
+    if (aIsLocal && !bIsLocal)
+      return 1;
+    if (bIsLocal && !aIsLocal)
+      return -1;
+    return 0;
+  }
+  accounts.sort(SortAccounts);
 
   for each (let account in accounts)
   {
     let identites = queryISupportsArray(account.identities,
                                         Components.interfaces.nsIMsgIdentity);
     for each (let identity in identites)
     {
       let item = menulist.appendItem(identity.identityName, identity.key,
--- a/suite/mailnews/msgViewNavigation.js
+++ b/suite/mailnews/msgViewNavigation.js
@@ -1,17 +1,15 @@
 /* -*- Mode: javascript; 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/. */
 
 /*  This file contains the js functions necessary to implement view navigation within the 3 pane. */
 
-Components.utils.import("resource:///modules/folderUtils.jsm");
-
 //NOTE: gMessengerBundle must be defined and set or this Overlay won't work
 
 function GetSubFoldersInFolderPaneOrder(folder)
 {
   var subFolders = folder.subFolders;
   var msgFolders = Array();
 
   // get all the subfolders
@@ -114,21 +112,65 @@ function FindNextFolder()
     if (folder)
       return folder;
   }
   return null;
 }
 
 function GetRootFoldersInFolderPaneOrder()
 {
-  var accounts = allAccountsSorted(false);
+  var acctMgr = Components.classes["@mozilla.org/messenger/account-manager;1"].
+                getService(Components.interfaces.nsIMsgAccountManager);
+  var acctEnum = acctMgr.accounts;
+  var count = acctEnum.Count();
+
+  var accounts = new Array();
+  for (var i = 0; i < count; i++) {
+    var acct = acctEnum.GetElementAt(i)
+                       .QueryInterface(Components.interfaces.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)
+      accounts.push(acct);
+  }
 
-  var serversMsgFolders = [];
-  for each (var account in accounts)
-    serversMsgFolders.push(account.incomingServer.rootMsgFolder);
+  /**
+   * This is our actual function for sorting accounts.  Accounts 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)
+      return -1;
+    if (b.key == acctMgr.defaultAccount.key)
+      return 1;
+    var aIsNews = a.incomingServer.type == "nntp";
+    var bIsNews = b.incomingServer.type == "nntp";
+    if (aIsNews && !bIsNews)
+      return 1;
+    if (bIsNews && !aIsNews)
+      return -1;
+
+    var aIsLocal = a.incomingServer.type == "none";
+    var bIsLocal = b.incomingServer.type == "none";
+    if (aIsLocal && !bIsLocal)
+      return 1;
+    if (bIsLocal && !aIsLocal)
+      return -1;
+    return 0;
+  }
+
+  // sort accounts, so they are in the same order as folder pane
+  accounts.sort(accountCompare)
+
+  var serversMsgFolders = new Array();
+  for each (var acct in accounts)
+    serversMsgFolders.push(acct.incomingServer.rootMsgFolder);
 
   return serversMsgFolders;
 }
 
 function CrossFolderNavigation(type)
 {
   // do cross folder navigation for next unread message/thread and message history
   if (type != nsMsgNavigationType.nextUnreadMessage &&