mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-03-04 18:53:42 +08: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!");
|
||||
}
|
||||
*/
|
||||
this.disposables = [];
|
||||
Object.defineProperty(this, 'disposables', {value: []});
|
||||
}
|
||||
|
||||
addObservables(observables) {
|
||||
|
|
|
@ -25,7 +25,7 @@ export class AbstractModel {
|
|||
throw new Error("Can't instantiate AbstractModel!");
|
||||
}
|
||||
*/
|
||||
this.disposables = [];
|
||||
Object.defineProperty(this, 'disposables', {value: []});
|
||||
}
|
||||
|
||||
addObservables(observables) {
|
||||
|
|
|
@ -188,6 +188,24 @@ export class FilterModel extends AbstractModel {
|
|||
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
|
||||
* @param {FetchJsonFilter} json
|
||||
|
@ -200,7 +218,10 @@ export class FilterModel extends AbstractModel {
|
|||
if (filter) {
|
||||
filter.id = '' + (filter.id || '');
|
||||
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;
|
||||
|
|
|
@ -79,6 +79,15 @@ export class FilterConditionModel extends AbstractModel {
|
|||
return true;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
Field: this.field(),
|
||||
Type: this.type(),
|
||||
Value: this.value(),
|
||||
ValueSecond: this.valueSecond()
|
||||
};
|
||||
}
|
||||
|
||||
// static reviveFromJson(json) {}
|
||||
|
||||
cloneSelf() {
|
||||
|
|
|
@ -228,7 +228,7 @@ function filtersToSieveScript(filters)
|
|||
}
|
||||
|
||||
// fileStringToCollection
|
||||
function sieveScriptToFilters(script)
|
||||
function rainloopScriptToFilters(script)
|
||||
{
|
||||
let regex = /BEGIN:HEADER([\s\S]+?)END:HEADER/gm,
|
||||
filters = [],
|
||||
|
@ -239,7 +239,6 @@ function sieveScriptToFilters(script)
|
|||
json = decodeURIComponent(escape(atob(json[1].replace(/\s+/g, ''))));
|
||||
if (json && json.length && (json = JSON.parse(json))) {
|
||||
json['@Object'] = 'Object/Filter';
|
||||
json.Conditions.forEach(condition => condition['@Object'] = 'Object/FilterCondition');
|
||||
filter = FilterModel.reviveFromJson(json);
|
||||
filter && filters.push(filter);
|
||||
}
|
||||
|
@ -279,11 +278,6 @@ export class SieveScriptModel extends AbstractModel
|
|||
// this.body(filtersToSieveScript(this.filters));
|
||||
}
|
||||
|
||||
rawToFilters() {
|
||||
return sieveScriptToFilters(this.body());
|
||||
// this.filters(sieveScriptToFilters(this.body()));
|
||||
}
|
||||
|
||||
verify() {
|
||||
this.nameError(!this.name());
|
||||
return !this.nameError();
|
||||
|
@ -314,7 +308,7 @@ export class SieveScriptModel extends AbstractModel
|
|||
const script = super.reviveFromJson(json);
|
||||
if (script) {
|
||||
if (script.allowFilters()) {
|
||||
script.filters(sieveScriptToFilters(script.body()));
|
||||
script.filters(rainloopScriptToFilters(script.body()));
|
||||
}
|
||||
script.exists(true);
|
||||
script.hasChanges(false);
|
||||
|
|
Loading…
Reference in a new issue