Bug 1633620 - Fix printing of address books. r=mkmelin
authorGeoff Lankow <geoff@darktrojan.net>
Tue, 28 Apr 2020 15:32:57 +1200
changeset 38071 a34c59e873c92c1d65c9dd3715d260698083d887
parent 38070 9eda2be91b4ed91bf64cb4571e1d70c360146225
child 38072 8ca165d3e5ee9f9073361d1d9417edae2090d9d1
push id2595
push userclokep@gmail.com
push dateMon, 04 May 2020 19:02:04 +0000
treeherdercomm-beta@f53913797371 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1633620
Bug 1633620 - Fix printing of address books. r=mkmelin
mailnews/addrbook/src/nsAbView.cpp
mailnews/addrbook/src/nsAddbookProtocolHandler.cpp
--- a/mailnews/addrbook/src/nsAbView.cpp
+++ b/mailnews/addrbook/src/nsAbView.cpp
@@ -174,32 +174,26 @@ NS_IMETHODIMP nsAbView::SetView(nsIAbDir
     rv = RemoveCardAt(i);
     NS_ASSERTION(NS_SUCCEEDED(rv), "remove card failed");
   }
 
   // We replace all cards so any sorting is no longer valid.
   mSortColumn.AssignLiteral("");
   mSortDirection.AssignLiteral("");
 
-  nsCString uri;
-  aAddressBook->GetURI(uri);
-  int32_t searchBegin = uri.FindChar('?');
-  nsCString searchQuery(Substring(uri, searchBegin));
-  // This is a special case, a workaround basically, to just have all ABs.
-  if (searchQuery.EqualsLiteral("?")) {
-    searchQuery.AssignLiteral("");
-  }
+  if (aAddressBook) {
+    nsCString uri;
+    aAddressBook->GetURI(uri);
 
-  if (Substring(uri, 0, searchBegin).EqualsLiteral(kAllDirectoryRoot)) {
+    mIsAllDirectoryRootView = false;
+    mDirectory = aAddressBook;
+    rv = EnumerateCards();
+    NS_ENSURE_SUCCESS(rv, rv);
+  } else {
     mIsAllDirectoryRootView = true;
-    // We have special request case to search all addressbooks, so we need
-    // to iterate over all addressbooks.
-    // Since the request is for all addressbooks, the URI must have been
-    // passed with an extra '?'. We still check it for sanity and trim it here.
-    if (searchQuery.Find("??") == 0) searchQuery = Substring(searchQuery, 1);
 
     nsCOMPtr<nsIAbManager> abManager(
         do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
     NS_ENSURE_SUCCESS(rv, rv);
     nsCOMPtr<nsISimpleEnumerator> enumerator;
     rv = abManager->GetDirectories(getter_AddRefs(enumerator));
     NS_ENSURE_SUCCESS(rv, rv);
 
@@ -209,30 +203,20 @@ NS_IMETHODIMP nsAbView::SetView(nsIAbDir
     while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMore)) && hasMore) {
       rv = enumerator->GetNext(getter_AddRefs(support));
       NS_ENSURE_SUCCESS(rv, rv);
       directory = do_QueryInterface(support, &rv);
 
       // If, for some reason, we are unable to get a directory, we continue.
       if (NS_FAILED(rv)) continue;
 
-      // Get appropriate directory with search query.
-      nsCString uri;
-      directory->GetURI(uri);
-      rv =
-          abManager->GetDirectory(uri + searchQuery, getter_AddRefs(directory));
       mDirectory = directory;
       rv = EnumerateCards();
       NS_ENSURE_SUCCESS(rv, rv);
     }
-  } else {
-    mIsAllDirectoryRootView = false;
-    mDirectory = aAddressBook;
-    rv = EnumerateCards();
-    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   NS_NAMED_LITERAL_STRING(generatedNameColumnId, GENERATED_NAME_COLUMN_ID);
 
   // See if the persisted sortColumn is valid.
   // It may not be, if you migrated from older versions, or switched between
   // a mozilla build and a commercial build, which have different columns.
   nsAutoString actualSortColumn;
--- a/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp
+++ b/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp
@@ -211,32 +211,30 @@ nsresult nsAddbookProtocolHandler::Gener
 
   uri.Insert('/', pos);
   uri.Insert(':', pos);
 
   nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIAbDirectory> directory;
-  rv = abManager->GetDirectory(uri, getter_AddRefs(directory));
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (!uri.Equals(kAllDirectoryRoot "?")) {
+    rv = abManager->GetDirectory(uri, getter_AddRefs(directory));
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
 
   rv = BuildDirectoryXML(directory, aOutput);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 nsresult nsAddbookProtocolHandler::BuildDirectoryXML(nsIAbDirectory *aDirectory,
                                                      nsString &aOutput) {
-  NS_ENSURE_ARG_POINTER(aDirectory);
-
   nsresult rv;
-  nsCOMPtr<nsISimpleEnumerator> cardsEnumerator;
-  nsCOMPtr<nsIAbCard> card;
 
   aOutput.AppendLiteral(
       "<?xml version=\"1.0\"?>\n"
       "<?xml-stylesheet type=\"text/css\" "
       "href=\"chrome://messagebody/content/addressbook/print.css\"?>\n"
       "<directory>\n");
 
   // Get Address Book string and set it as title of XML document
@@ -270,16 +268,22 @@ nsresult nsAddbookProtocolHandler::Build
   int32_t numRows;
   nsCOMPtr<nsITreeView> treeView = do_QueryInterface(view, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
   treeView->GetRowCount(&numRows);
 
   for (int32_t row = 0; row < numRows; row++) {
     nsCOMPtr<nsIAbCard> card;
     view->GetCardFromRow(row, getter_AddRefs(card));
+
+    bool isMailList;
+    if (NS_FAILED(card->GetIsMailList(&isMailList)) || isMailList) {
+      continue;
+    }
+
     nsCString xmlSubstr;
 
     rv = card->TranslateTo(NS_LITERAL_CSTRING("xml"), xmlSubstr);
     NS_ENSURE_SUCCESS(rv, rv);
 
     aOutput.AppendLiteral("<separator/>");
     aOutput.Append(NS_ConvertUTF8toUTF16(xmlSubstr));
     aOutput.AppendLiteral("<separator/>");