snappymail/dev/Sieve/Extensions/rfc5260.js

111 lines
2.7 KiB
JavaScript
Raw Normal View History

2022-03-09 19:33:31 +08:00
/**
* https://tools.ietf.org/html/rfc5260
*/
import {
GrammarNumber,
GrammarQuotedString,
GrammarStringList,
TestCommand
2022-03-09 19:33:31 +08:00
} from 'Sieve/Grammar';
export class DateTest extends TestCommand
2022-03-09 19:33:31 +08:00
{
constructor()
{
super();
2024-09-23 19:43:24 +08:00
this._zone = new GrammarQuotedString;
2022-03-09 19:33:31 +08:00
this.originalzone = false;
2024-09-23 19:43:24 +08:00
this._header_name = new GrammarQuotedString;
this._date_part = new GrammarQuotedString;
2022-03-09 19:33:31 +08:00
this.key_list = new GrammarStringList;
// rfc5260#section-6
this.index = new GrammarNumber;
this.last = false;
}
// get require() { return ['date','index']; }
get require() { return 'date'; }
2024-09-23 19:43:24 +08:00
get zone() { return this._zone.value; }
set zone(v) { this._zone.value = v; }
get header_name() { return this._header_name.value; }
set header_name(v) { this._header_name.value = v; }
get date_part() { return this._date_part.value; }
set date_part(v) { this._date_part.value = v; }
2022-03-09 19:33:31 +08:00
toString()
{
return 'date'
+ (this.last ? ' :last' : (this.index.value ? ' :index ' + this.index : ''))
2024-09-23 19:43:24 +08:00
+ (this.originalzone ? ' :originalzone' : (this._zone.length ? ' :zone ' + this._zone : ''))
+ (this._comparator ? ' :comparator ' + this._comparator : '')
+ (this._match_type ? ' ' + this._match_type : '')
+ (this.relational_match ? ' ' + this.relational_match : '')
2024-09-23 19:43:24 +08:00
+ ' ' + this._header_name
+ ' ' + this._date_part
2022-03-16 21:21:23 +08:00
+ ' ' + this.key_list;
2022-03-09 19:33:31 +08:00
}
pushArguments(args)
{
2022-03-15 16:58:04 +08:00
this.key_list = args.pop();
2024-09-23 19:43:24 +08:00
this._date_part = args.pop();
this._header_name = args.pop();
2022-03-09 19:33:31 +08:00
args.forEach((arg, i) => {
if (':originalzone' === arg) {
this.originalzone = true;
} else if (':last' === arg) {
this.last = true;
2022-05-17 20:48:38 +08:00
} else if (i && ':zone' === args[i-1]) {
2024-09-23 19:43:24 +08:00
this._zone.value = arg.value;
2022-05-17 20:48:38 +08:00
} else if (i && ':index' === args[i-1]) {
2022-03-09 19:33:31 +08:00
this.index.value = arg.value;
}
});
}
}
export class CurrentDateTest extends TestCommand
2022-03-09 19:33:31 +08:00
{
constructor()
{
super();
2024-09-23 19:43:24 +08:00
this._zone = new GrammarQuotedString;
this._date_part = new GrammarQuotedString;
2022-03-09 19:33:31 +08:00
this.key_list = new GrammarStringList;
}
get require() { return 'date'; }
2024-09-23 19:43:24 +08:00
get zone() { return this._zone.value; }
set zone(v) { this._zone.value = v; }
get date_part() { return this._date_part.value; }
set date_part(v) { this._date_part.value = v; }
2022-03-09 19:33:31 +08:00
toString()
{
return 'currentdate'
2024-09-23 19:43:24 +08:00
+ (this._zone.length ? ' :zone ' + this._zone : '')
+ (this._comparator ? ' :comparator ' + this._comparator : '')
+ (this._match_type ? ' ' + this._match_type : '')
+ (this.relational_match ? ' ' + this.relational_match : '')
2024-09-23 19:43:24 +08:00
+ ' ' + this._date_part
2022-03-16 21:21:23 +08:00
+ ' ' + this.key_list;
2022-03-09 19:33:31 +08:00
}
pushArguments(args)
{
2022-03-15 16:58:04 +08:00
this.key_list = args.pop();
2024-09-23 19:43:24 +08:00
this._date_part = args.pop();
2022-03-09 19:33:31 +08:00
args.forEach((arg, i) => {
2022-05-17 20:48:38 +08:00
if (i && ':zone' === args[i-1]) {
2024-09-23 19:43:24 +08:00
this._zone.value = arg.value;
2022-03-09 19:33:31 +08:00
}
});
}
}