More improvements and fixes based on test scripts

This commit is contained in:
djmaze 2021-01-14 17:50:23 +01:00
parent 0aafce4214
commit 22964f1fde
6 changed files with 100 additions and 50 deletions

View file

@ -4,14 +4,17 @@
(Sieve => { (Sieve => {
Sieve.Extensions.Body = class const Grammar = Sieve.Grammar;
class Body extends Grammar.Test
{ {
constructor() constructor()
{ {
super('body');
this.comparator = 'i;ascii-casemap', this.comparator = 'i;ascii-casemap',
this.match_type = ':is', this.match_type = ':is',
this.body_transform = ''; // :raw, :content <string-list>, :text this.body_transform = ''; // :raw, :content <string-list>, :text
this.key_list = new Sieve.Grammar.StringList; this.key_list = new Grammar.StringList;
} }
toString() toString()
@ -22,7 +25,25 @@ Sieve.Extensions.Body = class
+ ' ' + this.body_transform + ' ' + this.body_transform
+ ' ' + this.key_list; + ' ' + this.key_list;
} }
};
pushArguments(args)
{
args.forEach((arg, i) => {
if (':is' === arg || ':contains' === arg || ':matches' === arg) {
this.match_type = arg;
} else if (':raw' === arg || ':text' === arg) {
this.body_transform = arg;
} else if (':content' === arg) {
// string-list
} else if (arg instanceof Grammar.StringList || arg instanceof Grammar.StringType) {
this[args[i+1] ? 'content_list' : 'key_list'] = arg;
}
});
}
}
Sieve.Extensions.Body = Body;
})(this.Sieve); })(this.Sieve);

View file

@ -1,30 +0,0 @@
/**
* https://tools.ietf.org/html/rfc5429#section-2.1
*/
(Sieve => {
Sieve.Extensions.Ereject = class
{
constructor()
{
this.reason = new Sieve.Grammar.QuotedString;
}
toString()
{
return 'ereject ' + this.reason;
}
get reason()
{
return this.reason.value;
}
set reason(value)
{
this.reason.value = value;
}
};
})(this.Sieve);

View file

@ -1,30 +1,80 @@
/** /**
* https://tools.ietf.org/html/rfc5429#section-2.2 * https://tools.ietf.org/html/rfc5429
*/ */
(Sieve => { (Sieve => {
Sieve.Extensions.Reject = class const Grammar = Sieve.Grammar;
/**
* https://tools.ietf.org/html/rfc5429#section-2.1
*/
class Ereject extends Grammar.Command
{ {
constructor() constructor()
{ {
this.reason = new Sieve.Grammar.QuotedString; super('ereject');
this._reason = new Grammar.QuotedString;
} }
toString() toString()
{ {
return 'reject ' + this.reason; return 'ereject ' + this._reason + ';';
} }
get reason() get reason()
{ {
return this.reason.value; return this._reason.value;
} }
set reason(value) set reason(value)
{ {
this.reason.value = value; this._reason.value = value;
} }
};
pushArguments(args)
{
if (args[0] instanceof Grammar.StringType) {
this._reason = args[0];
}
}
}
/**
* https://tools.ietf.org/html/rfc5429#section-2.2
*/
class Reject extends Grammar.Command
{
constructor()
{
super('reject');
this._reason = new Grammar.QuotedString;
}
toString()
{
return 'reject ' + this._reason + ';';
}
get reason()
{
return this._reason.value;
}
set reason(value)
{
this._reason.value = value;
}
pushArguments(args)
{
if (args[0] instanceof Grammar.StringType) {
this._reason = args[0];
}
}
}
Sieve.Extensions.Ereject = Ereject;
Sieve.Extensions.Reject = Reject;
})(this.Sieve); })(this.Sieve);

View file

@ -4,10 +4,11 @@
(Sieve => { (Sieve => {
Sieve.Extensions.Vacation = class class Vacation extends Sieve.Grammar.Command
{ {
constructor() constructor()
{ {
super('vacation');
this.arguments = { this.arguments = {
':days' : new Sieve.Grammar.Number, ':days' : new Sieve.Grammar.Number,
':subject' : new Sieve.Grammar.QuotedString, ':subject' : new Sieve.Grammar.QuotedString,
@ -79,6 +80,8 @@ Sieve.Extensions.Vacation = class
} }
} }
*/ */
}; }
Sieve.Extensions.Vacation = Vacation;
})(this.Sieve); })(this.Sieve);

View file

@ -85,12 +85,10 @@ Sieve.parseScript = script => {
if ('if' === value) { if ('if' === value) {
new_command = new Sieve.Commands.Conditional(value); new_command = new Sieve.Commands.Conditional(value);
} else if ('elsif' === value || 'else' === value) { } else if ('elsif' === value || 'else' === value) {
(command instanceof Sieve.Commands.Conditional) // (prev_command instanceof Sieve.Commands.Conditional) || error('Not after IF condition');
|| error('Not after IF condition');
new_command = new Sieve.Commands.Conditional(value); new_command = new Sieve.Commands.Conditional(value);
} else if ('allof' === value || 'anyof' === value) { } else if ('allof' === value || 'anyof' === value) {
(command instanceof Sieve.Commands.Conditional) (command instanceof Sieve.Commands.Conditional) || error('Test-list not in conditional');
|| error('Test-list not in conditional');
new_command = new Sieve.Tests[className](); new_command = new Sieve.Tests[className]();
} else if (Sieve.Tests[className]) { } else if (Sieve.Tests[className]) {
// address / envelope / exists / header / not / size // address / envelope / exists / header / not / size
@ -102,8 +100,15 @@ Sieve.parseScript = script => {
// body / ereject / reject / imap4flags / vacation // body / ereject / reject / imap4flags / vacation
new_command = new Sieve.Extensions[className](); new_command = new Sieve.Extensions[className]();
} else { } else {
error('Unknown command ' + value); console.error('Unknown command: ' + value);
// new_command = new Sieve.Grammar.Command(value); if (command && (
command instanceof Sieve.Commands.Conditional
|| command instanceof Sieve.Tests.Not
|| command.tests instanceof Sieve.Grammar.TestList)) {
new_command = new Sieve.Grammar.Test(value);
} else {
new_command = new Sieve.Grammar.Command(value);
}
} }
if (new_command instanceof Sieve.Grammar.Test) { if (new_command instanceof Sieve.Grammar.Test) {
@ -198,6 +203,7 @@ Sieve.parseScript = script => {
case T_BLOCK_END: case T_BLOCK_END:
(command instanceof Sieve.Commands.Conditional) || error('Block end has no matching block start'); (command instanceof Sieve.Commands.Conditional) || error('Block end has no matching block start');
levels.pop(); levels.pop();
// prev_command = command;
command = levels.last(); command = levels.last();
break; break;

View file

@ -238,8 +238,8 @@ class True extends Test
Sieve.Tests = { Sieve.Tests = {
Address: Address, Address: Address,
AllOf: AllOf, Allof: AllOf,
AnyOf: AnyOf, Anyof: AnyOf,
Envelope: Envelope, Envelope: Envelope,
Exists: Exists, Exists: Exists,
False: False, False: False,