diff --git a/dev/Sieve/Commands.js b/dev/Sieve/Commands.js index 941b4e409..e2c59e5fa 100644 --- a/dev/Sieve/Commands.js +++ b/dev/Sieve/Commands.js @@ -48,6 +48,7 @@ import { NotifyCommand, ValidNotifyMethodTest, NotifyMethodCapabilityTest } from import { IHaveTest, ErrorCommand } from 'Sieve/Extensions/rfc5463'; import { MailboxExistsTest, MetadataTest, MetadataExistsTest } from 'Sieve/Extensions/rfc5490'; import { ForEveryPartCommand, BreakCommand, ReplaceCommand, EncloseCommand, ExtractTextCommand } from 'Sieve/Extensions/rfc5703'; +import { ValidExtListTest } from 'Sieve/Extensions/rfc6134'; import { IncludeCommand, ReturnCommand, GlobalCommand } from 'Sieve/Extensions/rfc6609'; export const @@ -127,6 +128,8 @@ export const ReplaceCommand, EncloseCommand, ExtractTextCommand, + // rfc6134 + ValidExtListTest, // rfc6609 IncludeCommand, ReturnCommand, @@ -144,6 +147,17 @@ export const return commands; }, + unavailableCommands = () => { + let commands = {}; + AllCommands.forEach(cmd => { + const obj = new cmd, requires = obj.require; + if (requires && !(Array.isArray(requires) ? requires : [requires]).every(string => capa.includes(string))) { + commands[obj.identifier] = cmd; + } + }); + return commands; + }, + availableActions = () => { let actions = {}, id; AllCommands.forEach(cmd => { diff --git a/dev/Sieve/Extensions/rfc5230.js b/dev/Sieve/Extensions/rfc5230.js index e1a552c32..a5937a3bd 100644 --- a/dev/Sieve/Extensions/rfc5230.js +++ b/dev/Sieve/Extensions/rfc5230.js @@ -80,7 +80,8 @@ export class VacationCommand extends ActionCommand this.addresses = arg; // GrammarStringList } else if (i && ':' === args[i-1][0]) { // :days, :seconds, :subject, :from, :handle - this[args[i-1].replace(':','_')].value = arg.value; + let p = args[i-1].replace(':','_'); + this[p] ? (this[p].value = arg.value) : console.log('Unknown VacationCommand :' + p); } }); } diff --git a/dev/Sieve/Extensions/rfc5235.js b/dev/Sieve/Extensions/rfc5235.js index bfec1bb57..1c8bc46b2 100644 --- a/dev/Sieve/Extensions/rfc5235.js +++ b/dev/Sieve/Extensions/rfc5235.js @@ -51,7 +51,7 @@ export class VirusTestTest extends TestCommand this._value = new GrammarQuotedString; // 1 - 5 } - get require() { return /:value|:count/.test(this.match_type) ? ['virustest','relational'] : 'virustest'; } + get require() { return /:value/.test(this.match_type) ? ['virustest','relational'] : 'virustest'; } get value() { return this._value.value; } set value(v) { this._value.value = v; } diff --git a/dev/Sieve/Extensions/rfc5435.js b/dev/Sieve/Extensions/rfc5435.js index 3595ee502..9bee9fdb6 100644 --- a/dev/Sieve/Extensions/rfc5435.js +++ b/dev/Sieve/Extensions/rfc5435.js @@ -65,7 +65,8 @@ export class NotifyCommand extends ActionCommand this.options = arg; // GrammarStringList } else if (i && ':' === args[i-1][0]) { // :from, :importance, :message - this[args[i-1].replace(':','_')].value = arg.value; + let p = args[i-1].replace(':','_'); + this[p] ? (this[p].value = arg.value) : console.log('Unknown VacationCommand :' + p); } }); } diff --git a/dev/Sieve/Extensions/rfc5703.js b/dev/Sieve/Extensions/rfc5703.js index 46302018d..552e04c2f 100644 --- a/dev/Sieve/Extensions/rfc5703.js +++ b/dev/Sieve/Extensions/rfc5703.js @@ -108,7 +108,8 @@ export class ReplaceCommand extends ActionCommand this.mime = true; } else if (i && ':' === args[i-1][0]) { // :subject, :from - this[args[i-1].replace(':','_')].value = arg.value; + let p = args[i-1].replace(':','_'); + this[p] ? (this[p].value = arg.value) : console.log('Unknown VacationCommand :' + p); } }); } @@ -148,7 +149,8 @@ export class EncloseCommand extends ActionCommand args.forEach((arg, i) => { if (i && ':' === args[i-1][0]) { // :subject, :headers - this[args[i-1].replace(':','_')].value = arg.value; + let p = args[i-1].replace(':','_'); + this[p] ? (this[p].value = arg.value) : console.log('Unknown VacationCommand :' + p); } }); } diff --git a/dev/Sieve/Extensions/rfc6134.js b/dev/Sieve/Extensions/rfc6134.js index 872938eab..1bdb7c8b0 100644 --- a/dev/Sieve/Extensions/rfc6134.js +++ b/dev/Sieve/Extensions/rfc6134.js @@ -14,7 +14,7 @@ export class ValidExtListTest extends TestCommand { constructor() { - super(); + super('valid_ext_list'); this.ext_list_names = new GrammarStringList; } diff --git a/dev/Sieve/Parser.js b/dev/Sieve/Parser.js index 64364cf95..8ef1dacc3 100644 --- a/dev/Sieve/Parser.js +++ b/dev/Sieve/Parser.js @@ -28,7 +28,7 @@ import { GrammarTestList } from 'Sieve/Grammar'; -import { availableCommands } from 'Sieve/Commands'; +import { availableCommands, unavailableCommands } from 'Sieve/Commands'; import { ConditionalCommand, IfCommand, RequireCommand } from 'Sieve/Commands/Controls'; import { NotTest } from 'Sieve/Commands/Tests'; @@ -93,6 +93,7 @@ export const parseScript = (script, name = 'script.sieve') => { // Only activate available commands const Commands = availableCommands(); + const disabledCommands = unavailableCommands(); let match, line = 1, @@ -173,17 +174,12 @@ export const parseScript = (script, name = 'script.sieve') => { // (command instanceof ConditionalCommand || command instanceof NotTest) || error('Test-list not in conditional'); } new_command = new Commands[value](); + } else if (disabledCommands[value]) { + console.error('Unsupported command: ' + value); + new_command = new disabledCommands[value](); } else { - if (command && ( - command instanceof ConditionalCommand - || command instanceof NotTest - || command.tests instanceof GrammarTestList)) { - console.error('Unknown test: ' + value); - new_command = new TestCommand(value); - } else { - console.error('Unknown command: ' + value); - new_command = new GrammarCommand(value); - } + console.error('Unknown command: ' + value); + new_command = new GrammarCommand(value); } if (new_command instanceof TestCommand) { @@ -201,7 +197,7 @@ export const parseScript = (script, name = 'script.sieve') => { if (command.commands) { command.commands.push(new_command); } else { - error('commands not allowed in "' + command.identifier + '" command'); + error('command "' + new_command.identifier + '" not allowed in "' + command.identifier + '" command'); } } else { tree.push(new_command);