From 22964f1fde7ea4195330aecf5cbb57e69f96fcbf Mon Sep 17 00:00:00 2001 From: djmaze Date: Thu, 14 Jan 2021 17:50:23 +0100 Subject: [PATCH] More improvements and fixes based on test scripts --- dev/Sieve/Extensions/Body.js | 27 ++++++++++++-- dev/Sieve/Extensions/Ereject.js | 30 --------------- dev/Sieve/Extensions/Reject.js | 64 ++++++++++++++++++++++++++++---- dev/Sieve/Extensions/Vacation.js | 7 +++- dev/Sieve/Parser.js | 18 ++++++--- dev/Sieve/Tests.js | 4 +- 6 files changed, 100 insertions(+), 50 deletions(-) delete mode 100644 dev/Sieve/Extensions/Ereject.js diff --git a/dev/Sieve/Extensions/Body.js b/dev/Sieve/Extensions/Body.js index 3b33f065f..b8ae60123 100644 --- a/dev/Sieve/Extensions/Body.js +++ b/dev/Sieve/Extensions/Body.js @@ -4,14 +4,17 @@ (Sieve => { -Sieve.Extensions.Body = class +const Grammar = Sieve.Grammar; + +class Body extends Grammar.Test { constructor() { + super('body'); this.comparator = 'i;ascii-casemap', this.match_type = ':is', this.body_transform = ''; // :raw, :content , :text - this.key_list = new Sieve.Grammar.StringList; + this.key_list = new Grammar.StringList; } toString() @@ -22,7 +25,25 @@ Sieve.Extensions.Body = class + ' ' + this.body_transform + ' ' + 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); diff --git a/dev/Sieve/Extensions/Ereject.js b/dev/Sieve/Extensions/Ereject.js deleted file mode 100644 index 74b938889..000000000 --- a/dev/Sieve/Extensions/Ereject.js +++ /dev/null @@ -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); diff --git a/dev/Sieve/Extensions/Reject.js b/dev/Sieve/Extensions/Reject.js index fe6505068..061564161 100644 --- a/dev/Sieve/Extensions/Reject.js +++ b/dev/Sieve/Extensions/Reject.js @@ -1,30 +1,80 @@ /** - * https://tools.ietf.org/html/rfc5429#section-2.2 + * https://tools.ietf.org/html/rfc5429 */ (Sieve => { -Sieve.Extensions.Reject = class +const Grammar = Sieve.Grammar; + +/** + * https://tools.ietf.org/html/rfc5429#section-2.1 + */ +class Ereject extends Grammar.Command { constructor() { - this.reason = new Sieve.Grammar.QuotedString; + super('ereject'); + this._reason = new Grammar.QuotedString; } toString() { - return 'reject ' + this.reason; + return 'ereject ' + this._reason + ';'; } get reason() { - return this.reason.value; + return this._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); diff --git a/dev/Sieve/Extensions/Vacation.js b/dev/Sieve/Extensions/Vacation.js index 7129bbc00..b72c2969d 100644 --- a/dev/Sieve/Extensions/Vacation.js +++ b/dev/Sieve/Extensions/Vacation.js @@ -4,10 +4,11 @@ (Sieve => { -Sieve.Extensions.Vacation = class +class Vacation extends Sieve.Grammar.Command { constructor() { + super('vacation'); this.arguments = { ':days' : new Sieve.Grammar.Number, ':subject' : new Sieve.Grammar.QuotedString, @@ -79,6 +80,8 @@ Sieve.Extensions.Vacation = class } } */ -}; +} + +Sieve.Extensions.Vacation = Vacation; })(this.Sieve); diff --git a/dev/Sieve/Parser.js b/dev/Sieve/Parser.js index f5b75865a..6cb7a2f82 100644 --- a/dev/Sieve/Parser.js +++ b/dev/Sieve/Parser.js @@ -85,12 +85,10 @@ Sieve.parseScript = script => { if ('if' === value) { new_command = new Sieve.Commands.Conditional(value); } else if ('elsif' === value || 'else' === value) { - (command instanceof Sieve.Commands.Conditional) - || error('Not after IF condition'); +// (prev_command instanceof Sieve.Commands.Conditional) || error('Not after IF condition'); new_command = new Sieve.Commands.Conditional(value); } else if ('allof' === value || 'anyof' === value) { - (command instanceof Sieve.Commands.Conditional) - || error('Test-list not in conditional'); + (command instanceof Sieve.Commands.Conditional) || error('Test-list not in conditional'); new_command = new Sieve.Tests[className](); } else if (Sieve.Tests[className]) { // address / envelope / exists / header / not / size @@ -102,8 +100,15 @@ Sieve.parseScript = script => { // body / ereject / reject / imap4flags / vacation new_command = new Sieve.Extensions[className](); } else { - error('Unknown command ' + value); -// new_command = new Sieve.Grammar.Command(value); + console.error('Unknown 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) { @@ -198,6 +203,7 @@ Sieve.parseScript = script => { case T_BLOCK_END: (command instanceof Sieve.Commands.Conditional) || error('Block end has no matching block start'); levels.pop(); +// prev_command = command; command = levels.last(); break; diff --git a/dev/Sieve/Tests.js b/dev/Sieve/Tests.js index 311401ca3..16ace5089 100644 --- a/dev/Sieve/Tests.js +++ b/dev/Sieve/Tests.js @@ -238,8 +238,8 @@ class True extends Test Sieve.Tests = { Address: Address, - AllOf: AllOf, - AnyOf: AnyOf, + Allof: AllOf, + Anyof: AnyOf, Envelope: Envelope, Exists: Exists, False: False,