Bug 1273477 - Allow choosing a directory for Becky AB import. ui-r=Paenglab, r=rkent
authoraceman <acelists@atlas.sk>
Tue, 14 Jun 2016 07:29:03 +0200
changeset 19464 4484cd5998c91cfab43a6b68ee3efdc303333e16
parent 19463 17d2260dacf286a7099eb06eb1e025a879dca6bc
child 19465 7cb60a63a47e7c77fce8cc07d2d142fb3dd06f21
push id11984
push useracelists@atlas.sk
push dateTue, 14 Jun 2016 05:29:25 +0000
treeherdercomm-central@4484cd5998c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersPaenglab, rkent
bugs1273477
Bug 1273477 - Allow choosing a directory for Becky AB import. ui-r=Paenglab, r=rkent
mailnews/import/becky/src/nsBeckyAddressBooks.cpp
mailnews/import/public/nsIImportAddressBooks.idl
mailnews/import/test/unit/test_becky_addressbook.js
--- a/mailnews/import/becky/src/nsBeckyAddressBooks.cpp
+++ b/mailnews/import/becky/src/nsBeckyAddressBooks.cpp
@@ -44,17 +44,17 @@ nsBeckyAddressBooks::nsBeckyAddressBooks
 nsBeckyAddressBooks::~nsBeckyAddressBooks()
 {
 }
 
 NS_IMETHODIMP
 nsBeckyAddressBooks::GetSupportsMultiple(bool *_retval)
 {
   NS_ENSURE_ARG_POINTER(_retval);
-  *_retval = false;
+  *_retval = true;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsBeckyAddressBooks::GetAutoFind(char16_t **aDescription,
                                  bool *_retval)
 {
   NS_ENSURE_ARG_POINTER(aDescription);
@@ -65,36 +65,44 @@ nsBeckyAddressBooks::GetAutoFind(char16_
   *_retval = false;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsBeckyAddressBooks::GetNeedsFieldMap(nsIFile *aLocation, bool *_retval)
 {
+  NS_ENSURE_ARG_POINTER(_retval);
+
   *_retval = false;
   return NS_OK;
 }
 
 nsresult
 nsBeckyAddressBooks::FindAddressBookDirectory(nsIFile **aAddressBookDirectory)
 {
   nsCOMPtr<nsIFile> userDirectory;
   nsresult rv = nsBeckyUtils::FindUserDirectory(getter_AddRefs(userDirectory));
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = userDirectory->Append(NS_LITERAL_STRING("AddrBook"));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  bool exists;
+  bool exists = false;
   rv = userDirectory->Exists(&exists);
   NS_ENSURE_SUCCESS(rv, rv);
   if (!exists)
     return NS_ERROR_FILE_NOT_FOUND;
 
+  bool isDirectory = false;
+  rv = userDirectory->IsDirectory(&isDirectory);
+  NS_ENSURE_SUCCESS(rv, rv);
+  if (!isDirectory)
+    return NS_ERROR_FILE_NOT_FOUND;
+
   userDirectory.forget(aAddressBookDirectory);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsBeckyAddressBooks::GetDefaultLocation(nsIFile **aLocation,
                                         bool *aFound,
                                         bool *aUserVerify)
@@ -123,30 +131,36 @@ nsBeckyAddressBooks::CreateAddressBookDe
   NS_ENSURE_SUCCESS(rv, rv);
 
   return importService->CreateNewABDescriptor(aDescriptor);
 }
 
 bool
 nsBeckyAddressBooks::IsAddressBookFile(nsIFile *aFile)
 {
+  if (!aFile)
+    return false;
+
   nsresult rv;
-  bool isDirectory = false;
-  rv = aFile->IsDirectory(&isDirectory);
-  if (NS_SUCCEEDED(rv) && isDirectory)
+  bool isFile = false;
+  rv = aFile->IsFile(&isFile);
+  if (NS_FAILED(rv) && !isFile)
     return false;
 
   nsAutoString name;
   rv = aFile->GetLeafName(name);
   return StringEndsWith(name, NS_LITERAL_STRING(".bab"));
 }
 
 bool
 nsBeckyAddressBooks::HasAddressBookFile(nsIFile *aDirectory)
 {
+  if (!aDirectory)
+    return false;
+
   nsresult rv;
   bool isDirectory = false;
   rv = aDirectory->IsDirectory(&isDirectory);
   if (NS_FAILED(rv) || !isDirectory)
     return false;
 
   nsCOMPtr<nsISimpleEnumerator> entries;
   rv = aDirectory->GetDirectoryEntries(getter_AddRefs(entries));
@@ -165,16 +179,19 @@ nsBeckyAddressBooks::HasAddressBookFile(
   }
 
   return false;
 }
 
 uint32_t
 nsBeckyAddressBooks::CountAddressBookSize(nsIFile *aDirectory)
 {
+  if (!aDirectory)
+    return 0;
+
   nsresult rv;
   bool isDirectory = false;
   rv = aDirectory->IsDirectory(&isDirectory);
   if (NS_FAILED(rv) || !isDirectory)
     return 0;
 
   nsCOMPtr<nsISimpleEnumerator> entries;
   rv = aDirectory->GetDirectoryEntries(getter_AddRefs(entries));
@@ -200,16 +217,18 @@ nsBeckyAddressBooks::CountAddressBookSiz
 
   return total;
 }
 
 nsresult
 nsBeckyAddressBooks::AppendAddressBookDescriptor(nsIFile *aEntry,
                                                  nsIMutableArray *aCollected)
 {
+  NS_ENSURE_ARG_POINTER(aCollected);
+
   if (!HasAddressBookFile(aEntry))
     return NS_OK;
 
   nsresult rv;
   nsCOMPtr<nsIImportABDescriptor> descriptor;
   rv = CreateAddressBookDescriptor(getter_AddRefs(descriptor));
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/mailnews/import/public/nsIImportAddressBooks.idl
+++ b/mailnews/import/public/nsIImportAddressBooks.idl
@@ -1,25 +1,24 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* 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/. */
 
 /*
-
   Interface for importing address books using the standard UI.  Address
   book import occurs in several forms (yuck!).
   The destination can be 1..n new address books corresponding to the source
   format.  For instance a text file would import into a new address book
   with the same name as the text file.
   The destination can be 1 pre-defined address book, all entries will be
   added to the supplied address book - this allows the address book UI so provide
   an import command specific for an individual address book.
 
-  The source can import 1 or mulitple address books.
+  The source can import 1 or multiple address books.
   The address books can be auto-discoverable or user specified.
   The address books can require field mapping or not.
 
   All of this is rather complicated but it should work out OK.
   1) The first UI
   panel will allow selection of the address book and will indicate to the user
   if the address book will be imported into an existing address book or new address
   books.  (This could be 2 separate xul UI's?).
--- a/mailnews/import/test/unit/test_becky_addressbook.js
+++ b/mailnews/import/test/unit/test_becky_addressbook.js
@@ -1,13 +1,10 @@
 function run_test()
 {
-  if (!("nsIWindowsRegKey" in Ci))
-    return;
-
   // Due to the import code using nsIAbManager off the main thread, we need
   // to ensure that it is initialized before we start the main test.
   let abMgr = Cc["@mozilla.org/abmanager;1"].getService(Ci.nsIAbManager);
 
   let file = do_get_file("resources/becky/addressbooks");
   let helper = new AbImportHelper(file, "Becky!", "addressbooks",
                                   "becky_addressbook");
   let vcfSupportedAttributes =