Bug 1185366 - check the full domain of the MX server to differentiate between Outlook.com and Office365. r=Neil a=jorgk
authorBen Bucksch <ben.bucksch@beonex.com>
Mon, 11 Nov 2019 02:01:43 +0100
changeset 37272 8c3e92a5c1e90562fc5a3837a2a606031bd2cee8
parent 37271 d66670635cca535201a53d1e7037dd9bd57fa331
child 37273 7b4e0757efc6667b5f570909efee795615cf7848
push id395
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:38:57 +0000
reviewersNeil, jorgk
bugs1185366
Bug 1185366 - check the full domain of the MX server to differentiate between Outlook.com and Office365. r=Neil a=jorgk
mail/components/accountcreation/content/fetchConfig.js
--- a/mail/components/accountcreation/content/fetchConfig.js
+++ b/mail/components/accountcreation/content/fetchConfig.js
@@ -189,21 +189,44 @@ function fetchConfigForMX(domain, succes
       let sld = Services.eTLD.getBaseDomainFromHost(mxHostname);
       ddump("base domain " + sld + " for " + mxHostname);
       if (sld == sanitizedDomain) {
         errorCallback(
           new Exception("MX lookup would be no different from domain")
         );
         return;
       }
-      sucAbortable.current = fetchConfigFromDB(
+
+      // In addition to just the base domain, also check the full domain of the MX server
+      // to differentiate between Outlook.com/Hotmail and Office365 business domains.
+      let mxDomain;
+      try {
+        mxDomain = Services.eTLD.getNextSubDomain(mxHostname);
+      } catch (ex) {
+        // e.g. hostname doesn't have enough components
+        console.error(ex); // not fatal
+      }
+      let priority = new PriorityOrderAbortable(successCallback, errorCallback);
+      if (mxDomain && sld != mxDomain) {
+        let call = priority.addCall();
+        let fetch = fetchConfigFromDB(
+          mxDomain,
+          call.successCallback(),
+          call.errorCallback()
+        );
+        call.setAbortable(fetch);
+      }
+      let call = priority.addCall();
+      let fetch = fetchConfigFromDB(
         sld,
-        successCallback,
-        errorCallback
+        call.successCallback(),
+        call.errorCallback()
       );
+      call.setAbortable(fetch);
+      sucAbortable.current = priority;
     },
     errorCallback
   );
   return sucAbortable;
 }
 
 /**
  * Queries the DNS MX records for a given domain. Calls `successCallback` with