mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-27 19:19:21 +03:00
Better Sieve rainloop.user script handling
This commit is contained in:
parent
f080a302b1
commit
4cfd6479ce
51 changed files with 92 additions and 99 deletions
|
|
@ -82,11 +82,9 @@ export class AbstractModel {
|
|||
}
|
||||
|
||||
revivePropertiesFromJson(json) {
|
||||
let model = this.constructor;
|
||||
if (!model.validJson(json)) {
|
||||
return false;
|
||||
}
|
||||
forEachObjectEntry(json, (key, value) => {
|
||||
const model = this.constructor,
|
||||
valid = model.validJson(json);
|
||||
valid && forEachObjectEntry(json, (key, value) => {
|
||||
if ('@' !== key[0]) try {
|
||||
key = key[0].toLowerCase() + key.slice(1);
|
||||
switch (typeof this[key])
|
||||
|
|
@ -104,9 +102,12 @@ export class AbstractModel {
|
|||
case 'string':
|
||||
this[key] = typeCast(this[key], value);
|
||||
break;
|
||||
// fall through
|
||||
case 'undefined':
|
||||
default:
|
||||
console.log(`Undefined ${model.name}.${key} not set`);
|
||||
// this[key] = value;
|
||||
break;
|
||||
// default:
|
||||
// console.log((typeof this[key])+` ${model.name}.${key} not revived`);
|
||||
// console.log((typeof this[key])+' '+(model.name)+'.'+key+' not revived');
|
||||
}
|
||||
} catch (e) {
|
||||
|
|
@ -114,7 +115,7 @@ export class AbstractModel {
|
|||
console.error(e);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
return valid;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,10 +53,10 @@ export class FilterModel extends AbstractModel {
|
|||
actionValueFourth: '',
|
||||
actionValueFourthError: false,
|
||||
|
||||
actionMarkAsRead: false,
|
||||
markAsRead: false,
|
||||
|
||||
actionKeep: true,
|
||||
actionNoStop: false,
|
||||
keep: true,
|
||||
stop: true,
|
||||
|
||||
actionType: FilterAction.MoveTo
|
||||
});
|
||||
|
|
@ -181,24 +181,24 @@ export class FilterModel extends AbstractModel {
|
|||
return true;
|
||||
}
|
||||
|
||||
toJson() {
|
||||
toJSON() {
|
||||
return {
|
||||
// '@Object': 'Object/Filter',
|
||||
ID: this.id,
|
||||
Enabled: this.enabled() ? 1 : 0,
|
||||
Name: this.name(),
|
||||
Conditions: this.conditions.map(item => item.toJson()),
|
||||
ConditionsType: this.conditionsType(),
|
||||
Name: this.name,
|
||||
Conditions: this.conditions,
|
||||
ConditionsType: this.conditionsType,
|
||||
|
||||
ActionType: this.actionType(),
|
||||
ActionValue: this.actionValue(),
|
||||
ActionValueSecond: this.actionValueSecond(),
|
||||
ActionValueThird: this.actionValueThird(),
|
||||
ActionValueFourth: this.actionValueFourth(),
|
||||
ActionValue: this.actionValue,
|
||||
ActionValueSecond: this.actionValueSecond,
|
||||
ActionValueThird: this.actionValueThird,
|
||||
ActionValueFourth: this.actionValueFourth,
|
||||
|
||||
Keep: this.actionKeep() ? 1 : 0,
|
||||
Stop: this.actionNoStop() ? 0 : 1,
|
||||
MarkAsRead: this.actionMarkAsRead() ? 1 : 0
|
||||
Keep: this.keep() ? 1 : 0,
|
||||
Stop: this.stop() ? 1 : 0,
|
||||
MarkAsRead: this.markAsRead() ? 1 : 0
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -216,15 +216,14 @@ export class FilterModel extends AbstractModel {
|
|||
* @returns {?FilterModel}
|
||||
*/
|
||||
static reviveFromJson(json) {
|
||||
json.id = json.ID;
|
||||
delete json.ID;
|
||||
const filter = super.reviveFromJson(json);
|
||||
if (filter) {
|
||||
filter.id = '' + (filter.id || '');
|
||||
filter.conditions(
|
||||
(json.Conditions || []).map(aData => FilterConditionModel.reviveFromJson(aData)).filter(v => v)
|
||||
);
|
||||
filter.actionKeep(0 != json.Keep);
|
||||
filter.actionNoStop(0 == json.Stop);
|
||||
filter.actionMarkAsRead(1 == json.MarkAsRead);
|
||||
}
|
||||
return filter;
|
||||
}
|
||||
|
|
@ -241,7 +240,7 @@ export class FilterModel extends AbstractModel {
|
|||
|
||||
filter.conditionsType(this.conditionsType());
|
||||
|
||||
filter.actionMarkAsRead(this.actionMarkAsRead());
|
||||
filter.markAsRead(this.markAsRead());
|
||||
|
||||
filter.actionType(this.actionType());
|
||||
|
||||
|
|
@ -252,8 +251,8 @@ export class FilterModel extends AbstractModel {
|
|||
filter.actionValueThird(this.actionValueThird());
|
||||
filter.actionValueFourth(this.actionValueFourth());
|
||||
|
||||
filter.actionKeep(this.actionKeep());
|
||||
filter.actionNoStop(this.actionNoStop());
|
||||
filter.keep(this.keep());
|
||||
filter.stop(this.stop());
|
||||
|
||||
filter.conditions(this.conditions.map(item => item.cloneSelf()));
|
||||
|
||||
|
|
|
|||
|
|
@ -81,13 +81,13 @@ export class FilterConditionModel extends AbstractModel {
|
|||
|
||||
// static reviveFromJson(json) {}
|
||||
|
||||
toJson() {
|
||||
toJSON() {
|
||||
return {
|
||||
// '@Object': 'Object/FilterCondition',
|
||||
Field: this.field(),
|
||||
Type: this.type(),
|
||||
Value: this.value(),
|
||||
ValueSecond: this.valueSecond()
|
||||
Field: this.field,
|
||||
Type: this.type,
|
||||
Value: this.value,
|
||||
ValueSecond: this.valueSecond
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ function filtersToSieveScript(filters)
|
|||
// actions
|
||||
block ? result.push('{') : (sTab = '');
|
||||
|
||||
if (filter.actionMarkAsRead() && ['None','MoveTo','Forward'].includes(filter.actionType())) {
|
||||
if (filter.markAsRead() && ['None','MoveTo','Forward'].includes(filter.actionType())) {
|
||||
require.imap4flags = 1;
|
||||
result.push(sTab + 'addflag "\\\\Seen";');
|
||||
}
|
||||
|
|
@ -182,7 +182,7 @@ function filtersToSieveScript(filters)
|
|||
break; }
|
||||
case 'Forward':
|
||||
if (value) {
|
||||
if (filter.actionKeep()) {
|
||||
if (filter.keep()) {
|
||||
require.fileinto = 1;
|
||||
result.push(sTab + 'fileinto "INBOX";');
|
||||
}
|
||||
|
|
@ -201,7 +201,7 @@ function filtersToSieveScript(filters)
|
|||
break;
|
||||
}
|
||||
|
||||
filter.actionNoStop() || result.push(sTab + 'stop;');
|
||||
filter.stop() && result.push(sTab + 'stop;');
|
||||
|
||||
block && result.push('}');
|
||||
|
||||
|
|
@ -213,7 +213,7 @@ function filtersToSieveScript(filters)
|
|||
'/*',
|
||||
'BEGIN:FILTER:' + filter.id,
|
||||
'BEGIN:HEADER',
|
||||
btoa(unescape(encodeURIComponent(JSON.stringify(filter.toJson())))).match(split).join(eol) + 'END:HEADER',
|
||||
btoa(unescape(encodeURIComponent(JSON.stringify(filter)))).match(split).join(eol) + 'END:HEADER',
|
||||
'*/',
|
||||
filter.enabled() ? '' : '/* @Filter is disabled ',
|
||||
filterToString(filter, require),
|
||||
|
|
@ -290,13 +290,12 @@ export class SieveScriptModel extends AbstractModel
|
|||
return !this.nameError();
|
||||
}
|
||||
|
||||
toJson() {
|
||||
toJSON() {
|
||||
return {
|
||||
name: this.name(),
|
||||
active: this.active() ? 1 : 0,
|
||||
body: this.body()
|
||||
name: this.name,
|
||||
active: this.active,
|
||||
body: this.body
|
||||
// body: this.allowFilters() ? this.body() : this.filtersToRaw()
|
||||
// filters: this.filters.map(item => item.toJson())
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -316,13 +315,7 @@ export class SieveScriptModel extends AbstractModel
|
|||
const script = super.reviveFromJson(json);
|
||||
if (script) {
|
||||
if (script.allowFilters()) {
|
||||
script.filters(
|
||||
Array.isArray(json.filters) && json.filters.length
|
||||
? json.filters.map(aData => FilterModel.reviveFromJson(aData)).filter(v => v)
|
||||
: sieveScriptToFilters(script.body())
|
||||
);
|
||||
} else {
|
||||
script.filters([]);
|
||||
script.filters(sieveScriptToFilters(script.body()));
|
||||
}
|
||||
script.canBeDeleted(SIEVE_FILE_NAME !== json.name);
|
||||
script.exists(true);
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ export class SieveScriptPopupView extends rl.pluginPopupView {
|
|||
// this.close();
|
||||
}
|
||||
},
|
||||
script.toJson()
|
||||
script.toJSON()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@
|
|||
@media screen and (max-width: 999px) {
|
||||
#rl-settings-subscreen {
|
||||
padding: 10px;
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
#rl-right {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue