Bug 1185366 - check the full domain of the MX server to differentiate between Outlook.com and Office365. r=Neil
authorBen Bucksch <ben.bucksch@beonex.com>
Mon, 11 Nov 2019 02:01:43 +0100
changeset 37491 8caa76852c2c73c348822f6430782fb2cd8a7146
parent 37490 e504cc780de97396cc5acb29ffe6adbd1770a821
child 37492 a9f7c4aa047f78a9f6f21e9206db567de8196f75
push id396
push userclokep@gmail.com
push dateMon, 06 Jan 2020 23:11:57 +0000
reviewersNeil
bugs1185366
Bug 1185366 - check the full domain of the MX server to differentiate between Outlook.com and Office365. r=Neil
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