2022-03-09 19:33:31 +08:00
|
|
|
/**
|
|
|
|
* https://tools.ietf.org/html/rfc5293
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {
|
2022-03-17 17:21:23 +08:00
|
|
|
ActionCommand,
|
2022-03-09 19:33:31 +08:00
|
|
|
GrammarNumber,
|
|
|
|
GrammarQuotedString,
|
|
|
|
GrammarString,
|
|
|
|
GrammarStringList
|
|
|
|
} from 'Sieve/Grammar';
|
|
|
|
|
2022-03-17 17:21:23 +08:00
|
|
|
export class AddHeaderCommand extends ActionCommand
|
2022-03-09 19:33:31 +08:00
|
|
|
{
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
this.last = false;
|
|
|
|
this.field_name = new GrammarQuotedString;
|
|
|
|
this.value = new GrammarQuotedString;
|
|
|
|
}
|
|
|
|
|
|
|
|
get require() { return 'editheader'; }
|
|
|
|
|
|
|
|
toString()
|
|
|
|
{
|
|
|
|
return this.identifier
|
|
|
|
+ (this.last ? ' :last' : '')
|
|
|
|
+ ' ' + this.field_name
|
|
|
|
+ ' ' + this.value + ';';
|
|
|
|
}
|
|
|
|
|
|
|
|
pushArguments(args)
|
|
|
|
{
|
2022-03-15 16:58:04 +08:00
|
|
|
this.value = args.pop();
|
|
|
|
this.field_name = args.pop();
|
2022-03-09 19:33:31 +08:00
|
|
|
this.last = args.includes(':last');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-17 17:21:23 +08:00
|
|
|
export class DeleteHeaderCommand extends ActionCommand
|
2022-03-09 19:33:31 +08:00
|
|
|
{
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
this.index = new GrammarNumber;
|
|
|
|
this.last = false;
|
|
|
|
this.comparator = '',
|
|
|
|
this.match_type = ':is',
|
|
|
|
this.field_name = new GrammarQuotedString;
|
|
|
|
this.value_patterns = new GrammarStringList;
|
|
|
|
}
|
|
|
|
|
|
|
|
get require() { return 'editheader'; }
|
|
|
|
|
|
|
|
toString()
|
|
|
|
{
|
|
|
|
return this.identifier
|
|
|
|
+ (this.last ? ' :last' : (this.index.value ? ' :index ' + this.index : ''))
|
|
|
|
+ (this.comparator ? ' :comparator ' + this.comparator : '')
|
|
|
|
+ ' ' + this.match_type
|
|
|
|
+ ' ' + this.field_name
|
|
|
|
+ ' ' + this.value_patterns + ';';
|
|
|
|
}
|
|
|
|
|
|
|
|
pushArguments(args)
|
|
|
|
{
|
|
|
|
let l = args.length - 1;
|
|
|
|
args.forEach((arg, i) => {
|
|
|
|
if (':last' === arg) {
|
|
|
|
this.last = true;
|
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;
|
|
|
|
args[i] = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-05-17 20:48:38 +08:00
|
|
|
if (l && args[l-1] instanceof GrammarString) {
|
2022-03-09 19:33:31 +08:00
|
|
|
this.field_name = args[l-1];
|
|
|
|
this.value_patterns = args[l];
|
|
|
|
} else {
|
|
|
|
this.field_name = args[l];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|