Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit c773b85

Browse files
author
the-djmaze
committed
Improve sieve parser
1 parent 0a3a5f6 commit c773b85

File tree

11 files changed

+122
-104
lines changed

11 files changed

+122
-104
lines changed

dev/Sieve/Commands.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
} from 'Sieve/Commands/Actions';
1616

1717
import {
18-
ConditionalCommand,
1918
ElsIfCommand,
2019
ElseCommand,
2120
IfCommand,
@@ -67,7 +66,6 @@ export const
6766
IfCommand,
6867
ElsIfCommand,
6968
ElseCommand,
70-
ConditionalCommand,
7169
RequireCommand,
7270
StopCommand,
7371
// Action commands

dev/Sieve/Commands/Actions.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@ export class FileIntoCommand extends ActionCommand
2121
super();
2222
// QuotedString / MultiLine
2323
this._mailbox = new GrammarQuotedString();
24+
// https://datatracker.ietf.org/doc/html/rfc3894
25+
this.copy = false;
26+
// https://datatracker.ietf.org/doc/html/rfc5490#section-3.2
27+
this.create = false;
2428
}
2529

2630
get require() { return 'fileinto'; }
2731

2832
toString()
2933
{
3034
return 'fileinto'
31-
// https://datatracker.ietf.org/doc/html/rfc3894
3235
+ ((this.copy && capa.includes('copy')) ? ' :copy' : '')
33-
// https://datatracker.ietf.org/doc/html/rfc5490#section-3.2
3436
+ ((this.create && capa.includes('mailbox')) ? ' :create' : '')
3537
+ ' ' + this._mailbox
3638
+ ';';
@@ -64,15 +66,17 @@ export class RedirectCommand extends ActionCommand
6466
super();
6567
// QuotedString / MultiLine
6668
this._address = new GrammarQuotedString();
69+
// https://datatracker.ietf.org/doc/html/rfc3894
70+
this.copy = false;
71+
// https://datatracker.ietf.org/doc/html/rfc6134#section-2.3
72+
this.list = null;
6773
}
6874

