From 42813b90dd8e405b65150c120cb7f7bcdb5108e2 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Fri, 11 Mar 2022 13:41:13 +0100 Subject: [PATCH] Added the new Sieve parser as script validator --- dev/Sieve/Parser.js | 2 +- dev/Sieve/View/Script.js | 17 ++++++++++++++--- .../templates/Views/User/PopupsSieveScript.html | 5 ++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/dev/Sieve/Parser.js b/dev/Sieve/Parser.js index a558b5b66..0473e2949 100644 --- a/dev/Sieve/Parser.js +++ b/dev/Sieve/Parser.js @@ -168,7 +168,7 @@ export const parseScript = (script, name = 'script.sieve') => { error = message => { // throw new SyntaxError(message + ' at ' + regex.lastIndex + ' line ' + line, name, line) throw new SyntaxError(message + ' on line ' + line - + ' around: ' + script.substr(regex.lastIndex - 10, 20).replace(/\r\n/g, '\\r\\n'), name, line) + + ' around:\n\n' + script.substr(regex.lastIndex - 20, 30), name, line) }, pushArg = arg => { command || error('Argument not part of command'); diff --git a/dev/Sieve/View/Script.js b/dev/Sieve/View/Script.js index b6b8cf64c..cb597464f 100644 --- a/dev/Sieve/View/Script.js +++ b/dev/Sieve/View/Script.js @@ -3,7 +3,7 @@ import { SieveScriptModel } from 'Sieve/Model/Script'; import { FilterPopupView } from 'Sieve/View/Filter'; -//import { parseScript } from 'Sieve/Parser'; +import { parseScript } from 'Sieve/Parser'; import { capa, @@ -18,7 +18,7 @@ export class SieveScriptPopupView extends rl.pluginPopupView { this.addObservables({ saveError: false, - saveErrorText: '', + errorText: '', rawActive: false, allowToggle: false, script: null @@ -30,6 +30,15 @@ export class SieveScriptPopupView extends rl.pluginPopupView { this.filterForDeletion = ko.observable(null).askDeleteHelper(); } + validateScript() { + try { + this.errorText(''); + parseScript(this.script().body()); + } catch (e) { + this.errorText(e.message); + } + } + saveScript() { let self = this, script = self.script(); @@ -45,6 +54,7 @@ export class SieveScriptPopupView extends rl.pluginPopupView { self.saving = true; self.saveError(false); + self.errorText(''); if (self.allowToggle()) { script.body(script.filtersToRaw()); @@ -56,7 +66,7 @@ export class SieveScriptPopupView extends rl.pluginPopupView { if (iError) { self.saveError(true); - self.saveErrorText((data && data.ErrorMessageAdditional) || getNotification(iError)); + self.errorText((data && data.ErrorMessageAdditional) || getNotification(iError)); } else { script.exists() || scripts.push(script); script.exists(true); @@ -125,6 +135,7 @@ export class SieveScriptPopupView extends rl.pluginPopupView { this.rawActive(raw); this.allowToggle(!raw); this.saveError(false); + this.errorText(''); /* // TODO: Sieve GUI diff --git a/snappymail/v/0.0.0/app/templates/Views/User/PopupsSieveScript.html b/snappymail/v/0.0.0/app/templates/Views/User/PopupsSieveScript.html index 893de585b..5e0ff4579 100644 --- a/snappymail/v/0.0.0/app/templates/Views/User/PopupsSieveScript.html +++ b/snappymail/v/0.0.0/app/templates/Views/User/PopupsSieveScript.html @@ -17,7 +17,7 @@
-
+
@@ -64,6 +64,9 @@ + + Validate + 💾