snappymail/dev/Sieve/Extensions/rfc5260.js

94 lines
2.1 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();
this.zone = new GrammarQuotedString;
this.originalzone = false;
this.header_name = new GrammarQuotedString;
this.date_part = new GrammarQuotedString;
this.key_list = new GrammarStringList;
// rfc5260#section-6
this.index = new GrammarNumber;
this.last = false;
}
// get require() { return ['date','index']; }
get require() { return 'date'; }
toString()
{
return 'date'
+ (this.last ? ' :last' : (this.index.value ? ' :index ' + this.index : ''))
+ (this.originalzone ? ' :originalzone' : (this.zone.length ? ' :zone ' + this.zone : ''))
+ (this.comparator ? ' :comparator ' + this.comparator : '')
+ ' ' + this.match_type
+ ' ' + 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();
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;
} else if (':zone' === args[i-1]) {
this.zone.value = arg.value;
} else if (':index' === args[i-1]) {
this.index.value = arg.value;
}
});
}
}
export class CurrentDateTest extends TestCommand
2022-03-09 19:33:31 +08:00
{
constructor()
{
super();
2022-03-09 19:33:31 +08:00
this.zone = new GrammarQuotedString;
this.date_part = new GrammarQuotedString;
this.key_list = new GrammarStringList;
}
get require() { return 'date'; }
toString()
{
return 'currentdate'
2022-03-09 19:33:31 +08:00
+ (this.zone.length ? ' :zone ' + this.zone : '')
+ (this.comparator ? ' :comparator ' + this.comparator : '')
+ ' ' + this.match_type
+ ' ' + 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();
this.date_part = args.pop();
2022-03-09 19:33:31 +08:00
args.forEach((arg, i) => {
if (':zone' === args[i-1]) {
this.zone.value = arg.value;
}
});
}
}