Bug 1518890 - [autoconfig] Pass Exchange URL from account creation dialog to addon. r=Neil
authorBen Bucksch <ben.bucksch>
Thu, 10 Jan 2019 08:18:00 +0100
changeset 34157 1ff4cbc59aae01ffd7fbb94852cbf07223e7806b
parent 34156 130e9b3087d79100c46fa00b54150d36267bf788
child 34158 67c263d7544b2b52ddcdeb9ed35d35737b6fd758
push id389
push userclokep@gmail.com
push dateMon, 18 Mar 2019 19:01:53 +0000
reviewersNeil
bugs1518890
Bug 1518890 - [autoconfig] Pass Exchange URL from account creation dialog to addon. r=Neil
mail/components/accountcreation/content/createInBackend.js
mail/components/accountcreation/content/verifyConfig.js
--- a/mail/components/accountcreation/content/createInBackend.js
+++ b/mail/components/accountcreation/content/createInBackend.js
@@ -39,53 +39,37 @@ function createAccountInBackend(config) 
     inServer.socketType = Ci.nsMsgSocketType.SSL;
   else if (config.incoming.socketType == 3) // STARTTLS
     inServer.socketType = Ci.nsMsgSocketType.alwaysSTARTTLS;
   // inServer.prettyName = config.displayName;
   inServer.prettyName = config.identity.emailAddress;
 
   inServer.doBiff = true;
   inServer.biffMinutes = config.incoming.checkInterval;
