Improve sieve parser

This commit is contained in:
the-djmaze 2024-09-23 10:48:22 +02:00
parent 0a3a5f6d59
commit c773b852a1
11 changed files with 124 additions and 106 deletions

View file

@ -43,7 +43,6 @@ export class VacationCommand extends ActionCommand
}
if (this._from.length) {
result += ' :from ' + this._from;
// result += ' :from ' + this.arguments[':from'];
}
if (this.addresses.length) {
result += ' :addresses ' + this.addresses;

View file

@ -43,11 +43,12 @@ class FlagCommand extends ActionCommand
if (args[0] instanceof GrammarQuotedString) {
this._variablename = args[0];
}
if (args[1] instanceof GrammarString) {
this.list_of_flags = args[1];
}
} else if (args[0] instanceof GrammarString) {
args[0] = args[1];
}
if (args[0] instanceof GrammarStringList) {
this.list_of_flags = args[0];
} else if (args[0]) {
this.list_of_flags.push(args[0]);
}
}
}

View file

@ -8,11 +8,11 @@ import {
GrammarString
} from 'Sieve/Grammar';
class rfc5429Command extends ActionCommand
class /*abstract*/ rfc5429Command extends ActionCommand
{
constructor(identifier)
constructor()
{
super(identifier);
super();
this._reason = new GrammarQuotedString;
}
@ -44,7 +44,6 @@ class rfc5429Command extends ActionCommand
*/
export class ErejectCommand extends rfc5429Command
{
constructor() { super('ereject'); }
get require() { return 'ereject'; }
}
@ -53,6 +52,5 @@ export class ErejectCommand extends rfc5429Command
*/
export class RejectCommand extends rfc5429Command
{
constructor() { super('reject'); }
get require() { return 'reject'; }
}

View file

@ -5,6 +5,7 @@
import {
ActionCommand,
ControlCommand,
GrammarCommands,
GrammarNumber,
GrammarQuotedString,
GrammarString,
@ -20,6 +21,7 @@ export class ForEveryPartCommand extends ControlCommand
{
super();
this._name = new GrammarString;
this.commands = new GrammarCommands;
}
get require() { return 'foreverypart'; }
@ -27,7 +29,7 @@ export class ForEveryPartCommand extends ControlCommand
toString()
{
let result = 'foreverypart';
if (this._subject.length) {
if (this._name.length) {
result += ' :name ' + this._name;
}
return result + ' ' + this.commands;
@ -43,12 +45,15 @@ export class ForEveryPartCommand extends ControlCommand
}
}
/**
* Must be inside foreverypart
*/
export class BreakCommand extends ForEveryPartCommand
{
toString()
{
let result = 'break';
if (this._subject.length) {
if (this._name.length) {
result += ' :name ' + this._name;
}
return result + ';';
@ -82,7 +87,6 @@ export class ReplaceCommand extends ActionCommand
}
if (this._from.length) {
result += ' :from ' + this._from;
// result += ' :from ' + this.arguments[':from'];
}
return result + this.replacement + ';';
}
@ -140,6 +144,7 @@ export class EncloseCommand extends ActionCommand
/**
* https://datatracker.ietf.org/doc/html/rfc5703#section-7
* Should be inside foreverypart, else empty and flagged as a compilation error
*/
export class ExtractTextCommand extends ActionCommand
{