6975
toString()
7076
{
7177

7278
return 'redirect'
73-
// https://datatracker.ietf.org/doc/html/rfc6134#section-2.3
7479
// + ((this.list && capa.includes('extlists')) ? ' :list ' + this.list : '')
75-
// https://datatracker.ietf.org/doc/html/rfc3894
7680
+ ((this.copy && capa.includes('copy')) ? ' :copy' : '')
7781
+ ' ' + this._address
7882
+ ';';

dev/Sieve/Commands/Controls.js

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import {
77
ControlCommand,
8+
GrammarCommands,
89
GrammarStringList,
910
GrammarQuotedString
1011
} from 'Sieve/Grammar';
@@ -16,37 +17,55 @@ import {
1617
* elsif <test2: test> <block2: block>
1718
* else <block3: block>
1819
*/
19-
export class ConditionalCommand extends ControlCommand
20+
export /*abstract*/ class ConditionalCommand extends ControlCommand
2021
{
21-
constructor(identifier)
22+
constructor()
2223
{
23-
super(identifier);
24-
this.test = null;
24+
/*
25+
if (this.constructor == ConditionalCommand) {
26+
throw Error("Abstract class can't be instantiated.");
27+
}
28+
*/
29+
super();
30+
this.commands = new GrammarCommands;
2531
}
32+
}
2633

27-
toString()
34+
export class IfCommand extends ConditionalCommand
35+
{
36+
constructor()
2837
{
29-
return this.identifier + ' ' + this.test + ' ' + this.commands;
38+
super();
39+
this._test = null; // must be descendent instanceof TestCommand
3040
}
31-
/*
32-
public function pushArguments(array $args): void
41+
42+
get test()
3343
{
34-
args.forEach((arg, i) => {
35-
if (i && ':' === args[i-1][0]) {
36-
this[args[i-1].replace(':','_')].value = arg.value;
37-
}
38-
});
39-
print_r($args);
40-
exit;
44+
return this._test;
4145
}
46+
47+
set test(value)
48+
{
49+
/*
50+
if (!value instanceof TestCommand) {
51+
throw Error("test must be descendent instanceof TestCommand.");
52+
}
4253
*/
43-
}
54+
this._test = value;
55+
}
4456

45-
export class IfCommand extends ConditionalCommand
46-
{
57+
toString()
58+
{
59+
/*
60+
if (!this._test instanceof TestCommand) {
61+
throw Error("test must be descendent instanceof TestCommand.");
62+
}
63+
*/
64+
return this.identifier + ' ' + this._test + ' ' + this.commands;
65+
}
4766
}
4867

49-
export class ElsIfCommand extends ConditionalCommand
68+
export class ElsIfCommand extends IfCommand
5069
{
5170
}
5271

dev/Sieve/Commands/Tests.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ export class HeaderTest extends TestCommand
230230
constructor()
231231
{
232232
super();
233+
this.match_type = ':is';
233234
this.address_part = ':all';
234235
this.header_names = new GrammarStringList;
235236
this.key_list = new GrammarStringList;
@@ -316,11 +317,6 @@ export class NotTest extends TestCommand
316317
{
317318
return 'not ' + this.test;
318319
}
319-
320-
pushArguments()
321-
{
322-
throw 'No arguments';
323-
}
324320
}
325321

326322
/**

dev/Sieve/Extensions/rfc5230.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export class VacationCommand extends ActionCommand
4343
}
4444
if (this._from.length) {
4545
result += ' :from ' + this._from;
46-
// result += ' :from ' + this.arguments[':from'];
4746
}
4847
if (this.addresses.length) {
4948
result += ' :addresses ' + this.addresses;

dev/Sieve/Extensions/rfc5232.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ class FlagCommand extends ActionCommand
4343
if (args[0] instanceof GrammarQuotedString) {
4444
this._variablename = args[0];
4545
}
46-
if (args[1] instanceof GrammarString) {
47-
this.list_of_flags = args[1];
48-
}
49-
} else if (args[0] instanceof GrammarString) {
46+
args[0] = args[1];
47+
}
48+
if (args[0] instanceof GrammarStringList) {
5049
this.list_of_flags = args[0];
50+
} else if (args[0]) {
51+
this.list_of_flags.push(args[0]);
5152
}
5253
}
5354
}

dev/Sieve/Extensions/rfc5429.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import {
88
GrammarString
99
} from 'Sieve/Grammar';
1010

11-
class rfc5429Command extends ActionCommand
11+
class /*abstract*/ rfc5429Command extends ActionCommand
1212
{
13-
constructor(identifier)
13+
constructor()
1414
{
15-
super(identifier);
15+
super();
1616
this._reason = new GrammarQuotedString;
1717
}
1818

@@ -44,7 +44,6 @@ class rfc5429Command extends ActionCommand
4444
*/
4545
export class ErejectCommand extends rfc5429Command
4646
{
47-
constructor() { super('ereject'); }
4847
get require() { return 'ereject'; }
4948
}
5049

@@ -53,6 +52,5 @@ export class ErejectCommand extends rfc5429Command
5352
*/
5453
export class RejectCommand extends rfc5429Command
5554
{
56-
constructor() { super('reject'); }
5755
get require() { return 'reject'; }
5856
}

dev/Sieve/Extensions/rfc5703.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import {
66
ActionCommand,
77
ControlCommand,
8+
GrammarCommands,
89
GrammarNumber,
910
GrammarQuotedString,
1011
GrammarString,
@@ -20,14 +21,15 @@ export class ForEveryPartCommand extends ControlCommand
2021
{
2122
super();
2223
this._name = new GrammarString;
24+
this.commands = new GrammarCommands;
2325
}
2426

2527
get require() { return 'foreverypart'; }
2628

2729
toString()
2830
{
2931
let result = 'foreverypart';
30-
if (this._subject.length) {
32+
if (this._name.length) {
3133
result += ' :name ' + this._name;
3234
}
3335
return result + ' ' + this.commands;
@@ -43,12 +45,15 @@ export class ForEveryPartCommand extends ControlCommand
4345
}
4446
}
4547

48+
/**
49+
* Must be inside foreverypart
50+
*/
4651
export class BreakCommand extends ForEveryPartCommand
4752
{
4853
toString()
4954
{
5055
let result = 'break';
51-
if (this._subject.length) {
56+
if (this._name.length) {
5257
result += ' :name ' + this._name;
5358
}
5459
return result + ';';
@@ -82,7 +87,6 @@ export class ReplaceCommand extends ActionCommand
8287
}
8388
if (this._from.length) {
8489
result += ' :from ' + this._from;
85-
// result += ' :from ' + this.arguments[':from'];
8690
}
8791
return result + this.replacement + ';';
8892
}
@@ -140,6 +144,7 @@ export class EncloseCommand extends ActionCommand
140144

141145
/**
142146
* https://datatracker.ietf.org/doc/html/rfc5703#section-7
147+
* Should be inside foreverypart, else empty and flagged as a compilation error
143148
*/
144149
export class ExtractTextCommand extends ActionCommand
145150
{

0 commit comments

Comments
 (0)