Bug 342632 - Adapt callers to defaultAccount being possibly null - mailnews/. r=mkmelin
authoraceman <acelists@atlas.sk>
Mon, 19 Nov 2018 00:56:48 +0100
changeset 25222 a6f1f63789af294ace5640de1e3d4cbeb9870877
parent 25221 38c2cc49dccc59a155c9060ef557dcadc2b978d3
child 25223 df8923d94a7af8755f16960a6e8f56e5ce68fe11
push id15139
push useracelists@atlas.sk
push dateSun, 18 Nov 2018 23:57:24 +0000
treeherdercomm-central@2dd62f4bcac3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs342632
Bug 342632 - Adapt callers to defaultAccount being possibly null - mailnews/. r=mkmelin
mailnews/base/src/nsMessengerWinIntegration.cpp
mailnews/base/src/nsMsgAccountManager.cpp
mailnews/compose/src/nsMsgComposeService.cpp
mailnews/compose/src/nsMsgSendLater.cpp
mailnews/import/becky/src/nsBeckyFilters.cpp
mailnews/import/test/unit/resources/import_helper.js
mailnews/mapi/mapihook/src/msgMapiImp.cpp
--- a/mailnews/base/src/nsMessengerWinIntegration.cpp
+++ b/mailnews/base/src/nsMessengerWinIntegration.cpp
@@ -1034,17 +1034,18 @@ nsMessengerWinIntegration::SetupInbox()
 
   // get default account
   nsCOMPtr <nsIMsgAccountManager> accountManager =
     do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv,rv);
 
   nsCOMPtr <nsIMsgAccount> account;
   rv = accountManager->GetDefaultAccount(getter_AddRefs(account));
