Bug 389139 - Do not show the current account in the folderpicker as a target for deferring. Allow hiding/disabling accounts in the picker. ui-r=bwinton, r=Neil, r=mkmelin
authoraceman <acelists@atlas.sk>
Mon, 10 Jun 2013 08:12:47 -0400
changeset 15713 d7d40b3d21d14ba337a00649fd3b1ede1544da6d
parent 15712 c1f0796a0baaf4d702b0c1e86d2132ac68534c10
child 15714 16e20df57d08f38c89a93571c59eb3f410834239
push id942
push userbugzilla@standard8.plus.com
push dateMon, 05 Aug 2013 19:15:38 +0000
treeherdercomm-beta@0e1a1c4a9f0c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbwinton, Neil, mkmelin
bugs389139
Bug 389139 - Do not show the current account in the folderpicker as a target for deferring. Allow hiding/disabling accounts in the picker. ui-r=bwinton, r=Neil, r=mkmelin
mail/locales/en-US/chrome/messenger/am-server-advanced.dtd
mail/locales/en-US/chrome/messenger/folderWidgets.properties
mail/locales/jar.mn
mailnews/base/content/folderWidgets.xml
mailnews/base/prefs/content/am-junk.js
mailnews/base/prefs/content/am-server-advanced.js
mailnews/base/prefs/content/am-server-advanced.xul
mailnews/base/prefs/content/am-server.js
mailnews/base/public/nsIMsgIncomingServer.idl
suite/locales/en-US/chrome/mailnews/folderWidgets.properties
suite/locales/en-US/chrome/mailnews/pref/am-server-advanced.dtd
suite/locales/jar.mn
--- a/mail/locales/en-US/chrome/messenger/am-server-advanced.dtd
+++ b/mail/locales/en-US/chrome/messenger/am-server-advanced.dtd
@@ -20,16 +20,14 @@
 <!ENTITY personalNamespace.accesskey "P">
 <!ENTITY publicNamespace.label "Public (shared):">
 <!ENTITY publicNamespace.accesskey "u">
 <!ENTITY otherUsersNamespace.label "Other Users:">
 <!ENTITY otherUsersNamespace.accesskey "O">
 <!ENTITY overrideNamespaces.label "Allow server to override these namespaces">
 <!ENTITY overrideNamespaces.accesskey "A">
 <!ENTITY pop3Desc.label "When downloading pop mail for this server, use the following folder for new mail:" >
-<!ENTITY globalInbox.label "Global Inbox (Local Folders Account)">
-<!ENTITY globalInbox.accesskey "G">
 <!ENTITY accountDirectory.label "Inbox for this server's account">
 <!ENTITY accountDirectory.accesskey "S">
 <!ENTITY deferToServer.label "Inbox for different account">
 <!ENTITY deferToServer.accesskey "D">
 <!ENTITY deferGetNewMail.label "Include this server when getting new mail">
 <!ENTITY deferGetNewMail.accesskey "I">
new file mode 100644
--- /dev/null
+++ b/mail/locales/en-US/chrome/messenger/folderWidgets.properties
@@ -0,0 +1,7 @@
+# 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/.
+
+# LOCALIZATION NOTE(globalInbox)
+# %S=name of the Local folders account
+globalInbox=Global Inbox (%S)
--- a/mail/locales/jar.mn
+++ b/mail/locales/jar.mn
@@ -46,21 +46,22 @@
   locale/@AB_CD@/messenger/am-im.dtd                                    (%chrome/messenger/am-im.dtd)
   locale/@AB_CD@/messenger/am-serverwithnoidentities.dtd                (%chrome/messenger/am-serverwithnoidentities.dtd)
   locale/@AB_CD@/messenger/am-junk.dtd                                  (%chrome/messenger/am-junk.dtd)
   locale/@AB_CD@/messenger/prefs.properties                             (%chrome/messenger/prefs.properties)
   locale/@AB_CD@/messenger/smtpEditOverlay.dtd                          (%chrome/messenger/smtpEditOverlay.dtd)
   locale/@AB_CD@/messenger/am-smime.dtd                                 (%chrome/messenger/am-smime.dtd)
   locale/@AB_CD@/messenger/am-smime.properties                          (%chrome/messenger/am-smime.properties)
   locale/@AB_CD@/messenger/messenger.properties                         (%chrome/messenger/messenger.properties)
-  locale/@AB_CD@/messenger/folderpane.dtd                               (%chrome/messenger/folderpane.dtd)
   locale/@AB_CD@/messenger/newFolderDialog.dtd                          (%chrome/messenger/newFolderDialog.dtd)
   locale/@AB_CD@/messenger/newTagDialog.dtd                             (%chrome/messenger/newTagDialog.dtd)
   locale/@AB_CD@/messenger/renameFolderDialog.dtd                       (%chrome/messenger/renameFolderDialog.dtd)
+  locale/@AB_CD@/messenger/folderpane.dtd                               (%chrome/messenger/folderpane.dtd)
   locale/@AB_CD@/messenger/folderProps.dtd                              (%chrome/messenger/folderProps.dtd)
+  locale/@AB_CD@/messenger/folderWidgets.properties                     (%chrome/messenger/folderWidgets.properties)
   locale/@AB_CD@/messenger/subscribe.dtd                                (%chrome/messenger/subscribe.dtd)
   locale/@AB_CD@/messenger/subscribe.properties                         (%chrome/messenger/subscribe.properties)
   locale/@AB_CD@/messenger/msgFolderPickerOverlay.dtd                   (%chrome/messenger/msgFolderPickerOverlay.dtd)
   locale/@AB_CD@/messenger/msgHdrViewOverlay.dtd                        (%chrome/messenger/msgHdrViewOverlay.dtd)
   locale/@AB_CD@/messenger/editContactOverlay.dtd                       (%chrome/messenger/editContactOverlay.dtd)
   locale/@AB_CD@/messenger/editContactOverlay.properties                (%chrome/messenger/editContactOverlay.properties)
   locale/@AB_CD@/messenger/mailEditorOverlay.dtd                        (%chrome/messenger/mailEditorOverlay.dtd)
   locale/@AB_CD@/messenger/msgSynchronize.dtd                           (%chrome/messenger/msgSynchronize.dtd)
--- a/mailnews/base/content/folderWidgets.xml
+++ b/mailnews/base/content/folderWidgets.xml
@@ -13,16 +13,19 @@
   <binding id="folder-menupopup"
            extends="chrome://global/content/bindings/popup.xml#popup">
     <implementation>
       <constructor><![CDATA[
         Components.utils.import("resource:///modules/mailServices.js", this);
         Components.utils.import("resource:///modules/MailUtils.js", this);
         Components.utils.import("resource:///modules/folderUtils.jsm", this);
         Components.utils.import("resource:///modules/iteratorUtils.jsm", this);
+        Components.utils.import("resource:///modules/StringBundle.js", this);
+        this._stringBundle = new this
+            .StringBundle("chrome://messenger/locale/folderWidgets.properties");
 
         // Find out if we are in a wrapper (customize toolbars mode is active).
         let inWrapper = false;
         let node = this;
         while (node instanceof XULElement) {
           if (node.id.startsWith("wrapper-")) {
             inWrapper = true;
             break;
@@ -72,16 +75,18 @@
         <body><![CDATA[
           if (!this._initialized)
             return;
 
           this.MailServices.mailSession.RemoveFolderListener(this._listener);
         ]]></body>
       </method>
 
+      <field name="_stringBundle">null</field>
+
       <!--
          - If non-null, the subFolders of this nsIMsgFolder will be used to
          - populate this menu.  If this is null, the menu will be populated
          - using the root-folders for all accounts
         -->
       <field name="_parentFolder">null</field>
       <property name="parentFolder"
                 onget="return this._parentFolder;"
@@ -127,17 +132,17 @@
           return aFolder.canSubscribe;
         },
 
         newFolder: function filter_newFolder(aFolder) {
           return aFolder.canCreateSubfolders &&
                  aFolder.server.canCreateFoldersOnServer;
         },
 
-        defered: function filter_defered(aFolder) {
+        deferred: function filter_defered(aFolder) {
           return aFolder.server.canCreateFoldersOnServer &&
                  !aFolder.supportsOffline;
         },
 
         // Folders that can be searched.
         search: function filter_search(aFolder) {
           if (!aFolder.server.canSearchMessages ||
               aFolder.getFlag(Components.interfaces.nsMsgFolderFlags.Virtual))
@@ -314,35 +319,51 @@
           this.MailServices.mailSession.AddFolderListener(this._listener,
                                                           Ci.nsIFolderListener.all);
 
           this._initialized = true;
         ]]></body>
       </method>
 
       <!--
-         - Actually constructs the menu-items based on the folders given
+         - Actually constructs the menu-items based on the folders given.
          -
-         - @param aFolders  an array of nsIMsgFolders to use for building
+         - @param aFolders  An array of nsIMsgFolders to use for building.
         -->
       <method name="_build">
         <parameter name="aFolders"/>
         <body><![CDATA[
-          var folders;
+          let folders;
+          let excludeServers = [];
+          let disableServers = [];
+
+          // excludeServers attribute is a comma separated list of server keys.
+          if (this.hasAttribute("excludeServers"))
+            excludeServers = this.getAttribute("excludeServers").split(",");
+
+          // disableServers attribute is a comma separated list of server keys.
+          if (this.hasAttribute("disableServers"))
+            disableServers = this.getAttribute("disableServers").split(",");
+
           // Extensions and other consumers can add to these modes too, see the
           // above note on the _filters field.
           var mode = this.getAttribute("mode");
           if (mode && mode != "") {
             var filterFunction = this._filters[mode];
             folders = aFolders.filter(filterFunction);
             this._listener._filterFunction = filterFunction;
           } else {
             folders = aFolders;
           }
 
+          if (excludeServers.length > 0) {
+            folders = folders.filter(function(aFolder) {
+              return !(excludeServers.indexOf(aFolder.server.key) != -1); });
+          }
+
           /* This code block will do the following: Add a menu item that refers
              back to the parent folder when there is a showFileHereLabel
              attribute or no mode attribute. However the code won't add such a
              menu item if one of the following conditions is met:
              (*) There is no parent folder
              (*) Current folder has a mode, the parent folder can be selected,
                  no messages can be filed into the parent folder (e.g. when the
                  parent folder is a news group or news server) and the folder
@@ -374,41 +395,48 @@
 
             if (this._parentFolder.noSelect)
               menuitem.setAttribute("disabled", "true");
 
             var sep= document.createElement("menuseparator");
             sep.setAttribute("generated", "true");
             this.appendChild(sep);
           }
-          // Some menus want a "Recent" option, but that should only be on our
-          // top-level menu
-          if (!this._parentFolder && this.getAttribute("showRecent") == "true")
-            this._buildRecentMenu();
 
-          /**
-           * Sorts the list of folders. We give first priority to the sortKey
-           * property, and then via a case-insensitive comparison of names
-           */
-          function nameCompare(a, b) {
-            var sortKey = a.compareSortKeys(b);
-            if (sortKey)
-              return sortKey;
-            return a.prettyName.toLowerCase() > b.prettyName.toLowerCase();
+          let globalInboxFolder = null;
+          // See if this is the toplevel menu (usually with accounts).
+          if (!this._parentFolder) {
+            // Some menus want a "Recent" option, but that should only be on our
+            // top-level menu
+            if (this.getAttribute("showRecent") == "true")
+              this._buildRecentMenu();
+            // If we are showing the accounts for deferring, move Local Folders to the top.
+            if (mode == "deferred") {
+              globalInboxFolder = this.MailServices.accounts.localFoldersServer
+                                                            .rootFolder;
+              let localFoldersIndex = folders.indexOf(globalInboxFolder);
+              if (localFoldersIndex != -1) {
+                folders.splice(localFoldersIndex, 1);
+                folders.unshift(globalInboxFolder);
+              }
+            }
+            // If we're the root of the folder hierarchy, then we actually don't
+            // want to sort the folders, but rather the accounts to which the
+            // folders belong.  Since that sorting was already done, we don't need
+            // to do anything for that case here.
+          } else {
+            // Sorts the list of folders. We give first priority to the sortKey
+            // property if it is available, otherwise a case-insensitive
+            // comparison of names.
+            folders = folders.sort(function nameCompare(a, b) {
+              return a.compareSortKeys(b) ||
+                     a.prettyName.localeCompare(b.prettyName);
+            });
           }
 
-          /**
-           * If we're the root of the folder hierarchy, then we actually don't
-           * want to sort the folders, but rather the accounts to which the
-           * folders belong.  Since that sorting was already done, we don't need
-           * to do anything for that case here
-           */
-          if (this._parentFolder)
-            folders = folders.sort(nameCompare);
-
           /* In some cases, the user wants to have a list of subfolders for only
            * some account types (or maybe all of them). So we use this to
            * determine what the user wanted.
            */
            var shouldExpand;
            var labels = null;
            if (this.getAttribute("expandFolders") == "true" ||
                !this.hasAttribute("expandFolders")) {
@@ -435,18 +463,19 @@
              }
              shouldExpand = function (e) { return types.indexOf(e) != -1; };
            }
 
           // We need to call this, or hasSubFolders will always return false.
           // Remove this workaround when Bug 502900 is fixed.
           this.MailUtils.discoverFolders();
 
-          for each (var folder in folders) {
-            var node;
+          for (let folder of folders) {
+            let node;
+
             // If we're going to add subFolders, we need to make menus, not
             // menuitems.
             if (!folder.hasSubFolders || !shouldExpand(folder.server.type)) {
               node = document.createElement("menuitem");
               // Grumble, grumble, legacy code support
               node.setAttribute("id", folder.URI);
               node.setAttribute("class", "folderMenuItem menuitem-iconic");
               node.setAttribute("generated", "true");
@@ -472,16 +501,19 @@
                 popup.setAttribute("fileHereLabel",
                                    this.getAttribute("fileHereLabel"));
               popup.setAttribute("showFileHereLabel",
                                  this.getAttribute("showFileHereLabel"));
               popup.setAttribute("oncommand",
                                  this.getAttribute("oncommand"));
               popup.setAttribute("mode",
                                  this.getAttribute("mode"));
+              if (this.hasAttribute("disableServers"))
+                popup.setAttribute("disableServers",
+                                   this.getAttribute("disableServers"));
               if (this.hasAttribute("position"))
                 popup.setAttribute("position",
                                    this.getAttribute("position"));
 
               // If there are labels, add the labels now
               if (labels) {
                 var serverNode = document.createElement("menuitem");
                 serverNode.setAttribute("label", labels[folder.server.type]);
@@ -491,23 +523,30 @@
                 var sep = document.createElement("menuseparator");
                 sep.setAttribute("generated", "true");
                 popup.appendChild(sep);
               }
 
               popup.setAttribute("generated", "true");
               node.appendChild(popup);
             }
+
+            if (disableServers.indexOf(folder.server.key) != -1)
+              node.setAttribute("disabled", "true");
+
             node._folder = folder;
-            node.setAttribute("label", folder.prettyName);
-
+            let label = "";
+            if (mode == "deferred" && folder.isServer &&
+                folder.server.rootFolder == globalInboxFolder) {
+              label = this._stringBundle.get("globalInbox", [folder.prettyName]);
+            } else {
+              label = folder.prettyName;
+            }
+            node.setAttribute("label", label);
             this._setCssSelectors(folder, node);
-
-            //xxx for later optimization
-            //builtFolders.push(folder);
           }
         ]]></body>
       </method>
 
       <!--
          - Builds a submenu with all of the recently used folders in it, to
          - allow for easy access.
         -->
@@ -648,45 +687,66 @@
             (aFolder.server.type == "rss" && !aFolder.isServer &&
              aFolder.getStringProperty("feedUrl") ? true : false));
         ]]></body>
       </method>
 
       <!--
          - Makes a given folder selected.
          -
-         - @param aFolder  the folder to select
-         - @note If aFolder is not in this popup, but is instead a descendant of
-         -       a member of the popup, that ancestor will be selected.
+         - @param aFolder  the folder to select (if unset, then choose first folder)
+         - @note  If aFolder is not in this popup, but is instead a descendant of
+         -        a member of the popup, that ancestor will be selected.
+         - @return  true if any usable folder was found, otherwise false.
         -->
       <method name="selectFolder">
         <parameter name="aFolder"/>
         <body><![CDATA[
-          for (var i in this.childNodes) {
-            var child = this.childNodes[i];
-            if (!child || !child._folder)
+          // Set the label of the aParent element as if aFolder had been selected.
+          function setupParent(aFolder, aParent) {
+            aParent.setAttribute("label", aFolder.name);
+            aParent.setAttribute("IsServer", aFolder.isServer);
+            aParent.setAttribute("IsSecure", aFolder.server.isSecure);
+            aParent.setAttribute("ServerType", aFolder.server.type);
+          }
+          for (let child of this.childNodes) {
+            if (!child || !child._folder || child.disabled)
               continue;
             // Is this the folder in question or subfolder of the folder?
-            if ((child._folder.URI == aFolder.URI) ||
+            if (!aFolder || (child._folder.URI == aFolder.URI) ||
                 (child.tagName == "menu" &&
                  child._folder.isAncestorOf(aFolder))) {
-              if (child._folder.URI == aFolder.URI) {
-                // Making an assumption about our DOM positioning here.
-                this.parentNode.selectedIndex = i;
+              if (!aFolder || (child._folder.URI == aFolder.URI))
+                this.parentNode.selectedItem = child;
+
+              if (aFolder) {
+                // If this is a subfolder of what's in question, we merely appear
+                // to select this node.
+                setupParent(aFolder || child._folder, this.parentNode);
               }
-              // If this is a subfolder of what's in question, we merely appear
-              // to select this node.
-              this.parentNode.setAttribute("label", aFolder.name);
-              this.parentNode.setAttribute("IsServer", aFolder.isServer);
-              this.parentNode.setAttribute("IsSecure", aFolder.server.isSecure);
-              this.parentNode.setAttribute("ServerType", aFolder.server.type);
-              return;
+              return true;
             }
           }
-          throw "unable to find folder to select!";
+
+          if (aFolder) {
+            // If the caller specified a folder to select and it was not
+            // found, blow up.
+            throw new Error("Unable to select folder " + aFolder.prettyName +
+                            " in the picker!");
+          } else {
+            // If the caller didn't care much but nothing got selected,
+            // this means there are at most some disabled items in the menulist.
+            // Pretend to select the first one so that the widget is not shown
+            // empty.
+            if (this.childNodes.length > 0)
+              setupParent(this.getItemAtIndex(0)._folder, this.parentNode);
+            else
+              Components.utils.reportError("Unable to find any folder in the picker!");
+          }
+          return false;
         ]]></body>
       </method>
 
       <!--
          - Removes all menu-items for this popup, resets all fields, and
          - removes the listener.  This function is invoked when a change
          - that affects this menu is detected by our listener.
         -->
@@ -698,17 +758,16 @@
               continue;
             if ("_teardown" in child)
               child._teardown();
             this.removeChild(child);
           }
 
           this._removeListener();
 
-          this._folders = null;
           this._initialized = false;
         ]]></body>
       </method>
     </implementation>
 
     <handlers>
       <!--
          - In order to improve performance, we're not going to build any of the
--- a/mailnews/base/prefs/content/am-junk.js
+++ b/mailnews/base/prefs/content/am-junk.js
@@ -48,20 +48,20 @@ function onInit(aPageId, aServerId)
   document.getElementById("actionTargetAccount")
           .setAttribute("label", prettyFolderName(server));
   document.getElementById("actionAccountPopup").selectFolder(server);
 
   let folder = null;
   try {
     folder = GetMsgFolderFromUri(spamActionTargetFolder, true);
     document.getElementById("actionFolderPopup").selectFolder(folder);
-  } catch (e) {
-    // OK for folder to not exist.
+  } catch (e) { } // OK for the folder to not exist.
+  if (!folder)
     folder = GetMsgFolderFromUri(spamActionTargetFolder, false);
-  }
+
   document.getElementById("actionTargetFolder")
           .setAttribute("label", prettyFolderName(folder));
 
   var currentArray = [];
   if (document.getElementById("server.useWhiteList").checked)
     currentArray = document.getElementById("server.whiteListAbURI").value.split(" ");
 
   // set up the whitelist UI
--- a/mailnews/base/prefs/content/am-server-advanced.js
+++ b/mailnews/base/prefs/content/am-server-advanced.js
@@ -4,18 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 Components.utils.import("resource:///modules/mailServices.js");
 Components.utils.import("resource://gre/modules/Services.jsm");
 
 // pull stuff out of window.arguments
 var gServerSettings = window.arguments[0];
 
-var serverList;
-
 var gFirstDeferredAccount;
 // initialize the controls with the "gServerSettings" argument
 
 var gControls;
 function getControls()
 {
   if (!gControls)
     gControls = document.getElementsByAttribute("amsa_persist", "true");
@@ -38,52 +36,51 @@ function onLoad()
               .getFormattedString("forAccount", [prettyName]);
 
   if (gServerSettings.serverType == "imap")
   {
     document.getElementById("pop3Panel").hidden = true;
   }
   else if (gServerSettings.serverType == "pop3")
   {
-    var radioGroup = document.getElementById("folderStorage");
     document.getElementById("imapPanel").hidden = true;
+    let radioGroup = document.getElementById("folderStorage");
+
     gFirstDeferredAccount = gServerSettings.deferredToAccount;
-    var localFoldersAccount = getLocalFoldersAccount();
-    var folderPopup = document.getElementById("deferedServerPopup");
-    if (gFirstDeferredAccount.length)
+    let folderPopup = document.getElementById("deferredServerPopup");
+
+    // The current account should not be shown in the folder picker
+    // of the "other account" option.
+    folderPopup._teardown();
+    folderPopup.setAttribute("excludeServers",
+                             gServerSettings.account.incomingServer.key);
+    folderPopup._ensureInitialized();
+
+    if (gServerSettings.account.incomingServer.isDeferredTo) {
+      // Some other account already defers to this account
+      // therefore this one can't be deferred further.
+      radioGroup.value = "currentAccount";
+      folderPopup.selectFolder();
+      radioGroup.disabled = true;
+    }
+    else if (gFirstDeferredAccount.length)
     {
+      // The current account is already deferred...
       let account = MailServices.accounts.getAccount(gFirstDeferredAccount);
-      if (account)
-      {
-        folderPopup.selectFolder(account.incomingServer.rootFolder);
-      }
-      if (gFirstDeferredAccount == localFoldersAccount.key)
-      {
-        radioGroup.selectedItem = document.getElementById("globalInbox");
-        folderPopup.selectFolder(localFoldersAccount.incomingServer.rootFolder);
-        updateInboxAccount(false, true);
-      }
-      else
-      {
-        radioGroup.selectedItem = document.getElementById("deferToServer");
-        folderPopup.selectFolder(account.incomingServer.rootFolder);
-        updateInboxAccount(true, true);
-      }
+      radioGroup.value = "otherAccount";
+      folderPopup.selectFolder(account.incomingServer.rootFolder);
     }
     else
     {
-      radioGroup.selectedItem = document.getElementById("accountDirectory");
-
-      // we should find out if there's another pop3/movemail server to defer to,
-      // perhaps by checking the number of elements in the picker. For now, 
-      // just use the local folders account
-      folderPopup.selectFolder(localFoldersAccount.incomingServer.rootFolder);
-
-      updateInboxAccount(false, false);
-
+      // Current account is not deferred.
+      radioGroup.value = "currentAccount";
+      // If there are no other suitable accounts to defer to,
+      // then disable the option.
+      if (!folderPopup.selectFolder())
+        document.getElementById("deferToOtherAccount").disabled = true;
     }
   }
 
   var controls = getControls();
 
   for (var i = 0; i < controls.length; i++)
   {
     var slot = controls[i].id;
@@ -101,36 +98,33 @@ function onOk()
 {
   // Handle account deferral settings for POP3 accounts.
   if (gServerSettings.serverType == "pop3")
   {
     var radioGroup = document.getElementById("folderStorage");
     var gPrefsBundle = document.getElementById("bundle_prefs");
 
     // if this account wasn't deferred, and is now...
-    if (radioGroup.value != 1 && !gFirstDeferredAccount.length)
+    if (radioGroup.value != "currentAccount" && !gFirstDeferredAccount.length)
     {
       var confirmDeferAccount =
         gPrefsBundle.getString("confirmDeferAccountWarning");
 
       var confirmTitle = gPrefsBundle.getString("confirmDeferAccountTitle");
 
       if (!Services.prompt.confirm(window, confirmTitle, confirmDeferAccount))
         return false;
     }
     switch (radioGroup.value)
     {
-      case "0":
-        gServerSettings['deferredToAccount'] = getLocalFoldersAccount().key;
-        break;
-      case "1":
+      case "currentAccount":
         gServerSettings['deferredToAccount'] = "";
         break;
-      case "2":
-        var server = document.getElementById("deferedServerFolderPicker")
+      case "otherAccount":
+        let server = document.getElementById("deferredServerFolderPicker")
                              .selectedItem._folder.server;
         let account = MailServices.accounts.FindAccountForServer(server);
         gServerSettings['deferredToAccount'] = account.key;
         break;
     }
   }
 
   // Save the controls back to the "gServerSettings" array.
@@ -147,16 +141,13 @@ function onOk()
     }
   }
 
   return true;
 }
 
 
 // Set radio element choices and picker states
