mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-11-15 12:15:20 +08:00
68fc9f21bd
Improved parser error handling Fix Sieve Vacation extension
272 lines
4.7 KiB
JavaScript
272 lines
4.7 KiB
JavaScript
/**
|
|
* https://tools.ietf.org/html/rfc5228#section-5
|
|
*/
|
|
|
|
(Sieve => {
|
|
|
|
const Grammar = Sieve.Grammar,
|
|
Test = Grammar.Test,
|
|
StringList = Grammar.StringList;
|
|
|
|
/**
|
|
* https://tools.ietf.org/html/rfc5228#section-5.1
|
|
*/
|
|
class Address extends Test
|
|
{
|
|
constructor()
|
|
{
|
|
super('address');
|
|
this.comparator = '';
|
|
this.address_part = ':all'; // :localpart | :domain | :all
|
|
this.match_type = ':is';
|
|
this.header_list = new StringList;
|
|
this.key_list = new StringList;
|
|
}
|
|
|
|
toString()
|
|
{
|
|
return 'address'
|
|
// + ' ' + this.comparator
|
|
+ ' ' + this.address_part
|
|
+ ' ' + this.match_type
|
|
+ ' ' + this.header_list
|
|
+ ' ' + this.key_list;
|
|
}
|
|
|
|
pushArguments(args)
|
|
{
|
|
args.forEach((arg, i) => {
|
|
if (':localpart' === arg || ':domain' === arg || ':all' === arg) {
|
|
this.address_part = arg;
|
|
} else if (arg instanceof StringList || arg instanceof Grammar.StringType) {
|
|
this[args[i+1] ? 'header_list' : 'key_list'] = arg;
|
|
// (args[i+1] ? this.header_list : this.key_list) = arg;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* https://tools.ietf.org/html/rfc5228#section-5.2
|
|
*/
|
|
class AllOf extends Test
|
|
{
|
|
constructor()
|
|
{
|
|
super('allof');
|
|
this.tests = new Grammar.TestList;
|
|
}
|
|
|
|
toString()
|
|
{
|
|
return 'allof ' + this.tests;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* https://tools.ietf.org/html/rfc5228#section-5.3
|
|
*/
|
|
class AnyOf extends Test
|
|
{
|
|
constructor()
|
|
{
|
|
super('anyof');
|
|
this.tests = new Grammar.TestList;
|
|
}
|
|
|
|
toString()
|
|
{
|
|
return 'anyof ' + this.tests;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* https://tools.ietf.org/html/rfc5228#section-5.4
|
|
*/
|
|
class Envelope extends Test
|
|
{
|
|
constructor()
|
|
{
|
|
super('envelope');
|
|
this.comparator = '';
|
|
this.address_part = ':all'; // :localpart | :domain | :all
|
|
this.match_type = ':is';
|
|
this.envelope_part = new StringList;
|
|
this.key_list = new StringList;
|
|
}
|
|
|
|
get require() { return 'envelope'; }
|
|
|
|
toString()
|
|
{
|
|
return 'envelope'
|
|
// + ' ' + this.comparator
|
|
+ ' ' + this.address_part
|
|
+ ' ' + this.match_type
|
|
+ ' ' + this.envelope_part
|
|
+ ' ' + this.key_list;
|
|
}
|
|
|
|
pushArguments(args)
|
|
{
|
|
args.forEach((arg, i) => {
|
|
if (':localpart' === arg || ':domain' === arg || ':all' === arg) {
|
|
this.address_part = arg;
|
|
} else if (arg instanceof StringList || arg instanceof Grammar.StringType) {
|
|
this[args[i+1] ? 'envelope_part' : 'key_list'] = arg;
|
|
// (args[i+1] ? this.envelope_part : this.key_list) = arg;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* https://tools.ietf.org/html/rfc5228#section-5.5
|
|
*/
|
|
class Exists extends Test
|
|
{
|
|
constructor()
|
|
{
|
|
super('exists');
|
|
this.header_names = new StringList;
|
|
}
|
|
|
|
toString()
|
|
{
|
|
return 'exists ' + this.header_names;
|
|
}
|
|
|
|
pushArguments(args)
|
|
{
|
|
if (args[0] instanceof StringList) {
|
|
this.header_names = args;
|
|
} else if (args[0] instanceof Grammar.StringType) {
|
|
this.header_names.push(args[0].value);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* https://tools.ietf.org/html/rfc5228#section-5.6
|
|
*/
|
|
class False extends Test
|
|
{
|
|
toString()
|
|
{
|
|
return "false";
|
|
}
|
|
}
|
|
|
|
/**
|
|
* https://tools.ietf.org/html/rfc5228#section-5.7
|
|
*/
|
|
class Header extends Test
|
|
{
|
|
constructor()
|
|
{
|
|
super('header');
|
|
this.comparator = '';
|
|
this.address_part = ':all'; // :localpart | :domain | :all
|
|
this.match_type = ':is';
|
|
this.header_names = new StringList;
|
|
this.key_list = new StringList;
|
|
}
|
|
|
|
toString()
|
|
{
|
|
return 'header'
|
|
// + ' ' + this.comparator
|
|
+ ' ' + this.match_type
|
|
+ ' ' + this.header_names
|
|
+ ' ' + this.key_list;
|
|
}
|
|
|
|
pushArguments(args)
|
|
{
|
|
args.forEach((arg, i) => {
|
|
if (':localpart' === arg || ':domain' === arg || ':all' === arg) {
|
|
this.address_part = arg;
|
|
} else if (arg instanceof StringList || arg instanceof Grammar.StringType) {
|
|
this[args[i+1] ? 'header_names' : 'key_list'] = arg;
|
|
// (args[i+1] ? this.header_names : this.key_list) = arg;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* https://tools.ietf.org/html/rfc5228#section-5.8
|
|
*/
|
|
class Not extends Test
|
|
{
|
|
constructor()
|
|
{
|
|
super('not');
|
|
this.test = new Test;
|
|
}
|
|
|
|
toString()
|
|
{
|
|
return 'not ' + this.test;
|
|
}
|
|
|
|
pushArguments()
|
|
{
|
|
throw 'No arguments';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* https://tools.ietf.org/html/rfc5228#section-5.9
|
|
*/
|
|
class Size extends Test
|
|
{
|
|
constructor()
|
|
{
|
|
super('size');
|
|
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;
|
|
} else if (arg instanceof Grammar.Number) {
|
|
this.limit = arg;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* https://tools.ietf.org/html/rfc5228#section-5.10
|
|
*/
|
|
class True extends Test
|
|
{
|
|
toString()
|
|
{
|
|
return 'true';
|
|
}
|
|
}
|
|
|
|
Object.assign(Sieve.Commands, {
|
|
address: Address,
|
|
allof: AllOf,
|
|
anyof: AnyOf,
|
|
envelope: Envelope,
|
|
exists: Exists,
|
|
false: False,
|
|
header: Header,
|
|
not: Not,
|
|
size: Size,
|
|
true: True
|
|
});
|
|
|
|
})(this.Sieve);
|