snappymail/dev/Sieve/Extensions/rfc5230.js

89 lines
2.4 KiB
JavaScript
Raw Normal View History

2022-03-09 19:33:31 +08:00
/**
* https://tools.ietf.org/html/rfc5230
* https://tools.ietf.org/html/rfc6131
*/
2022-03-15 17:16:26 +08:00
import { capa } from 'Sieve/Utils';
2022-03-09 19:33:31 +08:00
import {
ActionCommand,
2022-03-09 19:33:31 +08:00
GrammarNumber,
GrammarQuotedString,
GrammarStringList
} from 'Sieve/Grammar';
export class VacationCommand extends ActionCommand
2022-03-09 19:33:31 +08:00
{
constructor()
{
super();
this._days = new GrammarNumber;
2022-03-15 17:16:26 +08:00
this._seconds = new GrammarNumber;
2022-03-09 19:33:31 +08:00
this._subject = new GrammarQuotedString;
this._from = new GrammarQuotedString;
this.addresses = new GrammarStringList;
this.mime = false;
this._handle = new GrammarQuotedString;
this._reason = new GrammarQuotedString; // QuotedString / MultiLine
}
// get require() { return ['vacation','vacation-seconds']; }
get require() { return 'vacation'; }
toString()
{
let result = 'vacation';
2022-03-15 17:16:26 +08:00
if (0 < this._seconds.value && capa.includes('vacation-seconds')) {
result += ' :seconds ' + this._seconds;
} else if (0 < this._days.value) {
2022-03-09 19:33:31 +08:00
result += ' :days ' + this._days;
}
if (this._subject.length) {
result += ' :subject ' + this._subject;
}
if (this._from.length) {
2022-03-16 19:05:50 +08:00
result += ' :from ' + this._from;
// result += ' :from ' + this.arguments[':from'];
2022-03-09 19:33:31 +08:00
}
if (this.addresses.length) {
2022-03-16 21:21:23 +08:00
result += ' :addresses ' + this.addresses;
2022-03-09 19:33:31 +08:00
}
if (this.mime) {
result += ' :mime';
}
if (this._handle.length) {
result += ' :handle ' + this._handle;
}
return result + ' ' + this._reason;
}
get days() { return this._days.value; }
2022-03-15 17:16:26 +08:00
get seconds() { return this._seconds.value; }
2022-03-09 19:33:31 +08:00
get subject() { return this._subject.value; }
get from() { return this._from.value; }
get handle() { return this._handle.value; }
get reason() { return this._reason.value; }
set days(int) { this._days.value = int; }
2022-03-15 17:16:26 +08:00
set seconds(int) { this._seconds.value = int; }
2022-03-09 19:33:31 +08:00
set subject(str) { this._subject.value = str; }
set from(str) { this._from.value = str; }
set handle(str) { this._handle.value = str; }
set reason(str) { this._reason.value = str; }
pushArguments(args)
{
2022-03-15 16:58:04 +08:00
this._reason.value = args.pop().value; // GrammarQuotedString
2022-03-09 19:33:31 +08:00
args.forEach((arg, i) => {
if (':mime' === arg) {
this.mime = true;
2022-05-17 20:48:38 +08:00
} else if (i && ':addresses' === args[i-1]) {
2022-03-15 16:58:04 +08:00
this.addresses = arg; // GrammarStringList
2022-05-17 20:48:38 +08:00
} else if (i && ':' === args[i-1][0]) {
2022-03-15 16:58:04 +08:00
// :days, :seconds, :subject, :from, :handle
this[args[i-1].replace(':','_')].value = arg.value;
2022-03-09 19:33:31 +08:00
}
});
}
}