snappymail/dev/Sieve/Extensions/rfc6609.js

70 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-03-09 19:33:31 +08:00
/**
* https://tools.ietf.org/html/rfc6609
*/
import {
ControlCommand,
GrammarQuotedString,
GrammarStringList
2022-03-09 19:33:31 +08:00
} from 'Sieve/Grammar';
export class IncludeCommand extends ControlCommand
2022-03-09 19:33:31 +08:00
{
constructor()
{
super();
this.global = false; // ':personal' / ':global';
this.once = false;
this.optional = false;
this.value = new GrammarQuotedString;
}
get require() { return 'include'; }
toString()
{
return 'include'
2022-03-09 19:33:31 +08:00
+ (this.global ? ' :global' : '')
+ (this.once ? ' :once' : '')
+ (this.optional ? ' :optional' : '')
+ ' ' + this.value + ';';
}
pushArguments(args)
{
args.forEach(arg => {
if (':global' === arg || ':once' === arg || ':optional' === arg) {
2022-10-19 22:43:16 +08:00
this[arg.slice(1)] = true;
2022-03-09 19:33:31 +08:00
} else if (arg instanceof GrammarQuotedString) {
this.value = arg;
}
});
}
}
export class ReturnCommand extends ControlCommand
2022-03-09 19:33:31 +08:00
{
get require() { return 'include'; }
}
export class GlobalCommand extends ControlCommand
{
constructor()
{
super();
this.value = new GrammarStringList;
}
get require() { return ['include', 'variables']; }
toString()
{
return 'global ' + this.value + ';';
}
pushArguments(args)
{
this.value = args.pop();
}
}