Bug 342632 - Adapt callers to defaultAccount being possibly null - calendar/. r=Fallen
authoraceman <acelists@atlas.sk>
Mon, 19 Nov 2018 00:56:50 +0100
changeset 33733 b5de626e716d37cb333bcd462faf6ef5f67064ec
parent 33732 df8923d94a7af8755f16960a6e8f56e5ce68fe11
child 33734 d7cafc35543ea8021b3a095f3783f7283b1ae357
push id388
push userclokep@gmail.com
push dateMon, 28 Jan 2019 20:54:56 +0000
reviewersFallen
bugs342632
Bug 342632 - Adapt callers to defaultAccount being possibly null - calendar/. r=Fallen
calendar/base/modules/utils/calItipUtils.jsm
calendar/base/modules/utils/calProviderUtils.jsm
calendar/itip/calItipEmailTransport.js
--- a/calendar/base/modules/utils/calItipUtils.jsm
+++ b/calendar/base/modules/utils/calItipUtils.jsm
@@ -485,19 +485,23 @@ var calitip = {
             identities = actMgr.getAccount(aMsgHdr.accountKey).identities;
         } else if (aMsgHdr.folder) {
             // Without an account key, we have to revert back to using the server
             identities = actMgr.getIdentitiesForServer(aMsgHdr.folder.server);
         }
 
         let emailMap = {};
         if (!identities || identities.length == 0) {
+            let identity;
             // If we were not able to retrieve identities above, then we have no
-            // choice but to revert to the default identity
-            let identity = actMgr.defaultAccount.defaultIdentity;
+            // choice but to revert to the default identity.
+            let defaultAccount = actMgr.defaultAccount;
+            if (defaultAccount) {
+                identity = defaultAccount.defaultIdentity;
+            }
             if (!identity) {
                 // If there isn't a default identity (i.e Local Folders is your
                 // default identity), then go ahead and use the first available
                 // identity.
                 let allIdentities = actMgr.allIdentities;
                 if (allIdentities.length > 0) {
                     identity = allIdentities.queryElementAt(0, Components.interfaces.nsIMsgIdentity);
                 } else {
--- a/calendar/base/modules/utils/calProviderUtils.jsm
+++ b/calendar/base/modules/utils/calProviderUtils.jsm
@@ -270,23 +270,17 @@ var calprovider = {
             let findIdentity = function(account) {
                 if (account && account.identities.length) {
                     return account.defaultIdentity ||
                            account.identities.queryElementAt(0, Components.interfaces.nsIMsgIdentity);
                 }
                 return null;
             };
 
-            let foundAccount = (function() {
-                try {
-                    return MailServices.accounts.defaultAccount;
-                } catch (e) {
-                    return null;
-                }
-            })();
+            let foundAccount = MailServices.accounts.defaultAccount;
             let foundIdentity = findIdentity(foundAccount);
 
             if (!foundAccount || !foundIdentity) {
                 let accounts = MailServices.accounts.accounts;
                 for (let account of fixIterator(accounts, Components.interfaces.nsIMsgAccount)) {
                     let identity = findIdentity(account);
 
                     if (account && identity) {
--- a/calendar/itip/calItipEmailTransport.js
+++ b/calendar/itip/calItipEmailTransport.js
@@ -146,17 +146,17 @@ calItipEmailTransport.prototype = {
     },
 
     _initEmailTransport: function() {
         this.mHasXpcomMail = true;
 
         try {
             this.mDefaultSmtpServer = MailServices.smtp.defaultServer;
             this.mDefaultAccount = MailServices.accounts.defaultAccount;
-            this.mDefaultIdentity = this.mDefaultAccount.defaultIdentity;
+            this.mDefaultIdentity = this.mDefaultAccount ? this.mDefaultAccount.defaultIdentity : null;
 
             if (!this.mDefaultIdentity) {
                 // If there isn't a default identity (i.e Local Folders is your
                 // default identity, then go ahead and use the first available
                 // identity.
                 let allIdentities = MailServices.accounts.allIdentities;
                 if (allIdentities.length > 0) {
                     this.mDefaultIdentity = allIdentities.queryElementAt(0, Ci.nsIMsgIdentity);
@@ -186,16 +186,19 @@ calItipEmailTransport.prototype = {
             } else {
                 cal.WARN("No email identity configured for calendar " +
                          aItipItem.targetCalendar.name);
             }
         }
         if (!identity) { // use some default identity/account:
             identity = this.mDefaultIdentity;
             account = this.mDefaultAccount;
+            if (!account || !identity) {
+                throw new Error("sendXpcomMail: No usable account and identity found");
+            }
         }
 
         switch (aItipItem.autoResponse) {
             case Ci.calIItipItem.USER: {
                 cal.LOG("sendXpcomMail: Found USER autoResponse type.");
                 // We still need this as a last resort if a user just deletes or
                 //  drags an invitation related event
                 let parent = Services.wm.getMostRecentWindow(null);