Bug 437750 New message still return preferred format window when we use "additional email" address. r=Standard8,sr=bienvenu
authorBoying Lu <brian.lu@sun.com>
Thu, 18 Sep 2008 08:55:38 +0100
changeset 368 f8ca45bb7b11f4632edd40a4724e52fe3c0c2b19
parent 367 4df6a0bfc947a3eb1d7f45b6bd99078737f3ee23
child 369 619b7be9d9584b414ad05a67b9ead35bb0822483
push idunknown
push userunknown
push dateunknown
reviewersStandard8, bienvenu
bugs437750
Bug 437750 New message still return preferred format window when we use "additional email" address. r=Standard8,sr=bienvenu
mailnews/compose/src/nsMsgCompose.cpp
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -4520,26 +4520,16 @@ nsMsgCompose::CheckAndPopulateRecipients
       if (abDirectory && (addrbookDirArray[k] == abDirectory))
       {
         stillNeedToSearch = PR_FALSE;
         break;
       }
 
       abDirectory = addrbookDirArray[k];
 
-      // These will fail for non-MDB address books, therefore, just ignore
-      // errors, we'll check to see if we have got a valid database before using
-      // it.
-      nsCOMPtr<nsIAddrDatabase> abDataBase;
-      {
-        nsCOMPtr<nsIAbMDBDirectory> mdbDirectory(do_QueryInterface(abDirectory));
-        if (mdbDirectory)
-          mdbDirectory->GetDatabase(getter_AddRefs(abDataBase));
-      }
-
       PRBool supportsMailingLists;
       rv = abDirectory->GetSupportsMailingLists(&supportsMailingLists);
       if (NS_FAILED(rv) || !supportsMailingLists)
         continue;
 
       // Ensure the existing list is empty before filling it
       mailListArray->Clear();
 
@@ -4639,52 +4629,47 @@ nsMsgCompose::CheckAndPopulateRecipients
                  --j;
               }
               else
                 recipient.mProcessed = PR_TRUE;
 
               continue;
             }
 
-            // If we haven't got a database, don't try to increase the
-            // popularity index.
-            if (!abDataBase)
+            if (!abDirectory)
             {
               stillNeedToSearch = PR_TRUE;
               continue;
             }
 
-            // Then if we have a card for this email address
-            // Please DO NOT change the 4th param of GetCardFromAttribute() call to
-            // PR_TRUE (ie, case insensitive) without reading bugs #128535 and #121478.
-            rv = abDataBase->GetCardFromAttribute(abDirectory, kPriEmailProperty,
-                                                  NS_ConvertUTF16toUTF8(recipient.mEmail),
-                                                  PR_FALSE /* case insensitive */,
+            // find a card that contains this e-mail address 
+            rv = abDirectory->CardForEmailAddress(NS_ConvertUTF16toUTF8(recipient.mEmail),
                                                   getter_AddRefs(existingCard));
+
             if (NS_SUCCEEDED(rv) && existingCard)
             {
               recipient.mPreferFormat = nsIAbPreferMailFormat::unknown;
               rv = existingCard->GetPropertyAsUint32(kPreferMailFormatProperty,
                                                      &recipient.mPreferFormat);
               if (NS_SUCCEEDED(rv))
                 recipient.mProcessed = PR_TRUE;
 
+              PRInt32 isWriteable;
+              rv = abDirectory->GetOperations(&isWriteable);
+              NS_ENSURE_SUCCESS(rv,rv);
+
               // bump the popularity index for this card since we are about to send e-mail to it
               PRUint32 popularityIndex = 0;
-              if (NS_SUCCEEDED(existingCard->GetPropertyAsUint32(
+              if ((isWriteable & nsIAbDirectory::opWrite) && NS_SUCCEEDED(existingCard->GetPropertyAsUint32(
                       kPopularityIndexProperty, &popularityIndex)))
               {
+
                 existingCard->SetPropertyAsUint32(kPopularityIndexProperty,
                                                   ++popularityIndex);
-                // Since we are not notifying anyway, send null
-                abDataBase->EditCard(existingCard, PR_FALSE, nsnull);
-
-                // commit the database changes if we updated the popularity
-                // count.
-                abDataBase->Close(PR_TRUE);
+                abDirectory->ModifyCard(existingCard);
               }
             }
             else
               stillNeedToSearch = PR_TRUE;
           }
         }
       }
     }