From 37bb9a9a9757f8eccee0649120cd2beff28263e8 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Wed, 16 Mar 2022 14:33:43 +0100 Subject: [PATCH] added Sieve getMatchTypes() for easy valid match-types --- dev/Sieve/Grammar.js | 8 ++------ dev/Sieve/Parser.js | 8 ++------ dev/Sieve/Utils.js | 9 +++++++++ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/dev/Sieve/Grammar.js b/dev/Sieve/Grammar.js index 102fb6cfa..e985b696a 100644 --- a/dev/Sieve/Grammar.js +++ b/dev/Sieve/Grammar.js @@ -9,9 +9,7 @@ import { MULTILINE_DOTSTART } from 'Sieve/RegEx'; -import { - arrayToString -} from 'Sieve/Utils'; +import { arrayToString, getMatchTypes } from 'Sieve/Utils'; /** * abstract @@ -240,12 +238,10 @@ export class GrammarTest toString() { -/* // https://datatracker.ietf.org/doc/html/rfc6134#section-2.3 - if (':list' == this.match_type && !capa.includes('extlists')) { + if (!getMatchTypes().includes(this.match_type)) { throw 'Unsupported match-type ' + this.match_type; } -*/ return (this.identifier + (this.comparator ? ' :comparator ' + this.comparator : '') + (this.match_type ? ' ' + this.match_type : '') diff --git a/dev/Sieve/Parser.js b/dev/Sieve/Parser.js index 0516fffa3..b4508cb81 100644 --- a/dev/Sieve/Parser.js +++ b/dev/Sieve/Parser.js @@ -2,7 +2,7 @@ * https://tools.ietf.org/html/rfc5228#section-8 */ -import { capa } from 'Sieve/Utils'; +import { capa, getMatchTypes } from 'Sieve/Utils'; import { BRACKET_COMMENT, @@ -213,11 +213,7 @@ export const parseScript = (script, name = 'script.sieve') => { pushArg = arg => { command || error('Argument not part of command'); let prev_arg = args[args.length-1]; -/* - // https://datatracker.ietf.org/doc/html/rfc6134#section-2.3 - if (':is' === arg || ':contains' === arg || ':matches' === arg || (capa.includes('extlists') && ':list')) { -*/ - if (':is' === arg || ':contains' === arg || ':matches' === arg) { + if (getMatchTypes(0).includes(arg)) { command.match_type = arg; } else if (':value' === prev_arg || ':count' === prev_arg) { // Sieve relational [RFC5231] match types diff --git a/dev/Sieve/Utils.js b/dev/Sieve/Utils.js index 9b71a4cd5..4002b9e15 100644 --- a/dev/Sieve/Utils.js +++ b/dev/Sieve/Utils.js @@ -56,4 +56,13 @@ export const setError = text => { serverError(true); serverErrorDesc(text); + }, + + getMatchTypes = (validOnly = 1) => { + let result = [':is',':contains',':matches']; + // https://datatracker.ietf.org/doc/html/rfc6134#section-2.3 + if (capa.includes('extlists') || !validOnly) { + result.push(':list'); + } + return result; };