mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-06-26 16:26:44 +03:00
Bugfix handling of RainLoop Sieve script
This commit is contained in:
parent
f3935b1df4
commit
a96ff94c6f
5 changed files with 35 additions and 11 deletions
|
|
@ -26,7 +26,7 @@ export class AbstractModel {
|
||||||
throw new Error("Can't instantiate AbstractModel!");
|
throw new Error("Can't instantiate AbstractModel!");
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
this.disposables = [];
|
Object.defineProperty(this, 'disposables', {value: []});
|
||||||
}
|
}
|
||||||
|
|
||||||
addObservables(observables) {
|
addObservables(observables) {
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ export class AbstractModel {
|
||||||
throw new Error("Can't instantiate AbstractModel!");
|
throw new Error("Can't instantiate AbstractModel!");
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
this.disposables = [];
|
Object.defineProperty(this, 'disposables', {value: []});
|
||||||
}
|
}
|
||||||
|
|
||||||
addObservables(observables) {
|
addObservables(observables) {
|
||||||
|
|
|
||||||
|
|
@ -188,6 +188,24 @@ export class FilterModel extends AbstractModel {
|
||||||
this.conditions.remove(oConditionToDelete);
|
this.conditions.remove(oConditionToDelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toJSON() {
|
||||||
|
return {
|
||||||
|
ID: this.id,
|
||||||
|
Enabled: this.enabled(),
|
||||||
|
Name: this.name(),
|
||||||
|
Conditions: this.conditions(),
|
||||||
|
ConditionsType: this.conditionsType(),
|
||||||
|
ActionType: this.actionType(),
|
||||||
|
ActionValue: this.actionValue(),
|
||||||
|
ActionValueSecond: this.actionValueSecond(),
|
||||||
|
ActionValueThird: this.actionValueThird(),
|
||||||
|
ActionValueFourth: this.actionValueFourth(),
|
||||||
|
Keep: this.keep(),
|
||||||
|
Stop: this.stop(),
|
||||||
|
MarkAsRead: this.markAsRead()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @static
|
* @static
|
||||||
* @param {FetchJsonFilter} json
|
* @param {FetchJsonFilter} json
|
||||||
|
|
@ -200,7 +218,10 @@ export class FilterModel extends AbstractModel {
|
||||||
if (filter) {
|
if (filter) {
|
||||||
filter.id = '' + (filter.id || '');
|
filter.id = '' + (filter.id || '');
|
||||||
filter.conditions(
|
filter.conditions(
|
||||||
(json.Conditions || []).map(aData => FilterConditionModel.reviveFromJson(aData)).filter(v => v)
|
(json.Conditions || json.conditions || []).map(condition => {
|
||||||
|
condition['@Object'] = 'Object/FilterCondition';
|
||||||
|
return FilterConditionModel.reviveFromJson(condition)
|
||||||
|
}).filter(v => v)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return filter;
|
return filter;
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,15 @@ export class FilterConditionModel extends AbstractModel {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toJSON() {
|
||||||
|
return {
|
||||||
|
Field: this.field(),
|
||||||
|
Type: this.type(),
|
||||||
|
Value: this.value(),
|
||||||
|
ValueSecond: this.valueSecond()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// static reviveFromJson(json) {}
|
// static reviveFromJson(json) {}
|
||||||
|
|
||||||
cloneSelf() {
|
cloneSelf() {
|
||||||
|
|
|
||||||
|
|
@ -228,7 +228,7 @@ function filtersToSieveScript(filters)
|
||||||
}
|
}
|
||||||
|
|
||||||
// fileStringToCollection
|
// fileStringToCollection
|
||||||
function sieveScriptToFilters(script)
|
function rainloopScriptToFilters(script)
|
||||||
{
|
{
|
||||||
let regex = /BEGIN:HEADER([\s\S]+?)END:HEADER/gm,
|
let regex = /BEGIN:HEADER([\s\S]+?)END:HEADER/gm,
|
||||||
filters = [],
|
filters = [],
|
||||||
|
|
@ -239,7 +239,6 @@ function sieveScriptToFilters(script)
|
||||||
json = decodeURIComponent(escape(atob(json[1].replace(/\s+/g, ''))));
|
json = decodeURIComponent(escape(atob(json[1].replace(/\s+/g, ''))));
|
||||||
if (json && json.length && (json = JSON.parse(json))) {
|
if (json && json.length && (json = JSON.parse(json))) {
|
||||||
json['@Object'] = 'Object/Filter';
|
json['@Object'] = 'Object/Filter';
|
||||||
json.Conditions.forEach(condition => condition['@Object'] = 'Object/FilterCondition');
|
|
||||||
filter = FilterModel.reviveFromJson(json);
|
filter = FilterModel.reviveFromJson(json);
|
||||||
filter && filters.push(filter);
|
filter && filters.push(filter);
|
||||||
}
|
}
|
||||||
|
|
@ -279,11 +278,6 @@ export class SieveScriptModel extends AbstractModel
|
||||||
// this.body(filtersToSieveScript(this.filters));
|
// this.body(filtersToSieveScript(this.filters));
|
||||||
}
|
}
|
||||||
|
|
||||||
rawToFilters() {
|
|
||||||
return sieveScriptToFilters(this.body());
|
|
||||||
// this.filters(sieveScriptToFilters(this.body()));
|
|
||||||
}
|
|
||||||
|
|
||||||
verify() {
|
verify() {
|
||||||
this.nameError(!this.name());
|
this.nameError(!this.name());
|
||||||
return !this.nameError();
|
return !this.nameError();
|
||||||
|
|
@ -314,7 +308,7 @@ export class SieveScriptModel extends AbstractModel
|
||||||
const script = super.reviveFromJson(json);
|
const script = super.reviveFromJson(json);
|
||||||
if (script) {
|
if (script) {
|
||||||
if (script.allowFilters()) {
|
if (script.allowFilters()) {
|
||||||
script.filters(sieveScriptToFilters(script.body()));
|
script.filters(rainloopScriptToFilters(script.body()));
|
||||||
}
|
}
|
||||||
script.exists(true);
|
script.exists(true);
|
||||||
script.hasChanges(false);
|
script.hasChanges(false);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue