Bug 1182460 - allow exporting all addressbooks - version for TB45. r=mkmelin, r=rkent, a=rkent
authoraceman <acelists@atlas.sk>
Wed, 10 Feb 2016 11:28:00 +0100
changeset 26710 e69c46711b1a0af3f95007ff09a7aed790667e11
parent 26709 7d72264ce50702f410349ebeb5423b4b8c026781
child 26711 a98e0f07eada2d4493f1effd3c95df8928facaca
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin, rkent, rkent
bugs1182460
Bug 1182460 - allow exporting all addressbooks - version for TB45. r=mkmelin, r=rkent, a=rkent
mail/components/addrbook/content/addressbook.js
mail/components/addrbook/content/addressbook.xul
mailnews/addrbook/src/nsAbManager.cpp
--- a/mail/components/addrbook/content/addressbook.js
+++ b/mail/components/addrbook/content/addressbook.js
@@ -410,23 +410,57 @@ function AbPrintAddressBook()
   AbPrintAddressBookInternal(false, Components.interfaces.nsIMsgPrintEngine.MNAB_PRINT_ADDRBOOK);
 }
 
 function AbPrintPreviewAddressBook()
 {
   AbPrintAddressBookInternal(true, Components.interfaces.nsIMsgPrintEngine.MNAB_PRINTPREVIEW_ADDRBOOK);
 }
 
-function AbExport()
+/**
+ * Export the currently selected addressbook.
+ */
+function AbExportSelection() {
+  let selectedABURI = GetSelectedDirectory();
+  if (!selectedABURI)
+    return;
+
+ if (selectedABURI == (kAllDirectoryRoot + "?"))
+   return AbExportAll();
+
+ return AbExport(selectedABURI);
+}
+
+/**
+ * Export all found addressbooks, each in a separate file.
+ */
+function AbExportAll()
 {
+  let directories = MailServices.ab.directories;
+
+  while (directories.hasMoreElements()) {
+    let directory = directories.getNext();
+    // Do not export LDAP ABs.
+    if (!directory.URI.startsWith(kLdapUrlPrefix))
+      AbExport(directory.URI);
+  }
+}
+
+/**
+ * Export the specified addressbook to a file.
+ *
+ * @param aSelectedABURI  The URI if the addressbook to export.
+ */
+function AbExport(aSelectedABURI)
+{
+  if (!aSelectedABURI)
+    return;
+
   try {
-    let selectedABURI = GetSelectedDirectory();
-    if (!selectedABURI) return;
-
-    let directory = GetDirectoryFromURI(selectedABURI);
+    let directory = GetDirectoryFromURI(aSelectedABURI);
     MailServices.ab.exportAddressBook(window, directory);
   }
   catch (ex) {
     let message;
     switch (ex.result) {
       case Components.results.NS_ERROR_FILE_ACCESS_DENIED:
         message = gAddressBookBundle.getString("failedToExportMessageFileAccessDenied");
         break;
--- a/mail/components/addrbook/content/addressbook.xul
+++ b/mail/components/addrbook/content/addressbook.xul
@@ -547,17 +547,19 @@
         <!-- Moving the messengerCmd menu item item to the Window menu on the Mac -->
 #ifndef XP_MACOSX
             <menuitem id="tasksMenuMail" accesskey="&messengerCmd.accesskey;"
                       label="&messengerCmd.label;" key="key_mail"
                       oncommand="toMessengerWindow();"/>
             <menuseparator/>
 #endif
             <menuitem label="&importCmd.label;" accesskey="&importCmd.accesskey;" oncommand="toImport()"/>
-            <menuitem label="&exportCmd.label;" accesskey="&exportCmd.accesskey;" oncommand="AbExport()"/>
+            <menuitem label="&exportCmd.label;"
+                      accesskey="&exportCmd.accesskey;"
+                      oncommand="AbExportSelection();"/>
 
 #ifndef XP_UNIX
             <menuseparator id="prefSep"/>
             <menuitem id="menu_preferences"
                       label="&preferencesCmd2.label;"
                       accesskey="&preferencesCmd2.accesskey;"
                       command="cmd_preferences"/>
 #else
--- a/mailnews/addrbook/src/nsAbManager.cpp
+++ b/mailnews/addrbook/src/nsAbManager.cpp
@@ -540,20 +540,27 @@ NS_IMETHODIMP nsAbManager::ExportAddress
 
   nsCOMPtr<nsIStringBundleService> bundleService =
     mozilla::services::GetStringBundleService();
   NS_ENSURE_TRUE(bundleService, NS_ERROR_UNEXPECTED);
   nsCOMPtr<nsIStringBundle> bundle;
   rv = bundleService->CreateBundle("chrome://messenger/locale/addressbook/addressBook.properties", getter_AddRefs(bundle));
   NS_ENSURE_SUCCESS(rv, rv);
 
+  nsString dirName;
+  aDirectory->GetDirName(dirName);
+
   nsString title;
   rv = bundle->GetStringFromName(MOZ_UTF16("ExportAddressBookTitle"), getter_Copies(title));
   NS_ENSURE_SUCCESS(rv, rv);
 
+  // This is not properly localized but a proper version is already in trunk.
+  title.AppendLiteral(" - ");
+  title.Append(dirName);
+
   rv = filePicker->Init(aParentWin, title, nsIFilePicker::modeSave);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsString filterString;
 
   // CSV: System charset and UTF-8.
   rv = bundle->GetStringFromName(MOZ_UTF16("CSVFilesSysCharset"), getter_Copies(filterString));
   NS_ENSURE_SUCCESS(rv, rv);