2021-01-14 04:23:19 +08:00
|
|
|
/**
|
|
|
|
* https://tools.ietf.org/html/rfc5228#section-5
|
|
|
|
*/
|
|
|
|
|
|
|
|
(Sieve => {
|
|
|
|
|
2021-01-14 23:38:26 +08:00
|
|
|
const Grammar = Sieve.Grammar,
|
|
|
|
Test = Grammar.Test,
|
|
|
|
StringList = Grammar.StringList;
|
|
|
|
|
2021-01-14 04:23:19 +08:00
|
|
|
/**
|
|
|
|
* https://tools.ietf.org/html/rfc5228#section-5.1
|
|
|
|
*/
|
2021-01-14 23:38:26 +08:00
|
|
|
class Address extends Test
|
2021-01-14 04:23:19 +08:00
|
|
|
{
|
|
|
|
constructor()
|
|
|
|
{
|
2021-01-14 23:38:26 +08:00
|
|
|
super('address');
|
2021-01-15 18:34:16 +08:00
|
|
|
this.comparator = '';
|
2021-01-14 04:23:19 +08:00
|
|
|
this.address_part = ':all'; // :localpart | :domain | :all
|
|
|
|
this.match_type = ':is';
|
2021-01-14 23:38:26 +08:00
|
|
|
this.header_list = new StringList;
|
|
|
|
this.key_list = new StringList;
|
2021-01-14 04:23:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
toString()
|
|
|
|
{
|
|
|
|
return 'address'
|
|
|
|
// + ' ' + this.comparator
|
|
|
|
+ ' ' + this.address_part
|
|
|
|
+ ' ' + this.match_type
|
|
|
|
+ ' ' + this.header_list
|
|
|
|
+ ' ' + this.key_list;
|
|
|
|
}
|
|
|
|
|
2021-01-15 07:32:04 +08:00
|
|
|
pushArguments(args)
|
2021-01-14 04:23:19 +08:00
|
|
|
{
|
2021-01-15 07:32:04 +08:00
|
|
|
args.forEach((arg, i) => {
|
2021-01-15 18:34:16 +08:00
|
|
|
if (':localpart' === arg || ':domain' === arg || ':all' === arg) {
|
2021-01-15 07:32:04 +08:00
|
|
|
this.address_part = arg;
|
|
|
|
} else if (arg instanceof StringList || arg instanceof Grammar.StringType) {
|
2021-01-15 18:34:16 +08:00
|
|
|
this[args[i+1] ? 'header_list' : 'key_list'] = arg;
|
|
|
|
// (args[i+1] ? this.header_list : this.key_list) = arg;
|
2021-01-15 07:32:04 +08:00
|
|
|
}
|
|
|
|
});
|
2021-01-14 04:23:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* https://tools.ietf.org/html/rfc5228#section-5.2
|
|
|
|
*/
|
2021-01-14 23:38:26 +08:00
|
|
|
class AllOf extends Test
|
2021-01-14 04:23:19 +08:00
|
|
|
{
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
super('allof');
|
2021-01-14 23:38:26 +08:00
|
|
|
this.tests = new Grammar.TestList;
|
|
|
|
}
|
|
|
|
|
|
|
|
toString()
|
|
|
|
{
|
2021-01-15 18:34:16 +08:00
|
|
|
return 'allof ' + this.tests;
|
2021-01-14 04:23:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* https://tools.ietf.org/html/rfc5228#section-5.3
|
|
|
|
*/
|
2021-01-14 23:38:26 +08:00
|
|
|
class AnyOf extends Test
|
2021-01-14 04:23:19 +08:00
|
|
|
{
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
super('anyof');
|
2021-01-14 23:38:26 +08:00
|
|
|
this.tests = new Grammar.TestList;
|
|
|
|
}
|
|
|
|
|
|
|
|
toString()
|
|
|
|
{
|
2021-01-15 18:34:16 +08:00
|
|
|
return 'anyof ' + this.tests;
|
2021-01-14 04:23:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* https://tools.ietf.org/html/rfc5228#section-5.4
|
|
|
|
*/
|
2021-01-14 23:38:26 +08:00
|
|
|
class Envelope extends Test
|
2021-01-14 04:23:19 +08:00
|
|
|
{
|
|
|
|
constructor()
|
|
|
|
{
|
2021-01-14 23:38:26 +08:00
|
|
|
super('envelope');
|
2021-01-15 18:34:16 +08:00
|
|
|
this.comparator = '';
|
2021-01-14 04:23:19 +08:00
|
|
|
this.address_part = ':all'; // :localpart | :domain | :all
|
|
|
|
this.match_type = ':is';
|
2021-01-14 23:38:26 +08:00
|
|
|
this.envelope_part = new StringList;
|
|
|
|
this.key_list = new StringList;
|
2021-01-14 04:23:19 +08:00
|
|
|
}
|
|
|
|
|
2021-01-15 07:14:45 +08:00
|
|
|
get require() { return 'envelope'; }
|
|
|
|
|
2021-01-14 04:23:19 +08:00
|
|
|
toString()
|
|
|
|
{
|
|
|
|
return 'envelope'
|
|
|
|
// + ' ' + this.comparator
|
|
|
|
+ ' ' + this.address_part
|
|
|
|
+ ' ' + this.match_type
|
|
|
|
+ ' ' + this.envelope_part
|
|
|
|
+ ' ' + this.key_list;
|
|
|
|
}
|
|
|
|
|
2021-01-15 07:32:04 +08:00
|
|
|
pushArguments(args)
|
2021-01-14 04:23:19 +08:00
|
|
|
{
|
2021-01-15 07:32:04 +08:00
|
|
|
args.forEach((arg, i) => {
|
2021-01-15 18:34:16 +08:00
|
|
|
if (':localpart' === arg || ':domain' === arg || ':all' === arg) {
|
2021-01-15 07:32:04 +08:00
|
|
|
this.address_part = arg;
|
|
|
|
} else if (arg instanceof StringList || arg instanceof Grammar.StringType) {
|
2021-01-15 18:34:16 +08:00
|
|
|
this[args[i+1] ? 'envelope_part' : 'key_list'] = arg;
|
|
|
|
// (args[i+1] ? this.envelope_part : this.key_list) = arg;
|
2021-01-15 07:32:04 +08:00
|
|
|
}
|
|
|
|
});
|
2021-01-14 04:23:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* https://tools.ietf.org/html/rfc5228#section-5.5
|
|
|
|
*/
|
2021-01-14 23:38:26 +08:00
|
|
|
class Exists extends Test
|
2021-01-14 04:23:19 +08:00
|
|
|
{
|
|
|
|
constructor()
|
|
|
|
{
|
2021-01-14 23:38:26 +08:00
|
|
|
super('exists');
|
|
|
|
this.header_names = new StringList;
|
2021-01-14 04:23:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
toString()
|
|
|
|
{
|
2021-01-14 23:38:26 +08:00
|
|
|
return 'exists ' + this.header_names;
|
2021-01-14 04:23:19 +08:00
|
|
|
}
|
|
|
|
|
2021-01-15 07:32:04 +08:00
|
|
|
pushArguments(args)
|
2021-01-14 04:23:19 +08:00
|
|
|
{
|
2021-01-15 07:32:04 +08:00
|
|
|
if (args[0] instanceof StringList) {
|
|
|
|
this.header_names = args;
|
|
|
|
} else if (args[0] instanceof Grammar.StringType) {
|
|
|
|
this.header_names.push(args[0].value);
|
|
|
|
}
|
2021-01-14 04:23:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* https://tools.ietf.org/html/rfc5228#section-5.6
|
|
|
|
*/
|
2021-01-14 23:38:26 +08:00
|
|
|
class False extends Test
|
2021-01-14 04:23:19 +08:00
|
|
|
{
|
|
|
|
toString()
|
|
|
|
{
|
|
|
|
return "false";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* https://tools.ietf.org/html/rfc5228#section-5.7
|
|
|
|
*/
|
2021-01-14 23:38:26 +08:00
|
|
|
class Header extends Test
|
2021-01-14 04:23:19 +08:00
|
|
|
{
|
|
|
|
constructor()
|
|
|
|
{
|
2021-01-14 23:38:26 +08:00
|
|
|
super('header');
|
2021-01-15 18:34:16 +08:00
|
|
|
this.comparator = '';
|
2021-01-14 04:23:19 +08:00
|
|
|
this.address_part = ':all'; // :localpart | :domain | :all
|
|
|
|
this.match_type = ':is';
|
2021-01-14 23:38:26 +08:00
|
|
|
this.header_names = new StringList;
|
|
|
|
this.key_list = new StringList;
|
2021-01-14 04:23:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
toString()
|
|
|
|
{
|
|
|
|
return 'header'
|
|
|
|
// + ' ' + this.comparator
|
|
|
|
+ ' ' + this.match_type
|
|
|
|
+ ' ' + this.header_names
|
|
|
|
+ ' ' + this.key_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
pushArguments(args)
|
|
|
|
{
|
|
|
|
args.forEach((arg, i) => {
|
2021-01-15 18:34:16 +08:00
|
|
|
if (':localpart' === arg || ':domain' === arg || ':all' === arg) {
|
2021-01-15 07:32:04 +08:00
|
|
|
this.address_part = arg;
|
2021-01-14 23:38:26 +08:00
|
|
|
} else if (arg instanceof StringList || arg instanceof Grammar.StringType) {
|
2021-01-15 18:34:16 +08:00
|
|
|
this[args[i+1] ? 'header_names' : 'key_list'] = arg;
|
|
|
|
// (args[i+1] ? this.header_names : this.key_list) = arg;
|
2021-01-14 04:23:19 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* https://tools.ietf.org/html/rfc5228#section-5.8
|
|
|
|
*/
|
2021-01-14 23:38:26 +08:00
|
|
|
class Not extends Test
|
2021-01-14 04:23:19 +08:00
|
|
|
{
|
|
|
|
constructor()
|
|
|
|
{
|
2021-01-14 23:38:26 +08:00
|
|
|
super('not');
|
|
|
|
this.test = new Test;
|
2021-01-14 04:23:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
toString()
|
|
|
|
{
|
|
|
|
return 'not ' + this.test;
|
|
|
|
}
|
|
|
|
|
2021-01-15 07:32:04 +08:00
|
|
|
pushArguments()
|
2021-01-14 04:23:19 +08:00
|
|
|
{
|
2021-01-15 07:32:04 +08:00
|
|
|
throw 'No arguments';
|
2021-01-14 04:23:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* https://tools.ietf.org/html/rfc5228#section-5.9
|
|
|
|
*/
|
2021-01-14 23:38:26 +08:00
|
|
|
class Size extends Test
|
2021-01-14 04:23:19 +08:00
|
|
|
{
|
|
|
|
constructor()
|
|
|
|
{
|
2021-01-14 23:38:26 +08:00
|
|
|
super('size');
|
2021-01-14 04:23:19 +08:00
|
|
|
this.mode = ':over'; // :under
|
|
|
|
this.limit = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
toString()
|
|
|
|
{
|
|
|
|
return 'size ' + this.mode + ' ' + this.limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
pushArguments(args)
|
|
|
|
{
|
|
|
|
args.forEach(arg => {
|
|
|
|
if (':over' === arg || ':under' === arg) {
|
|
|
|
this.mode = arg;
|
2021-01-14 23:38:26 +08:00
|
|
|
} else if (arg instanceof Grammar.Number) {
|
2021-01-14 04:23:19 +08:00
|
|
|
this.limit = arg;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-14 23:38:26 +08:00
|
|
|
/**
|
|
|
|
* https://tools.ietf.org/html/rfc5228#section-5.10
|
|
|
|
*/
|
|
|
|
class True extends Test
|
|
|
|
{
|
|
|
|
toString()
|
|
|
|
{
|
|
|
|
return 'true';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-15 06:42:46 +08:00
|
|
|
Object.assign(Sieve.Commands, {
|
|
|
|
address: Address,
|
|
|
|
allof: AllOf,
|
|
|
|
anyof: AnyOf,
|
|
|
|
envelope: Envelope,
|
|
|
|
exists: Exists,
|
|
|
|
false: False,
|
|
|
|
header: Header,
|
|
|
|
not: Not,
|
|
|
|
size: Size,
|
|
|
|
true: True
|
|
|
|
});
|
2021-01-14 04:23:19 +08:00
|
|
|
|
|
|
|
})(this.Sieve);
|