Bug 861767 - Use server.protocolInfo.requiresUsername instead of hardcoding type != "nntp" in CheckUserServerChanges. r=mkmelin
authoraceman <acelists@atlas.sk>
Wed, 29 May 2013 18:52:29 -0400
changeset 15685 b63bf044ddcc2681330da391edcf68c5a44fa2d8
parent 15684 4a0ad377d047a01eea96974faf90a71230c4143f
child 15686 3a04eb8b4f839c89153a7bdaa54930dccc6195a2
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)
reviewersmkmelin
bugs861767
Bug 861767 - Use server.protocolInfo.requiresUsername instead of hardcoding type != "nntp" in CheckUserServerChanges. r=mkmelin
mailnews/base/prefs/content/AccountManager.js
--- a/mailnews/base/prefs/content/AccountManager.js
+++ b/mailnews/base/prefs/content/AccountManager.js
@@ -482,16 +482,18 @@ function checkUserServerChanges(showAler
   var accountValues = getValueArrayFor(currentAccount);
   if (!accountValues)
     return true;
 
   var pageElements = getPageFormElements();
   if (!pageElements)
     return true;
 
+  let currentServer = currentAccount ? currentAccount.incomingServer : null;
+
   // Get the new username, hostname and type from the page
   var newUser, newHost, newType, oldUser, oldHost;
   var uIndx, hIndx;
   for (let i = 0; i < pageElements.length; i++) {
     if (pageElements[i].id) {
       let vals = pageElements[i].id.split(".");
       if (vals.length >= 2) {
         let type = vals[0];
@@ -512,18 +514,18 @@ function checkUserServerChanges(showAler
         }
         else if (slot == "type")
           newType = getFormElementValue(pageElements[i]);
       }
     }
   }
 
   var checkUser = true;
-  // There is no username defined for news so reset it.
-  if (newType == "nntp") {
+  // There is no username needed for e.g. news so reset it.
+  if (currentServer && !currentServer.protocolInfo.requiresUsername) {
     oldUser = newUser = "";
     checkUser = false;
   }
   alertText = null;
   // If something is changed then check if the new user/host already exists.
   if ((oldUser != newUser) || (oldHost != newHost)) {
     newUser = newUser.trim();
     newHost = cleanUpHostName(newHost);
@@ -531,17 +533,17 @@ function checkUserServerChanges(showAler
       alertText = prefBundle.getString("userNameEmpty");
     }
     else if (!isLegalHostNameOrIP(newHost)) {
       alertText = prefBundle.getString("enterValidServerName");
     }
     else {
       let sameServer = MailServices.accounts
                                    .findRealServer(newUser, newHost, newType, 0);
-      if (sameServer && (sameServer != currentAccount.incomingServer)) {
+      if (sameServer && (sameServer != currentServer)) {
         alertText = prefBundle.getString("modifiedAccountExists");
       } else {
         // New hostname passed all checks. We may have cleaned it up so set
         // the new value back into the input element.
         setFormElementValue(pageElements[hIndx], newHost);
       }
     }
 
@@ -557,18 +559,18 @@ function checkUserServerChanges(showAler
       return !showAlert;
     }
 
     // If username is changed remind users to change Your Name and Email Address.
     // If server name is changed and has defined filters then remind users
     // to edit rules.
     if (showAlert) {
       let filterList;
-      if (currentAccount && checkUser) {
-        filterList = currentAccount.incomingServer.getEditableFilterList(null);
+      if (currentServer && checkUser) {
+        filterList = currentServer.getEditableFilterList(null);
       }
       let changeText = "";
       if ((oldHost != newHost) &&
           (filterList != undefined) && filterList.filterCount)
         changeText = prefBundle.getString("serverNameChanged");
       // In the event that oldHost == newHost or oldUser == newUser,
       // the \n\n will be trimmed off before the message is shown.
       if (oldUser != newUser)