-function updateInboxAccount(enablePicker, enableDeferGetNewMail, event)
+function updateInboxAccount(enablePicker)
 {
-    var picker = document.getElementById('deferedServerFolderPicker');
-    picker.disabled = !enablePicker;
-
-    var deferCheckbox = document.getElementById('deferGetNewMail');
-    deferCheckbox.disabled = !enableDeferGetNewMail
+  document.getElementById("deferredServerFolderPicker").disabled = !enablePicker;
+  document.getElementById("deferGetNewMail").disabled = !enablePicker;
 }
--- a/mailnews/base/prefs/content/am-server-advanced.xul
+++ b/mailnews/base/prefs/content/am-server-advanced.xul
@@ -100,35 +100,38 @@
       </grid>
     </vbox>
 
 
     <!-- POP3 Panel -->
     <vbox id="pop3Panel">
       <label flex="1" control="folderStorage">&pop3Desc.label;</label>
       <hbox align="center">
-        <radiogroup id="folderStorage" orient="horizontal" amsa_persist="true">
+        <radiogroup id="folderStorage"
+                    orient="horizontal"
+                    amsa_persist="true"
+                    onselect="updateInboxAccount(this.selectedIndex == 1);">
           <rows>
             <row>
-              <radio value="1" id = "accountDirectory" label="&accountDirectory.label;"
-                     accesskey="&accountDirectory.accesskey;"
-                     oncommand="updateInboxAccount(false, false)" />
-            </row>
-            <row align = "center">
-              <radio value="0" id = "globalInbox" label="&globalInbox.label;"
-                      oncommand="updateInboxAccount(false, true)" 
-                      accesskey="&globalInbox.accesskey;"/>
+              <radio id="deferToCurrentAccount"
+                     value="currentAccount"
+                     label="&accountDirectory.label;"
+                     accesskey="&accountDirectory.accesskey;"/>
             </row>
             <row>