-  if (NS_FAILED(rv)) {
+  NS_ENSURE_SUCCESS(rv, rv);
+  if (!account) {
     // this can happen if we launch mail on a new profile
     // we don't have a default account yet
     mDefaultAccountMightHaveAnInbox = false;
     return NS_OK;
   }
 
   // get incoming server
   nsCOMPtr <nsIMsgIncomingServer> server;
--- a/mailnews/base/src/nsMsgAccountManager.cpp
+++ b/mailnews/base/src/nsMsgAccountManager.cpp
@@ -3670,17 +3670,17 @@ nsMsgAccountManager::GetSortOrder(nsIMsg
   // If the passed in server is the default, return its sort order as 0 regardless
   // of its server sort order.
 
   nsCOMPtr<nsIMsgAccount> defaultAccount;
   nsresult rv = GetDefaultAccount(getter_AddRefs(defaultAccount));
   if (NS_SUCCEEDED(rv) && defaultAccount) {
     nsCOMPtr<nsIMsgIncomingServer> defaultServer;
     rv = m_defaultAccount->GetIncomingServer(getter_AddRefs(defaultServer));
-    if (NS_SUCCEEDED(rv) && defaultServer && (aServer == defaultServer)) {
+    if (NS_SUCCEEDED(rv) && (aServer == defaultServer)) {
       *aSortOrder = 0;
       return NS_OK;
     }
     // It is OK if there is no default account.
   }
 
   // This function returns the sort order by querying the server object for its
   // sort order value and then incrementing it by the position of the server in
--- a/mailnews/compose/src/nsMsgComposeService.cpp
+++ b/mailnews/compose/src/nsMsgComposeService.cpp
@@ -610,17 +610,17 @@ nsMsgComposeService::GetDefaultIdentity(
   nsresult rv;
   nsCOMPtr<nsIMsgAccountManager> accountManager = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIMsgAccount> defaultAccount;
   rv = accountManager->GetDefaultAccount(getter_AddRefs(defaultAccount));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  return defaultAccount->GetDefaultIdentity(_retval);
+  return defaultAccount ? defaultAccount->GetDefaultIdentity(_retval) : NS_OK;
 }
 
 /* readonly attribute boolean logComposePerformance; */
 NS_IMETHODIMP nsMsgComposeService::GetLogComposePerformance(bool *aLogComposePerformance)
 {
   *aLogComposePerformance = mLogComposePerformance;
   return NS_OK;
 }
--- a/mailnews/compose/src/nsMsgSendLater.cpp
+++ b/mailnews/compose/src/nsMsgSendLater.cpp
@@ -511,16 +511,18 @@ nsresult
 nsMsgSendLater::CompleteMailFileSend()
 {
   // get the identity from the key
   // if no key, or we fail to find the identity
   // use the default identity on the default account
   nsCOMPtr<nsIMsgIdentity> identity;
   nsresult rv = GetIdentityFromKey(mIdentityKey, getter_AddRefs(identity));
   NS_ENSURE_SUCCESS(rv,rv);
+  if (!identity)
+    return NS_ERROR_UNEXPECTED;
 
   // If for some reason the tmp file didn't get created, we've failed here
   bool created;
   mTempFile->Exists(&created);
   if (!created)
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIMsgCompFields> compFields = do_CreateInstance(NS_MSGCOMPFIELDS_CONTRACTID, &rv);
@@ -632,16 +634,18 @@ nsMsgSendLater::StartNextMailFileSend(ns
   nsCString identityKey;
   rv = mMessage->GetStringProperty(HEADER_X_MOZILLA_IDENTITY_KEY,
                                    getter_Copies(identityKey));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIMsgIdentity> identity;
   rv = GetIdentityFromKey(identityKey.get(), getter_AddRefs(identity));
   NS_ENSURE_SUCCESS(rv, rv);
+  if (!identity)
+    return NS_ERROR_UNEXPECTED;
 
   // Notify that we're just about to start sending this message
   NotifyListenersOnMessageStartSending(mTotalSendCount, mMessagesToSend.Count(),
                                        identity);
 
   // Setup what we need to parse the data stream correctly
   m_inhead = true;
   m_headersFP = 0;
@@ -1442,24 +1446,27 @@ nsMsgSendLater::GetIdentityFromKey(const
         {
           lookupIdentity.forget(aIdentity);
           return NS_OK;
         }
       }
     }
   }
 
-  // if no aKey, or we failed to find the identity from the key
+  // If no aKey, or we failed to find the identity from the key
   // use the identity from the default account.
   nsCOMPtr<nsIMsgAccount> defaultAccount;
   rv = accountManager->GetDefaultAccount(getter_AddRefs(defaultAccount));
   NS_ENSURE_SUCCESS(rv,rv);
 
-  rv = defaultAccount->GetDefaultIdentity(aIdentity);
-  NS_ENSURE_SUCCESS(rv,rv);
+  if (defaultAccount)
+    rv = defaultAccount->GetDefaultIdentity(aIdentity);
+  else
+    *aIdentity = nullptr;
+
   return rv;
 }
 
 NS_IMETHODIMP
 nsMsgSendLater::OnItemAdded(nsIMsgFolder *aParentItem, nsISupports *aItem)
 {
   // No need to trigger if timer is already set
   if (mTimerSet)
--- a/mailnews/import/becky/src/nsBeckyFilters.cpp
+++ b/mailnews/import/becky/src/nsBeckyFilters.cpp
@@ -761,19 +761,26 @@ nsBeckyFilters::CollectServers()
   nsresult rv;
   nsCOMPtr<nsIMsgAccountManager> accountManager;
   accountManager = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIMsgAccount> defaultAccount;
   rv = accountManager->GetDefaultAccount(getter_AddRefs(defaultAccount));
   NS_ENSURE_SUCCESS(rv, rv);
+  if (defaultAccount)
+    return defaultAccount->GetIncomingServer(getter_AddRefs(mServer));
 
-  nsCOMPtr<nsIMsgIncomingServer> server;
-  return defaultAccount->GetIncomingServer(getter_AddRefs(mServer));
+  // We can also import filters into the Local Folders account.
+  rv = accountManager->GetLocalFoldersServer(getter_AddRefs(mServer));
+  NS_ENSURE_SUCCESS(rv, rv);
+  if (!mServer)
+    return NS_ERROR_UNEXPECTED;
+
+  return NS_OK;
 }
 
 nsresult
 nsBeckyFilters::RemoveConvertedFile()
 {
   nsresult rv = NS_OK;
   if (mConvertedFile) {
     bool exists = false;
--- a/mailnews/import/test/unit/resources/import_helper.js
+++ b/mailnews/import/test/unit/resources/import_helper.js
@@ -21,17 +21,17 @@ var gGenericImportHelper;
 function GenericImportHelper(aModuleType, aModuleSearchString, aFile)
 {
   gGenericImportHelper = null;
   if (!["addressbook", "mail", "settings", "filters"].includes(aModuleType))
     do_throw("Unexpected type passed to the GenericImportHelper constructor");
   this.mModuleType = aModuleType;
   this.mModuleSearchString = aModuleSearchString;
   this.mInterface = this._findInterface();
-  Assert.notEqual(this.mInterface, null);
+  Assert.ok(this.mInterface !== null);
 
   this.mFile = aFile; // checked in the beginImport method
 }
 
 GenericImportHelper.prototype =
 {
   interfaceType: Ci.nsIImportGeneric,
   /**
@@ -228,17 +228,17 @@ AbImportHelper.prototype =
     if (!this.mJsonCards)
       do_throw("The address book must be setup before checking results");
     // When do_test_pending() was called and there is an error the test hangs.
     // This try/catch block will catch any errors and call do_throw() with the
     // error to throw the error and avoid the hang.
     try {
       // make sure an address book was created
       var newAb = this.getAbByName(this.mAbName);
-      Assert.notEqual(newAb, null);
+      Assert.ok(newAb !== null);
       Assert.ok(newAb instanceof Ci.nsIAbDirectory &&
                 newAb.childCards instanceof Ci.nsISimpleEnumerator);
       // get the imported card(s) and check each one
       var iter = newAb.childCards;
       var count = 0;
       for (; iter.hasMoreElements(); count++) {
         var importedCard = iter.getNext().QueryInterface(Ci.nsIAbCard);
         this.compareCards(this.mJsonCards[count], importedCard);
--- a/mailnews/mapi/mapihook/src/msgMapiImp.cpp
+++ b/mailnews/mapi/mapihook/src/msgMapiImp.cpp
@@ -145,20 +145,24 @@ STDMETHODIMP CMapiImp::Login(unsigned lo
     }
     else
     {
       // get default account
       nsresult rv;
       nsCOMPtr <nsIMsgAccountManager> accountManager =
         do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
       NS_ENSURE_SUCCESS(rv,MAPI_E_LOGIN_FAILURE);
-      nsCOMPtr <nsIMsgAccount> account;
-      nsCOMPtr <nsIMsgIdentity> identity;
+
+      nsCOMPtr<nsIMsgAccount> account;
       rv = accountManager->GetDefaultAccount(getter_AddRefs(account));
       NS_ENSURE_SUCCESS(rv,MAPI_E_LOGIN_FAILURE);
+      if (!account)
+        return MAPI_E_LOGIN_FAILURE;
+
+      nsCOMPtr<nsIMsgIdentity> identity;
       rv = account->GetDefaultIdentity(getter_AddRefs(identity));
       NS_ENSURE_SUCCESS(rv,MAPI_E_LOGIN_FAILURE);
       if (!identity)
         return MAPI_E_LOGIN_FAILURE;
       identity->GetKey(id_key);
     }
 
     // finally register(create) the session.
@@ -263,16 +267,18 @@ nsresult CMapiImp::GetDefaultInbox(nsIMs
   nsresult rv;
   nsCOMPtr <nsIMsgAccountManager> accountManager =
     do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv,rv);
 
   nsCOMPtr <nsIMsgAccount> account;
   rv = accountManager->GetDefaultAccount(getter_AddRefs(account));
   NS_ENSURE_SUCCESS(rv,rv);
+  if (!account)
+    return NS_ERROR_FAILURE;
 
   // get incoming server
   nsCOMPtr <nsIMsgIncomingServer> server;
   rv = account->GetIncomingServer(getter_AddRefs(server));
   NS_ENSURE_SUCCESS(rv,rv);
 
   nsCString type;
   rv = server->GetType(type);