From 219589b8ea34a2b81625f42e4cd889ffa976292c Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Mon, 14 Mar 2022 14:06:28 +0100 Subject: [PATCH] Support Sieve RFC3894 --- dev/Sieve/Commands.js | 22 ++++++++++++------- dev/Sieve/Parser.js | 15 ++++++++++++- dev/Sieve/README.md | 2 +- .../Views/User/PopupsSieveScript.html | 2 +- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/dev/Sieve/Commands.js b/dev/Sieve/Commands.js index 49a2dabfa..4f701d45d 100644 --- a/dev/Sieve/Commands.js +++ b/dev/Sieve/Commands.js @@ -2,6 +2,8 @@ * https://tools.ietf.org/html/rfc5228#section-2.9 */ +import { capa } from 'Sieve/Utils'; + import { GrammarCommand, GrammarString, @@ -102,11 +104,13 @@ export class FileIntoCommand extends GrammarCommand toString() { - // https://datatracker.ietf.org/doc/html/rfc3894 - // :copy - // https://datatracker.ietf.org/doc/html/rfc5490#section-3.2 - // :create - return 'fileinto ' + this._mailbox + ';'; + return 'fileinto ' + // https://datatracker.ietf.org/doc/html/rfc3894 + + ((this.copy && capa.includes('copy')) ? ':copy ' : '') + // https://datatracker.ietf.org/doc/html/rfc5490#section-3.2 + + ((this.create && capa.includes('mailbox')) ? ':create ' : '') + + this._mailbox + + ';'; } get mailbox() @@ -141,9 +145,11 @@ export class RedirectCommand extends GrammarCommand toString() { - // https://datatracker.ietf.org/doc/html/rfc3894 - // :copy - return 'redirect ' + this._address + ';'; + return 'redirect ' + // https://datatracker.ietf.org/doc/html/rfc3894 + + ((this.copy && capa.includes('copy')) ? ':copy ' : '') + + this._address + + ';'; } get address() diff --git a/dev/Sieve/Parser.js b/dev/Sieve/Parser.js index 92e705d25..4a650b2ec 100644 --- a/dev/Sieve/Parser.js +++ b/dev/Sieve/Parser.js @@ -2,6 +2,8 @@ * https://tools.ietf.org/html/rfc5228#section-8 */ +import { capa, forEachObjectEntry } from 'Sieve/Utils'; + import { BRACKET_COMMENT, HASH_COMMENT, @@ -84,7 +86,7 @@ import { } from 'Sieve/Extensions/rfc6609'; const - Commands = { + AllCommands = { // Control commands if: IfCommand, elsif: ElsIfCommand, @@ -182,6 +184,17 @@ const export const parseScript = (script, name = 'script.sieve') => { script = script.replace(/\r?\n/g, '\r\n'); + // Only activate available commands + const Commands = {}; + forEachObjectEntry(AllCommands, (key, cmd) => { + const requires = (new cmd).require; + if (!requires + || (Array.isArray(requires) ? requires : [requires]).every(string => capa.includes(string)) + ) { + Commands[key] = cmd; + } + }); + let match, line = 1, tree = [], diff --git a/dev/Sieve/README.md b/dev/Sieve/README.md index 2e7e4946c..effb8ce32 100644 --- a/dev/Sieve/README.md +++ b/dev/Sieve/README.md @@ -2,7 +2,7 @@ https://www.iana.org/assignments/sieve-extensions/sieve-extensions.xhtml - [ ] RFC2852 envelope-deliverby / redirect-deliverby - [ ] RFC3461 envelope-dsn / redirect-dsn -- [ ] RFC3894 copy +- [x] RFC3894 copy - [ ] RFC4790 comparator-* - [x] RFC5173 body - [x] RFC5183 environment diff --git a/snappymail/v/0.0.0/app/templates/Views/User/PopupsSieveScript.html b/snappymail/v/0.0.0/app/templates/Views/User/PopupsSieveScript.html index 821017588..58a4f3ab8 100644 --- a/snappymail/v/0.0.0/app/templates/Views/User/PopupsSieveScript.html +++ b/snappymail/v/0.0.0/app/templates/Views/User/PopupsSieveScript.html @@ -25,7 +25,7 @@ : - +