This patch adds two buttons to the preferences dialog. One on the "Basic" tab 
for loading Enigmail settings from a file and another on the "Advanced" tab for 
saving the current settings into a file.

The settings are (de)serialized as a single JSON object. When saving the 
"agentPath", "configuredVersion" and "advancedUser" options are skipped.

Closes issue #469.

Regards,
Kai
---
 ui/content/pref-enigmail.js         | 82 +++++++++++++++++++++++++++++++++++++
 ui/content/pref-enigmail.xul        | 17 +++++++-
 ui/locale/en-US/enigmail.dtd        |  6 +++
 ui/locale/en-US/enigmail.properties |  4 ++
 4 files changed, 108 insertions(+), 1 deletion(-)

diff --git a/ui/content/pref-enigmail.js b/ui/content/pref-enigmail.js
index ab3e87c..03eb502 100644
--- a/ui/content/pref-enigmail.js
+++ b/ui/content/pref-enigmail.js
@@ -293,6 +293,88 @@ function resetPrefs() {
   }
 }
 
+// Serializes various Enigmail settings into a separate file.
+function backupPrefs() {
+  EnigmailLog.DEBUG("pref-enigmail.js: backupPrefs\n");
+
+  var maybe_file = EnigFilePicker(EnigGetString("pickBackupFile"),"", true, 
"json","enigmail.json",null);
+  if (maybe_file !== null) {
+    var retObj = {value:0};
+    var branch = EnigmailPrefs.getPrefBranch();
+    var allPrefs = branch.getChildList("",retObj);
+    var prefObj = {};
+    var nsIPB = Components.interfaces.nsIPrefBranch;
+
+    for (var p in allPrefs) {
+      var name = allPrefs[p];
+
+      /*
+       * agentPath is system-depend, configuredVersion build-depend and
+       * advancedUser must be set in order to save the profile.
+       */
+      if (name == "agentPath" || name == "configuredVersion" || name == 
"advancedUser" ) {
+        continue;
+      }
+
+      switch (branch.getPrefType(name)) {
+        case nsIPB.PREF_STRING:
+          prefObj[name] = branch.getCharPref(name); break;
+        case nsIPB.PREF_INT:
+          prefObj[name] = branch.getIntPref(name); break;
+        case nsIPB.PREF_BOOL:
+          prefObj[name] = branch.getBoolPref(name); break;
+        default:
+          EnigmailLog.ERROR("Pref '" + name + "' has unknown type\n");
+      }
+    }
+
+    // serialize everything to UTF-8 encoded JSON.
+    var strm = Components.classes["@mozilla.org/network/file-output-stream;1"]
+                         
.createInstance(Components.interfaces.nsIFileOutputStream);
+    var nativeJSON = Components.classes["@mozilla.org/dom/json;1"]
+                               .createInstance(Components.interfaces.nsIJSON);
+
+    try {
+      strm.init(maybe_file,-1,-1,0);
+      nativeJSON.encodeToStream(strm,"UTF-8",false,prefObj);
+      strm.close();
+
+    } catch (ex) {
+      EnigError(EnigGetString("cantWriteBackupFile"));
+    }
+  }
+}
+
+// Loads settings saved with backupPrefs() into Enigmail.
+function restorePrefs() {
+  EnigmailLog.DEBUG("pref-enigmail.js: restorePrefs\n");
+
+  var maybe_file = EnigFilePicker(EnigGetString("loadBackupFile"),"", false, 
"json","enigmail.json",null);
+  if (maybe_file !== null) {
+    // Profile must be a single UTF-8 encoded JSON object.
+    var strm = Components.classes["@mozilla.org/network/file-input-stream;1"]
+                         
.createInstance(Components.interfaces.nsIFileInputStream);
+    var nativeJSON = Components.classes["@mozilla.org/dom/json;1"]
+                               .createInstance(Components.interfaces.nsIJSON);
+
+    try {
+      strm.init(maybe_file,-1,-1,0);
+      var prefObj = nativeJSON.decodeFromStream(strm,"UTF-8",false);
+      strm.close();
+
+      var nsIPB = Components.interfaces.nsIPrefBranch;
+      var branch = EnigmailPrefs.getPrefBranch();
+
+      // Set all options recorded in the JSON file.
+      for (var name in prefObj) {
+        EnigSetPref(name,prefObj[name]);
+      }
+    } catch (ex) {
+      EnigError(EnigGetString("cantReadBackupFile"));
+    }
+  }
+}
+
 function disableManually (disable)
 {
   var elems = [
diff --git a/ui/content/pref-enigmail.xul b/ui/content/pref-enigmail.xul
index 641da07..90d5f24 100755
--- a/ui/content/pref-enigmail.xul
+++ b/ui/content/pref-enigmail.xul
@@ -74,6 +74,12 @@
     <tooltip id="resetPrefs.tooltip">
       <description>&enigmail.resetPrefs.tooltip;</description>
     </tooltip>
+    <tooltip id="backupPrefs.tooltip">
+      <description>&enigmail.backupPrefs.tooltip;</description>
+    </tooltip>
+    <tooltip id="restorePrefs.tooltip">
+      <description>&enigmail.restorePrefs.tooltip;</description>
+    </tooltip>
     <tooltip id="wrapHtmlBeforeSend.tooltip">
       <description>&enigmail.wrapHtmlBeforeSend.tooltip;</description>
     </tooltip>
@@ -241,7 +247,12 @@
 
           <vbox autostretch="never" align="end">
             <hbox>
-              <button id="resetPrefs"
+              <button id="restorePrefs"
+                      label="&enigmail.restorePrefsButton.label;"
+                      tooltip="restorePrefs.tooltip"
+                      oncommand="restorePrefs();"/>
+
+             <button id="resetPrefs"
                       label="&enigmail.resetPrefsButton.label;"
                       tooltip="resetPrefs.tooltip"
                       oncommand="resetPrefs();"/>
@@ -443,6 +454,10 @@
                     label="&enigmail.resetRememberedValues.label;"
                     tooltip="resetRememberedValues.tooltip"
                     oncommand="resetRememberedValues();"/>
+            <button id="backupPrefs"
+                    label="&enigmail.backupPrefsButton.label;"
+                    tooltip="backupPrefs.tooltip"
+                    oncommand="backupPrefs();"/>
           </hbox>
       </vbox>
 
diff --git a/ui/locale/en-US/enigmail.dtd b/ui/locale/en-US/enigmail.dtd
index 267c543..9e2ab2b 100644
--- a/ui/locale/en-US/enigmail.dtd
+++ b/ui/locale/en-US/enigmail.dtd
@@ -51,6 +51,12 @@
 <!ENTITY enigmail.resetPrefsButton.label "Reset">
 <!ENTITY enigmail.resetPrefs.tooltip     "Set all Enigmail preferences back to 
their default value.">
 
+<!ENTITY enigmail.backupPrefsButton.label "Save Profile">
+<!ENTITY enigmail.backupPrefs.tooltip     "Save all Enigmail preferences 
except which certificate to use by default and GnuPG's location into a file.">
+
+<!ENTITY enigmail.restorePrefsButton.label "Load Profile">
+<!ENTITY enigmail.restorePrefs.tooltip     "Loads Enigmail preferences except 
which certificate to use by default and GnuPG's location from a file.">
+
 <!ENTITY enigmail.basic.label            "Basic">
 <!ENTITY enigmail.sending.label          "Sending">
 <!ENTITY enigmail.keySel.label           "Key Selection">
diff --git a/ui/locale/en-US/enigmail.properties 
b/ui/locale/en-US/enigmail.properties
index 003b643..8cbab6b 100644
--- a/ui/locale/en-US/enigmail.properties
+++ b/ui/locale/en-US/enigmail.properties
@@ -284,6 +284,10 @@ prefs.gpgNotFound=Could not find GnuPG
 prefs.warnAskNever=Warning: activating this option will result in unencrypted 
emails without any further information if there is no key for one of the 
recipients -- Enigmail will not inform you if this happens!
 prefs.warnIdleTimeForUnknownAgent=Cannot connect to gpg-agent. Maybe your 
system uses a specialized tool for passphrase handling (e.g. gnome-keyring, 
seahorse-agent, KDE wallet manager, ...). Unfortunately Enigmail cannot control 
the passphrase timeout for the tool you are using. Therefore the respective 
timeout settings in Enigmail are disregarded.
 prefEnigmail.oneKeyserverOnly=Error - you can only specify one keyserver for 
automatic downloading of missing OpenPGP keys.
+cantWriteBackupFile=Can't write profile to disk.
+cantReadBackupFile=Can't read profile from disk.
+pickBackupFile=Save current Enigmail Profile.
+loadBackupFile=Load an Enigmail Profile.
 
 # Strings used in components/enigmail.js
 # (said file also re-uses some strings from above)
-- 
2.3.6

_______________________________________________
enigmail-users mailing list
[email protected]
To unsubscribe or make changes to your subscription click here:
https://admin.hostpoint.ch/mailman/listinfo/enigmail-users_enigmail.net

Reply via email to