Bug 1583777 - Allow useGlobalPreferredServer on incoming servers too. r=BenB
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Wed, 25 Sep 2019 16:03:46 +0100
changeset 37024 0932bea10bc3d0b1e7553697acd4d13c6f4133c8
parent 37023 538d73551084ef5e61ab3b27c3d3ebcd894e31e5
child 37025 acb4414af757785719878354fc7bae9ca00a657f
push id395
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:38:57 +0000
reviewersBenB
bugs1583777
Bug 1583777 - Allow useGlobalPreferredServer on incoming servers too. r=BenB
mail/components/accountcreation/content/accountConfig.js
mail/components/accountcreation/content/createInBackend.js
mail/components/accountcreation/content/readFromXML.js
--- a/mail/components/accountcreation/content/accountConfig.js
+++ b/mail/components/accountcreation/content/accountConfig.js
@@ -107,16 +107,18 @@ AccountConfig.prototype = {
       // Not yet implemented. { Boolean }
       useGlobalInbox: false,
       leaveMessagesOnServer: true,
       daysToLeaveMessagesOnServer: 14,
       deleteByAgeFromServer: true,
       // When user hits delete, delete from local store and from server
       deleteOnServerWhenLocalDelete: true,
       downloadOnBiff: true,
+      // Override `addThisServer` for a specific incoming server
+      useGlobalPreferredServer: false,
 
       // for Microsoft Exchange servers. Optional.
       owaURL: null,
       ewsURL: null,
       easURL: null,
       // for when an addon overrides the account type. Optional.
       addonAccountType: null,
     };
@@ -288,17 +290,20 @@ AccountConfig.prototype = {
         ", username: " +
         usernameToString(config.username) +
         ", password: " +
         passwordToString(config.password)
       );
     }
 
     let result = "Incoming: " + configToString(this.incoming) + "\nOutgoing: ";
-    if (this.outgoing.useGlobalPreferredServer) {
+    if (
+      this.outgoing.useGlobalPreferredServer ||
+      this.incoming.useGlobalPreferredServer
+    ) {
       result += "Use global server";
     } else if (this.outgoing.existingServerKey) {
       result += "Use existing server " + this.outgoing.existingServerKey;
     } else {
       result += configToString(this.outgoing);
     }
     for (let config of this.incomingAlternatives) {
       result += "\nIncoming alt: " + configToString(config);
--- a/mail/components/accountcreation/content/createInBackend.js
+++ b/mail/components/accountcreation/content/createInBackend.js
@@ -91,17 +91,21 @@ function createAccountInBackend(config) 
   );
   assert(
     config.outgoing.addThisServer ||
       config.outgoing.useGlobalPreferredServer ||
       config.outgoing.existingServerKey,
     "No SMTP server: inconsistent flags"
   );
 
-  if (config.outgoing.addThisServer && !outServer) {
+  if (
+    config.outgoing.addThisServer &&
+    !outServer &&
+    !config.incoming.useGlobalPreferredServer
+  ) {
     outServer = MailServices.smtp.createServer();
     outServer.hostname = config.outgoing.hostname;
     outServer.port = config.outgoing.port;
     outServer.authMethod = config.outgoing.auth;
     if (config.outgoing.auth > 1) {
       outServer.username = username;
       outServer.password = config.incoming.password;
       if (config.rememberPassword && config.incoming.password.length) {
@@ -178,20 +182,25 @@ function createAccountInBackend(config) 
 
   // due to accepted conventions, news accounts should default to plain text
   if (config.incoming.type == "nntp") {
     identity.composeHtml = false;
   }
 
   identity.valid = true;
 
-  if (config.outgoing.existingServerKey) {
-    identity.smtpServerKey = config.outgoing.existingServerKey;
-  } else if (!config.outgoing.useGlobalPreferredServer) {
-    identity.smtpServerKey = outServer.key;
+  if (
+    !config.outgoing.useGlobalPreferredServer &&
+    !config.incoming.useGlobalPreferredServer
+  ) {
+    if (config.outgoing.existingServerKey) {
+      identity.smtpServerKey = config.outgoing.existingServerKey;
+    } else {
+      identity.smtpServerKey = outServer.key;
+    }
   }
 
   // account and hook up
   // Note: Setting incomingServer will cause the AccountManager to refresh
   // itself, which could be a problem if we came from it and we haven't set
   // the identity (see bug 521955), so make sure everything else on the
   // account is set up before you set the incomingServer.
   let account = MailServices.accounts.createAccount();
--- a/mail/components/accountcreation/content/readFromXML.js
+++ b/mail/components/accountcreation/content/readFromXML.js
@@ -178,16 +178,26 @@ function readFromXML(clientConfigXML) {
           if ("downloadOnBiff" in iX.pop3) {
             iO.downloadOnBiff = sanitize.boolean(iX.pop3.downloadOnBiff);
           }
         } catch (e) {
           logException(e);
         }
       }
 
+      try {
+        if ("useGlobalPreferredServer" in iX) {
+          iO.useGlobalPreferredServer = sanitize.boolean(
+            iX.useGlobalPreferredServer
+          );
+        }
+      } catch (e) {
+        logException(e);
+      }
+
       // processed successfully, now add to result object
       if (!d.incoming.hostname) {
         // first valid
         d.incoming = iO;
       } else {
         d.incomingAlternatives.push(iO);
       }
     } catch (e) {