-  const loginAtStartupPrefTemplate =
-    "mail.server.%serverkey%.login_at_startup";
-  var loginAtStartupPref =
-    loginAtStartupPrefTemplate.replace("%serverkey%", inServer.key);
-  Services.prefs.setBoolPref(loginAtStartupPref,
-                             config.incoming.loginAtStartup);
+  inServer.setBoolValue("login_at_startup", config.incoming.loginAtStartup);
   if (config.incoming.type == "pop3") {
-    const leaveOnServerPrefTemplate =
-      "mail.server.%serverkey%.leave_on_server";
-    const daysToLeaveOnServerPrefTemplate =
-      "mail.server.%serverkey%.num_days_to_leave_on_server";
-    const deleteFromServerPrefTemplate =
-      "mail.server.%serverkey%.delete_mail_left_on_server";
-    const deleteByAgeFromServerPrefTemplate =
-      "mail.server.%serverkey%.delete_by_age_from_server";
-    const downloadOnBiffPrefTemplate =
-      "mail.server.%serverkey%.download_on_biff";
-    var leaveOnServerPref =
-      leaveOnServerPrefTemplate.replace("%serverkey%", inServer.key);
-    var ageFromServerPref =
-      deleteByAgeFromServerPrefTemplate.replace("%serverkey%", inServer.key);
-    var daysToLeaveOnServerPref =
-      daysToLeaveOnServerPrefTemplate.replace("%serverkey%", inServer.key);
-    var deleteFromServerPref =
-      deleteFromServerPrefTemplate.replace("%serverkey%", inServer.key);
-    let downloadOnBiffPref =
-      downloadOnBiffPrefTemplate.replace("%serverkey%", inServer.key);
-    Services.prefs.setBoolPref(leaveOnServerPref,
-                               config.incoming.leaveMessagesOnServer);
-    Services.prefs.setIntPref(daysToLeaveOnServerPref,
-                              config.incoming.daysToLeaveMessagesOnServer);
-    Services.prefs.setBoolPref(deleteFromServerPref,
-                               config.incoming.deleteOnServerWhenLocalDelete);
-    Services.prefs.setBoolPref(ageFromServerPref,
-                               config.incoming.deleteByAgeFromServer);
-    Services.prefs.setBoolPref(downloadOnBiffPref,
-                               config.incoming.downloadOnBiff);
+    inServer.setBoolValue("leave_on_server",
+      config.incoming.leaveMessagesOnServer);
+    inServer.setIntValue("num_days_to_leave_on_server",
+      config.incoming.daysToLeaveMessagesOnServer);
+    inServer.setBoolValue("delete_mail_left_on_server",
+      config.incoming.deleteOnServerWhenLocalDelete);
+    inServer.setBoolValue("delete_by_age_from_server",
+      config.incoming.deleteByAgeFromServer);
+    inServer.setBoolValue("download_on_biff",
+      config.incoming.downloadOnBiff);
+  }
+  if (config.incoming.owaURL) {
+    inServer.setUnicharValue("owa_url", config.incoming.owaURL);
+  }
+  if (config.incoming.ewsURL) {
+    inServer.setUnicharValue("ews_url", config.incoming.ewsURL);
+  }
+  if (config.incoming.easURL) {
+    inServer.setUnicharValue("eas_url", config.incoming.easURL);
   }
   inServer.valid = true;
 
   let username = config.outgoing.auth > 1 ? config.outgoing.username : null;
   let outServer = MailServices.smtp.findServer(username, config.outgoing.hostname);
   assert(config.outgoing.addThisServer ||
          config.outgoing.useGlobalPreferredServer ||
          config.outgoing.existingServerKey,
@@ -99,20 +83,20 @@ function createAccountInBackend(config) 
     if (config.outgoing.auth > 1) {
       outServer.username = username;
       outServer.password = config.incoming.password;
       if (config.rememberPassword && config.incoming.password.length)
         rememberPassword(outServer, config.incoming.password);
     }
 
     if (outServer.authMethod == Ci.nsMsgAuthMethod.OAuth2) {
-      let pref = "mail.smtpserver." + outServer.key + ".";
-      Services.prefs.setCharPref(pref + "oauth2.scope",
+      let prefBranch = "mail.smtpserver." + outServer.key + ".";
+      Services.prefs.setCharPref(prefBranch + "oauth2.scope",
                                  config.oauthSettings.scope);
-      Services.prefs.setCharPref(pref + "oauth2.issuer",
+      Services.prefs.setCharPref(prefBranch + "oauth2.issuer",
                                  config.oauthSettings.issuer);
     }
 
     if (config.outgoing.socketType == 1) // no SSL
       outServer.socketType = Ci.nsMsgSocketType.plain;
     else if (config.outgoing.socketType == 2) // SSL / TLS
       outServer.socketType = Ci.nsMsgSocketType.SSL;
     else if (config.outgoing.socketType == 3) // STARTTLS
--- a/mail/components/accountcreation/content/verifyConfig.js
+++ b/mail/components/accountcreation/content/verifyConfig.js
@@ -88,16 +88,25 @@ function verifyConfig(config, alter, msg
       }
       gEmailWizardLogger.info("Saving oauth parameters for issuer " +
                                config.oauthSettings.issuer);
       inServer.setCharValue("oauth2.scope", config.oauthSettings.scope);
       inServer.setCharValue("oauth2.issuer", config.oauthSettings.issuer);
       gEmailWizardLogger.info("OAuth2 issuer, scope is " +
                               config.oauthSettings.issuer + ", " + config.oauthSettings.scope);
     }
+    if (config.incoming.owaURL) {
+      inServer.setUnicharValue("owa_url", config.incoming.owaURL);
+    }
+    if (config.incoming.ewsURL) {
+      inServer.setUnicharValue("ews_url", config.incoming.ewsURL);
+    }
+    if (config.incoming.easURL) {
+      inServer.setUnicharValue("eas_url", config.incoming.easURL);
+    }
 
     if (inServer.password || inServer.authMethod == Ci.nsMsgAuthMethod.OAuth2) {
       verifyLogon(config, inServer, alter, msgWindow, successCallback, errorCallback);
     } else {
       // Avoid pref pollution, clear out server prefs.
       MailServices.accounts.removeIncomingServer(inServer, true);
       successCallback(config);
     }