Bug 1356881 - find mailinglists (groups) also in OS X and Outlook addressbooks. r=Paenglab, r=jorgk a=jorgk
authoraceman <acelists@atlas.sk>
Wed, 03 May 2017 22:40:00 +0200
changeset 27840 f46aa8903207e4f78a9ab3d6405b289d77c5f404
parent 27839 77f134f6ddb895b67f19706010f8def09418c4ab
child 27841 88a73f0bbf8f659b984270a0fcbb641b510b950f
push id1938
push usermozilla@jorgk.com
push dateThu, 04 May 2017 10:31:57 +0000
treeherdercomm-beta@a3dc003cd9e3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersPaenglab, jorgk, jorgk
bugs1356881
Bug 1356881 - find mailinglists (groups) also in OS X and Outlook addressbooks. r=Paenglab, r=jorgk a=jorgk
mailnews/addrbook/public/nsIAbDirectory.idl
mailnews/addrbook/src/nsAbDirProperty.cpp
mailnews/addrbook/src/nsAbMDBDirectory.cpp
mailnews/addrbook/src/nsAbMDBDirectory.h
mailnews/addrbook/src/nsAbManager.cpp
--- a/mailnews/addrbook/public/nsIAbDirectory.idl
+++ b/mailnews/addrbook/public/nsIAbDirectory.idl
@@ -115,16 +115,19 @@ interface nsIAbDirectory : nsIAbCollecti
   // of obtaining cards the method will throw an
   // NS_ERROR_NOT_AVAILABLE exception if the card
   // cannot be found.
   boolean hasCard(in nsIAbCard cards);
 
   // Check if directory contains directory
   boolean hasDirectory(in nsIAbDirectory dir);
 
+  // Check if directory contains a mailinglist by name
+  boolean hasMailListWithName(in wstring aName);
+
   /**
    * Adds a card to the database.
    *
    * This card does not need to be of the same type as the database, e.g., one
    * can add an nsIAbLDAPCard to an nsIAbMDBDirectory.
    *
    * @return "Real" card (eg nsIAbLDAPCard) that can be used for some
    *         extra functions.
--- a/mailnews/addrbook/src/nsAbDirProperty.cpp
+++ b/mailnews/addrbook/src/nsAbDirProperty.cpp
@@ -1,23 +1,24 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "nsAbDirProperty.h"	 
+#include "nsAbDirProperty.h"
 #include "nsAbBaseCID.h"
 #include "nsIAbCard.h"
 #include "nsDirPrefs.h"
 #include "nsIPrefService.h"
 #include "nsIPrefLocalizedString.h"
 #include "nsServiceManagerUtils.h"
 #include "nsComponentManagerUtils.h"
 #include "prmem.h"
 #include "nsIAbManager.h"
+#include "nsArrayUtils.h"
 
 // From nsDirPrefs
 #define kDefaultPosition 1
 
 nsAbDirProperty::nsAbDirProperty(void)
   : m_LastModifiedDate(0),
     mIsValidURI(false),
     mIsQueryURI(false)
@@ -291,16 +292,57 @@ NS_IMETHODIMP
 nsAbDirProperty::HasCard(nsIAbCard *cards, bool *hasCard)
 { return NS_ERROR_NOT_IMPLEMENTED; }
 
 NS_IMETHODIMP
 nsAbDirProperty::HasDirectory(nsIAbDirectory *dir, bool *hasDir)
 { return NS_ERROR_NOT_IMPLEMENTED; }
 
 NS_IMETHODIMP
+nsAbDirProperty::HasMailListWithName(const char16_t *aName, bool *aHasList)
+{
+  NS_ENSURE_ARG_POINTER(aName);
+  NS_ENSURE_ARG_POINTER(aHasList);
+
+  *aHasList = false;
+
+  bool supportsLists = false;
+  nsresult rv = GetSupportsMailingLists(&supportsLists);
+  if (NS_FAILED(rv) || !supportsLists)
+    return NS_OK;
+
+  if (m_IsMailList)
+    return NS_OK;
+
+  nsCOMPtr<nsIMutableArray> addressLists;
+  rv = GetAddressLists(getter_AddRefs(addressLists));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  uint32_t listCount = 0;
+  rv = addressLists->GetLength(&listCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  for (uint32_t i = 0; i < listCount; i++)
+  {
+    nsCOMPtr<nsIAbDirectory> listDir(do_QueryElementAt(addressLists, i, &rv));
+    if (NS_SUCCEEDED(rv) && listDir)
+    {
+      nsAutoString listName;
+      rv = listDir->GetDirName(listName);
+      if (NS_SUCCEEDED(rv) && listName.Equals(aName))
+      {
+        *aHasList = true;
+        return NS_OK;
+      }
+    }
+  }
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsAbDirProperty::CreateNewDirectory(const nsAString &aDirName,
                                     const nsACString &aURI,
                                     uint32_t aType,
                                     const nsACString &aPrefName,
                                     nsACString &aResult)
 { return NS_ERROR_NOT_IMPLEMENTED; }
 
 NS_IMETHODIMP
--- a/mailnews/addrbook/src/nsAbMDBDirectory.cpp
+++ b/mailnews/addrbook/src/nsAbMDBDirectory.cpp
@@ -582,16 +582,32 @@ NS_IMETHODIMP nsAbMDBDirectory::HasDirec
 
     if (NS_SUCCEEDED(rv))
       rv = database->ContainsMailList(dir, hasDir);
   }
 
   return rv;
 }
 
+NS_IMETHODIMP nsAbMDBDirectory::HasMailListWithName(const char16_t *aName, bool *aHasList)
+{
+  NS_ENSURE_ARG_POINTER(aHasList);
+
+  nsCOMPtr<nsIAddrDatabase> database;
+  nsresult rv = GetDatabase(getter_AddRefs(database));
+  if (NS_SUCCEEDED(rv))
+  {
+    rv = database->FindMailListbyUnicodeName(aName, aHasList);
+    if (NS_SUCCEEDED(rv) && *aHasList)
+      return NS_OK;
+  }
+
+  return rv;
+}
+
 NS_IMETHODIMP nsAbMDBDirectory::AddMailList(nsIAbDirectory *list, nsIAbDirectory **addedList)
 {
   NS_ENSURE_ARG_POINTER(addedList);
 
   if (mIsQueryURI)
     return NS_ERROR_NOT_IMPLEMENTED;
 
   nsresult rv = NS_OK;
--- a/mailnews/addrbook/src/nsAbMDBDirectory.h
+++ b/mailnews/addrbook/src/nsAbMDBDirectory.h
@@ -55,16 +55,17 @@ public:
   // nsIAbDirectory methods:
   NS_IMETHOD GetChildNodes(nsISimpleEnumerator* *result) override;
   NS_IMETHOD GetChildCards(nsISimpleEnumerator* *result) override;
   NS_IMETHOD GetIsQuery(bool *aResult) override;
   NS_IMETHOD DeleteDirectory(nsIAbDirectory *directory) override;
   NS_IMETHOD DeleteCards(nsIArray *cards) override;
   NS_IMETHOD HasCard(nsIAbCard *cards, bool *hasCard) override;
   NS_IMETHOD HasDirectory(nsIAbDirectory *dir, bool *hasDir) override;
+  NS_IMETHOD HasMailListWithName(const char16_t *aName, bool *aHasList) override;
   NS_IMETHOD AddMailList(nsIAbDirectory *list, nsIAbDirectory **addedList) override;
   NS_IMETHOD AddCard(nsIAbCard *card, nsIAbCard **addedCard) override;
   NS_IMETHOD ModifyCard(nsIAbCard *aModifiedCard) override;
   NS_IMETHOD DropCard(nsIAbCard *card, bool needToCopyCard) override;
   NS_IMETHOD EditMailListToDatabase(nsIAbCard *listCard) override;
   NS_IMETHOD CardForEmailAddress(const nsACString &aEmailAddress,
                                  nsIAbCard ** aAbCard) override;
   NS_IMETHOD GetCardFromProperty(const char *aProperty,
--- a/mailnews/addrbook/src/nsAbManager.cpp
+++ b/mailnews/addrbook/src/nsAbManager.cpp
@@ -461,55 +461,49 @@ NS_IMETHODIMP nsAbManager::GetUserProfil
 
   rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(profileDir));
   NS_ENSURE_SUCCESS(rv, rv);
 
   profileDir.forget(userDir);
   return NS_OK;
 }
 
-NS_IMETHODIMP nsAbManager::MailListNameExists(const char16_t *name, bool *exist)
+NS_IMETHODIMP nsAbManager::MailListNameExists(const char16_t *aName, bool *aExists)
 {
   nsresult rv;
-  NS_ENSURE_ARG_POINTER(exist);
+  NS_ENSURE_ARG_POINTER(aExists);
 
-  *exist = false;
+  *aExists = false;
 
   // now get the top-level book
   nsCOMPtr<nsIAbDirectory> topDirectory;
   rv = GetRootDirectory(getter_AddRefs(topDirectory));
 
   // now go through the address books
   nsCOMPtr<nsISimpleEnumerator> enumerator;
   rv = topDirectory->GetChildNodes(getter_AddRefs(enumerator));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsISupports> item;
-  nsCOMPtr<nsIAbMDBDirectory> directory;
-
   bool hasMore;
-  // XXX Make this not MDB specific.
   while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMore)) && hasMore)
   {
+    nsCOMPtr<nsISupports> item;
     rv = enumerator->GetNext(getter_AddRefs(item));
     NS_ENSURE_SUCCESS(rv, rv);
 
-    directory = do_QueryInterface(item, &rv);
-    if (NS_SUCCEEDED(rv))
-    {
-        nsCOMPtr<nsIAddrDatabase> database;
-      rv = directory->GetDatabase(getter_AddRefs(database));
-        if (NS_SUCCEEDED(rv))
-        {
-        rv = database->FindMailListbyUnicodeName(name, exist);
-        if (NS_SUCCEEDED(rv) && *exist)
-            return NS_OK;
-        }
-      }
-    }
+    nsCOMPtr<nsIAbDirectory> directory = do_QueryInterface(item, &rv);
+    if (NS_FAILED(rv))
+      continue;
+
+    rv = directory->HasMailListWithName(aName, aExists);
+    if (NS_SUCCEEDED(rv) && *aExists)
+      return NS_OK;
+  }
+
+  *aExists = false;
   return NS_OK;
 }
 
 #define CSV_DELIM ","
 #define CSV_DELIM_LEN 1
 #define TAB_DELIM "\t"
 #define TAB_DELIM_LEN 1