mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-06 16:07:03 +03:00
Added the new Sieve parser as script validator
This commit is contained in:
parent
9bae77bfa1
commit
42813b90dd
3 changed files with 19 additions and 5 deletions
|
|
@ -168,7 +168,7 @@ export const parseScript = (script, name = 'script.sieve') => {
|
||||||
error = message => {
|
error = message => {
|
||||||
// throw new SyntaxError(message + ' at ' + regex.lastIndex + ' line ' + line, name, line)
|
// throw new SyntaxError(message + ' at ' + regex.lastIndex + ' line ' + line, name, line)
|
||||||
throw new SyntaxError(message + ' on line ' + 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 => {
|
pushArg = arg => {
|
||||||
command || error('Argument not part of command');
|
command || error('Argument not part of command');
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { SieveScriptModel } from 'Sieve/Model/Script';
|
||||||
|
|
||||||
import { FilterPopupView } from 'Sieve/View/Filter';
|
import { FilterPopupView } from 'Sieve/View/Filter';
|
||||||
|
|
||||||
//import { parseScript } from 'Sieve/Parser';
|
import { parseScript } from 'Sieve/Parser';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
capa,
|
capa,
|
||||||
|
|
@ -18,7 +18,7 @@ export class SieveScriptPopupView extends rl.pluginPopupView {
|
||||||
|
|
||||||
this.addObservables({
|
this.addObservables({
|
||||||
saveError: false,
|
saveError: false,
|
||||||
saveErrorText: '',
|
errorText: '',
|
||||||
rawActive: false,
|
rawActive: false,
|
||||||
allowToggle: false,
|
allowToggle: false,
|
||||||
script: null
|
script: null
|
||||||
|
|
@ -30,6 +30,15 @@ export class SieveScriptPopupView extends rl.pluginPopupView {
|
||||||
this.filterForDeletion = ko.observable(null).askDeleteHelper();
|
this.filterForDeletion = ko.observable(null).askDeleteHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
validateScript() {
|
||||||
|
try {
|
||||||
|
this.errorText('');
|
||||||
|
parseScript(this.script().body());
|
||||||
|
} catch (e) {
|
||||||
|
this.errorText(e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
saveScript() {
|
saveScript() {
|
||||||
let self = this,
|
let self = this,
|
||||||
script = self.script();
|
script = self.script();
|
||||||
|
|
@ -45,6 +54,7 @@ export class SieveScriptPopupView extends rl.pluginPopupView {
|
||||||
|
|
||||||
self.saving = true;
|
self.saving = true;
|
||||||
self.saveError(false);
|
self.saveError(false);
|
||||||
|
self.errorText('');
|
||||||
|
|
||||||
if (self.allowToggle()) {
|
if (self.allowToggle()) {
|
||||||
script.body(script.filtersToRaw());
|
script.body(script.filtersToRaw());
|
||||||
|
|
@ -56,7 +66,7 @@ export class SieveScriptPopupView extends rl.pluginPopupView {
|
||||||
|
|
||||||
if (iError) {
|
if (iError) {
|
||||||
self.saveError(true);
|
self.saveError(true);
|
||||||
self.saveErrorText((data && data.ErrorMessageAdditional) || getNotification(iError));
|
self.errorText((data && data.ErrorMessageAdditional) || getNotification(iError));
|
||||||
} else {
|
} else {
|
||||||
script.exists() || scripts.push(script);
|
script.exists() || scripts.push(script);
|
||||||
script.exists(true);
|
script.exists(true);
|
||||||
|
|
@ -125,6 +135,7 @@ export class SieveScriptPopupView extends rl.pluginPopupView {
|
||||||
this.rawActive(raw);
|
this.rawActive(raw);
|
||||||
this.allowToggle(!raw);
|
this.allowToggle(!raw);
|
||||||
this.saveError(false);
|
this.saveError(false);
|
||||||
|
this.errorText('');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// TODO: Sieve GUI
|
// TODO: Sieve GUI
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="alert g-ui-user-select-none" data-bind="visible: hasChanges" data-icon="⚠" data-i18n="POPUPS_SIEVE_SCRIPT/CHANGES_NEED_TO_BE_SAVED_DESC"></div>
|
<div class="alert g-ui-user-select-none" data-bind="visible: hasChanges" data-icon="⚠" data-i18n="POPUPS_SIEVE_SCRIPT/CHANGES_NEED_TO_BE_SAVED_DESC"></div>
|
||||||
<div class="alert alert-error g-ui-user-select-none" data-bind="visible: $root.saveError, text: $root.saveErrorText" data-icon="⚠"></div>
|
<div class="alert alert-error g-ui-user-select-none" style="white-space:pre" data-bind="visible: $root.errorText, text: $root.errorText" data-icon="⚠"></div>
|
||||||
|
|
||||||
<div class="control-group" data-bind="visible: $root.rawActive">
|
<div class="control-group" data-bind="visible: $root.rawActive">
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -64,6 +64,9 @@
|
||||||
<a class="btn" data-bind="visible: $root.allowToggle, click: function() { $root.toggleFiltersRaw(); }, css: {'active': $root.rawActive }" data-i18n="[title]POPUPS_SIEVE_SCRIPT/BUTTON_RAW_SCRIPT">
|
<a class="btn" data-bind="visible: $root.allowToggle, click: function() { $root.toggleFiltersRaw(); }, css: {'active': $root.rawActive }" data-i18n="[title]POPUPS_SIEVE_SCRIPT/BUTTON_RAW_SCRIPT">
|
||||||
<i class="icon-file-code"></i>
|
<i class="icon-file-code"></i>
|
||||||
</a>
|
</a>
|
||||||
|
<a class="btn" data-bind="visible: $root.rawActive, click: function() { $root.validateScript(); }">
|
||||||
|
Validate
|
||||||
|
</a>
|
||||||
<a class="btn buttonSave" data-bind="visible: hasChanges, click: function() { $root.saveScript(); }, css: {'btn-danger': $root.saveError}">
|
<a class="btn buttonSave" data-bind="visible: hasChanges, click: function() { $root.saveScript(); }, css: {'btn-danger': $root.saveError}">
|
||||||
<i class="fontastic" data-bind="css: {'icon-spinner': $root.saving}">💾</i>
|
<i class="fontastic" data-bind="css: {'icon-spinner': $root.saving}">💾</i>
|
||||||
<span data-i18n="GLOBAL/SAVE"></span>
|
<span data-i18n="GLOBAL/SAVE"></span>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue