> On 07/14/2015 05:36 PM, Patrick Brunschwig wrote:
>> On 14.07.2015 14:09, Kai Michaelis wrote:
>>> This patch extends the save/restore profile function so that it
>>> saves the contents of pgpRules.xml too. When restoring a saved
>>> profile all existing per-recipient rules are _deleted_ and
>>> replaced with the ones in the saved profile.
>
>> Hi Kai
>
>> From what I can see, you put a lot of logic into pref-enigmail.js
>> that should go into rules.jsm (or that actually is already
>> there!).
>
>> We should avoid to duplicate code.
>
>> Why don't you simply write the rules file to disk, and and use
>> the existing EnigmailRules.loadRulesFile() to get them loaded?
>
On 16.07.15 12:06, Kai Michaelis wrote:
> you're right about the rulesToObject and objectToRules functions.
> I'll move them into rules.jsm.
>
> Writing the rules file to disk in backupPrefs will result in two
> files. One with the saved Enigmail preferences and the
> pgpRules.xml. As I understand ticket #469 the use case for the
> save/restore function is to help users to install a certain
> configuration instead of guiding them through the advanced tab.
> Forcing the user to send and afterwards load two files makes the
> whole process error-prone.
On 07/16/2015 06:36 PM, Patrick Brunschwig wrote:
> Could we agree on bottom posting on this list?
>
> I fully agree with what you say. But when you restore the settings, you
> could save the new rules-file over the old one and then load the rules
> from that file. You would anywayOR you simply change
> EnigmailRules.loadRulesFile() to allow loading from the backup rules file.
>
> -Patrick
We can.
This patch is an improved version of the previous save/restore functionality
for pgprules.xml. The rules file is now written directly instead of calling
addRule() repeatedly. To allow this loadRules() was split into two.
Code that converted the user prefs into an object was moved into prefs.jsm,
the code that remains in prefs-enigmail.js only handles (de)serialization and
file access.
The previous patch was reformatted using js-beautify.
Regards
Kai
---
package/prefs.jsm | 44 +++++++++++++++++++++++++++++++++++++
package/rules.jsm | 23 +++++++++++++-------
ui/content/pref-enigmail.js | 53 +++++++++++++++++----------------------------
3 files changed, 79 insertions(+), 41 deletions(-)
diff --git a/package/prefs.jsm b/package/prefs.jsm
index d2f92f1..58078e9 100644
--- a/package/prefs.jsm
+++ b/package/prefs.jsm
@@ -193,5 +193,49 @@ const EnigmailPrefs = {
p.service.savePrefFile(null);
}
catch (ex) {}
+ },
+
+ /**
+ * Compiles all Enigmail preferences into an object
+ */
+ getAllPrefs: function() {
+ EnigmailLog.DEBUG("prefs.js: getAllPrefs\n");
+
+ var retObj = {
+ value: 0
+ };
+ var branch = this.getPrefBranch();
+ var allPrefs = branch.getChildList("", retObj);
+ var prefObj = {};
+ var nsIPB = Components.interfaces.nsIPrefBranch;
+
+ for (var q in allPrefs) {
+ var name = allPrefs[q];
+
+ /*
+ * 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");
+ }
+ }
+
+ return prefObj;
}
};
+
diff --git a/package/rules.jsm b/package/rules.jsm
index 819f3fb..145419c 100644
--- a/package/rules.jsm
+++ b/package/rules.jsm
@@ -74,22 +74,27 @@ const EnigmailRules = {
},
loadRulesFile: function() {
- EnigmailLog.DEBUG("enigmail.js: loadRulesFile\n");
var flags = NS_RDONLY;
var rulesFile = this.getRulesFile();
if (rulesFile.exists()) {
var fileContents = EnigmailFiles.readFile(rulesFile);
- if (fileContents.length === 0 || fileContents.search(/^\s*$/) === 0) {
- return false;
- }
+ return this.loadRulesFromString(fileContents);
+ }
- var domParser =
Cc[NS_DOMPARSER_CONTRACTID].createInstance(Ci.nsIDOMParser);
- rulesListHolder.rulesList = domParser.parseFromString(fileContents,
"text/xml");
+ return false;
+ },
- return true;
+ loadRulesFromString: function(contents) {
+ EnigmailLog.DEBUG("enigmail.js: loadRulesFromString\n");
+ if (contents.length === 0 || contents.search(/^\s*$/) === 0) {
+ return false;
}
- return false;
+
+ var domParser =
Cc[NS_DOMPARSER_CONTRACTID].createInstance(Ci.nsIDOMParser);
+ rulesListHolder.rulesList = domParser.parseFromString(contents,
"text/xml");
+
+ return true;
},
saveRulesFile: function() {
@@ -170,9 +175,11 @@ const EnigmailRules = {
registerOn: function(target) {
target.getRulesFile = EnigmailRules.getRulesFile;
target.loadRulesFile = EnigmailRules.loadRulesFile;
+ target.loadRulesFromString = EnigmailRules.loadRulesFromString;
target.saveRulesFile = EnigmailRules.saveRulesFile;
target.getRulesData = EnigmailRules.getRulesData;
target.addRule = EnigmailRules.addRule;
target.clearRules = EnigmailRules.clearRules;
}
};
+
diff --git a/ui/content/pref-enigmail.js b/ui/content/pref-enigmail.js
index e752e7f..6dd3248 100644
--- a/ui/content/pref-enigmail.js
+++ b/ui/content/pref-enigmail.js
@@ -35,6 +35,8 @@
// Uses: chrome://enigmail/content/enigmailCommon.js
+Components.utils.import("resource://enigmail/rules.jsm");
+
// Initialize enigmailCommon
EnigInitCommon("pref-enigmail");
@@ -304,38 +306,16 @@ function backupPrefs() {
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;
- }
+ // user preference
+ var prefObj = EnigmailPrefs.getAllPrefs();
- 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");
- }
+ // per-recipient rules (aka pgpRules.xml)
+ var rulesFile = EnigmailRules.getRulesFile();
+ if (rulesFile.exists()) {
+ prefObj.rules = EnigmailFiles.readFile(rulesFile);
+ }
+ else {
+ prefObj.rules = "";
}
// serialize everything to UTF-8 encoded JSON.
@@ -378,7 +358,13 @@ function restorePrefs() {
// Set all options recorded in the JSON file.
for (var name in prefObj) {
- EnigSetPref(name, prefObj[name]);
+ if (name == "rules") {
+ EnigmailRules.loadRulesFromString(prefObj[name]);
+ EnigmailRules.saveRulesFile();
+ }
+ else {
+ EnigSetPref(name, prefObj[name]);
+ }
}
}
catch (ex) {
@@ -657,4 +643,5 @@ function enigLocateGpg() {
// }
document.getElementById("enigmail_agentPath").value = filePath.path;
}
-}
\ No newline at end of file
+}
+
--
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