-              <radio value="2" id="deferToServer" label="&deferToServer.label;"
-                     accesskey="&deferToServer.accesskey;"
-                     oncommand="updateInboxAccount(true, true)"/>
-  	        <menulist id="deferedServerFolderPicker" aria-labelledby="deferToServer">
-                  <menupopup type="folder" id="deferedServerPopup"
-                             expandFolders="false" mode="defered"/>
+              <radio id="deferToOtherAccount"
+                     value="otherAccount"
+                     label="&deferToServer.label;"
+                     accesskey="&deferToServer.accesskey;"/>
+                <menulist id="deferredServerFolderPicker"
+                          aria-labelledby="deferToServer">
+                  <menupopup id="deferredServerPopup"
+                             type="folder"
+                             expandFolders="false"
+                             mode="deferred"/>
                 </menulist>
             </row>
           </rows>
         </radiogroup>
       </hbox>
 
       <separator class="thin"/>
 
--- a/mailnews/base/prefs/content/am-server.js
+++ b/mailnews/base/prefs/content/am-server.js
@@ -94,16 +94,17 @@ function onAdvanced()
 {
   // Store the server type and, if an IMAP or POP3 server,
   // the settings needed for the IMAP/POP3 tab into the array
   var serverSettings = {};
   var serverType = document.getElementById("server.type").getAttribute("value");
   serverSettings.serverType = serverType;
 
   serverSettings.serverPrettyName = gServer.prettyName;
+  serverSettings.account = top.getCurrentAccount();
 
   if (serverType == "imap")
   {
     serverSettings.dualUseFolders = document.getElementById("imap.dualUseFolders").checked;
     serverSettings.usingSubscription = document.getElementById("imap.usingSubscription").checked;
     serverSettings.useIdle = document.getElementById("imap.useIdle").checked;
     serverSettings.maximumConnectionsNumber = document.getElementById("imap.maximumConnectionsNumber").getAttribute("value");
     // string prefs
@@ -292,17 +293,19 @@ function setupImapDeleteUI(aServerId)
   var trashFolderName = getTrashFolderName();
 
   // set folderPicker menulist
   var trashPopup = document.getElementById("msgTrashFolderPopup");
   trashPopup._teardown();
   trashPopup._parentFolder = GetMsgFolderFromUri(aServerId);
   trashPopup._ensureInitialized();
 
-  var trashFolder = GetMsgFolderFromUri(aServerId+"/"+trashFolderName);
+  // TODO: There is something wrong here, selectFolder() fails even if the
+  // folder does exist. Try to fix in bug 802609.
+  let trashFolder = GetMsgFolderFromUri(aServerId + "/" + trashFolderName, false);
   try {
     trashPopup.selectFolder(trashFolder);
   } catch(ex) {
     trashPopup.parentNode.setAttribute("label", trashFolder.prettyName);
   }
   trashPopup.parentNode.folder = trashFolder;
 }
 
--- a/mailnews/base/public/nsIMsgIncomingServer.idl
+++ b/mailnews/base/public/nsIMsgIncomingServer.idl
@@ -468,16 +468,17 @@ interface nsIMsgIncomingServer : nsISupp
   /**
    * spam settings
    */
   readonly attribute nsISpamSettings spamSettings;
   readonly attribute nsIMsgFilterPlugin spamFilterPlugin;
 
   nsIMsgFolder getMsgFolderFromURI(in nsIMsgFolder aFolderResource, in ACString aURI);
 
+  /// Indicates if any other server has deferred storage to this account.
   readonly attribute boolean isDeferredTo;
 
   const long keepDups = 0;
   const long deleteDups = 1;
   const long moveDupsToTrash = 2;
   const long markDupsRead = 3;
 
   attribute long incomingDuplicateAction;
new file mode 100644
--- /dev/null
+++ b/suite/locales/en-US/chrome/mailnews/folderWidgets.properties
@@ -0,0 +1,7 @@
+# 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/.
+
+# LOCALIZATION NOTE(globalInbox)
+# %S=name of the Local folders account
+globalInbox=Global Inbox (%S)
--- a/suite/locales/en-US/chrome/mailnews/pref/am-server-advanced.dtd
+++ b/suite/locales/en-US/chrome/mailnews/pref/am-server-advanced.dtd
@@ -20,16 +20,14 @@
 <!ENTITY personalNamespace.accesskey "P">
 <!ENTITY publicNamespace.label "Public (shared):">
 <!ENTITY publicNamespace.accesskey "u">
 <!ENTITY otherUsersNamespace.label "Other Users:">
 <!ENTITY otherUsersNamespace.accesskey "O">
 <!ENTITY overrideNamespaces.label "Allow server to override these namespaces">
 <!ENTITY overrideNamespaces.accesskey "A">
 <!ENTITY pop3Desc.label "When downloading pop mail for this server, use the following folder for new mail:" >
-<!ENTITY globalInbox.label "Global Inbox (Local Folders Account)">
-<!ENTITY globalInbox.accesskey "G">
 <!ENTITY accountDirectory.label "Inbox for this server's account">
 <!ENTITY accountDirectory.accesskey "S">
 <!ENTITY deferToServer.label "Inbox for different account">
 <!ENTITY deferToServer.accesskey "D">
 <!ENTITY deferGetNewMail.label "Include this server when getting new mail">
 <!ENTITY deferGetNewMail.accesskey "I">
--- a/suite/locales/jar.mn
+++ b/suite/locales/jar.mn
@@ -255,16 +255,17 @@
   locale/@AB_CD@/messenger/eudoraImportMsgs.properties                      (%chrome/mailnews/eudoraImportMsgs.properties)
   locale/@AB_CD@/messenger/downloadheaders.dtd                              (%chrome/mailnews/downloadheaders.dtd)
   locale/@AB_CD@/messenger/fieldMapImport.dtd                               (%chrome/mailnews/fieldMapImport.dtd)
   locale/@AB_CD@/messenger/filter.properties                                (%chrome/mailnews/filter.properties)
   locale/@AB_CD@/messenger/FilterEditor.dtd                                 (%chrome/mailnews/FilterEditor.dtd)
   locale/@AB_CD@/messenger/FilterListDialog.dtd                             (%chrome/mailnews/FilterListDialog.dtd)
   locale/@AB_CD@/messenger/folderpane.dtd                                   (%chrome/mailnews/folderpane.dtd)
   locale/@AB_CD@/messenger/folderProps.dtd                                  (%chrome/mailnews/folderProps.dtd)
+  locale/@AB_CD@/messenger/folderWidgets.properties                         (%chrome/mailnews/folderwidgets.properties)
   locale/@AB_CD@/messenger/gloda.properties                                 (%chrome/mailnews/gloda.properties)
   locale/@AB_CD@/messenger/imapMsgs.properties                              (%chrome/mailnews/imapMsgs.properties)
   locale/@AB_CD@/messenger/importDialog.dtd                                 (%chrome/mailnews/importDialog.dtd)
   locale/@AB_CD@/messenger/importMsgs.properties                            (%chrome/mailnews/importMsgs.properties)
   locale/@AB_CD@/messenger/localMsgs.properties                             (%chrome/mailnews/localMsgs.properties)
   locale/@AB_CD@/messenger/junkLog.dtd                                      (%chrome/mailnews/junkLog.dtd)
   locale/@AB_CD@/messenger/junkMailInfo.dtd                                 (%chrome/mailnews/junkMailInfo.dtd)
   locale/@AB_CD@/messenger/mailEditorOverlay.dtd                            (%chrome/mailnews/mailEditorOverlay.dtd)