Bug 437908 Search/Filters don't check correctly for address in Mac OS X Address Book. r/sr=bienvenu
authorMark Banner <bugzilla@standard8.plus.com>
Sun, 17 Aug 2008 21:59:02 +0100
changeset 124 5773e859a5a6cae2861d3c19c4f6d157ea53c658
parent 123 71183dfd149ec5196a902bfd80c6ecb131e605ef
child 125 4665f977d95b80be80d2dec85d162cfaa68d8a60
push idunknown
push userunknown
push dateunknown
bugs437908
Bug 437908 Search/Filters don't check correctly for address in Mac OS X Address Book. r/sr=bienvenu
mailnews/addrbook/src/nsAbOSXDirectory.h
mailnews/addrbook/src/nsAbOSXDirectory.mm
--- a/mailnews/addrbook/src/nsAbOSXDirectory.h
+++ b/mailnews/addrbook/src/nsAbOSXDirectory.h
@@ -94,16 +94,18 @@ public:
   
   // nsAbDirProperty methods
   NS_IMETHOD GetOperations(PRInt32 *aOperations);
   NS_IMETHOD GetChildCards(nsISimpleEnumerator **aCards);
   NS_IMETHOD GetChildNodes(nsISimpleEnumerator **aNodes);
   NS_IMETHOD HasCard(nsIAbCard *aCard, PRBool *aHasCard);
   NS_IMETHOD HasDirectory(nsIAbDirectory *aDirectory, PRBool *aHasDirectory);
   NS_IMETHOD GetURI(nsACString &aURI);
+  NS_IMETHOD CardForEmailAddress(const nsACString &aEmailAddress,
+                                 nsIAbCard **aResult);
 
   // nsIAbOSXDirectory
   nsresult AssertChildNodes();
   nsresult AssertDirectory(nsIAbManager *aManager,
                            nsIAbDirectory *aDirectory);
   nsresult AssertCard(nsIAbManager *aManager,
                       nsIAbCard *aCard);
   nsresult UnassertCard(nsIAbManager *aManager,
--- a/mailnews/addrbook/src/nsAbOSXDirectory.mm
+++ b/mailnews/addrbook/src/nsAbOSXDirectory.mm
@@ -836,16 +836,72 @@ nsAbOSXDirectory::GetChildCards(nsISimpl
   }
 
   // Not a search, so just return the appropriate list of items.
   return m_IsMailList ? NS_NewArrayEnumerator(aCards, m_AddressList) :
          NS_NewArrayEnumerator(aCards, mCardList);
 }
 
 NS_IMETHODIMP
+nsAbOSXDirectory::CardForEmailAddress(const nsACString &aEmailAddress,
+                                      nsIAbCard **aResult)
+{
+  NS_ENSURE_ARG_POINTER(aResult);
+
+  *aResult = nsnull;
+
+  if (aEmailAddress.IsEmpty())
+    return NS_OK;
+
+  nsIMutableArray *list = m_IsMailList ? m_AddressList : mCardList;
+
+  if (!list)
+    return NS_OK;
+
+  PRUint32 length;
+  nsresult rv = list->GetLength(&length);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr<nsIAbCard> card;
+
+  for (PRUint32 i = 0; i < length && !*aResult; ++i)
+  {
+    card = do_QueryElementAt(list, i, &rv);
+    if (NS_SUCCEEDED(rv))
+    {
+      nsCString email;
+      rv = card->GetPropertyAsAUTF8String(kPriEmailProperty, email);
+      if (NS_FAILED(rv))
+        continue;
+
+#ifdef MOZILLA_INTERNAL_API
+      if (email.Equals(aEmailAddress, nsCaseInsensitiveCStringComparator()))
+#else
+      if (email.Equals(aEmailAddress, CaseInsensitiveCompare))
+#endif
+        NS_IF_ADDREF(*aResult = card);
+      else
+      {
+        rv = card->GetPropertyAsAUTF8String(k2ndEmailProperty, email);
+        if (NS_FAILED(rv))
+          continue;
+
+#ifdef MOZILLA_INTERNAL_API
+        if (email.Equals(aEmailAddress, nsCaseInsensitiveCStringComparator()))
+#else
+          if (email.Equals(aEmailAddress, CaseInsensitiveCompare))
+#endif
+          NS_IF_ADDREF(*aResult = card);
+      }
+    }
+  }
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsAbOSXDirectory::HasCard(nsIAbCard *aCard, PRBool *aHasCard)
 {
   NS_ENSURE_ARG_POINTER(aCard);
   NS_ENSURE_ARG_POINTER(aHasCard);
 
   nsresult rv = NS_OK;
   PRUint32 index;
   if (m_IsMailList)