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

Commit 4022d39

Browse files
author
the-djmaze
committed
Some Sieve parser improvements
1 parent 61c2eef commit 4022d39

File tree

7 files changed

+32
-18
lines changed

7 files changed

+32
-18
lines changed

dev/Sieve/Commands.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { NotifyCommand, ValidNotifyMethodTest, NotifyMethodCapabilityTest } from
4848
import { IHaveTest, ErrorCommand } from 'Sieve/Extensions/rfc5463';
4949
import { MailboxExistsTest, MetadataTest, MetadataExistsTest } from 'Sieve/Extensions/rfc5490';
5050
import { ForEveryPartCommand, BreakCommand, ReplaceCommand, EncloseCommand, ExtractTextCommand } from 'Sieve/Extensions/rfc5703';
51+
import { ValidExtListTest } from 'Sieve/Extensions/rfc6134';
5152
import { IncludeCommand, ReturnCommand, GlobalCommand } from 'Sieve/Extensions/rfc6609';
5253

5354
export const
@@ -127,6 +128,8 @@ export const
127128
ReplaceCommand,
128129
EncloseCommand,
129130
ExtractTextCommand,
131+
// rfc6134
132+
ValidExtListTest,
130133
// rfc6609
131134
IncludeCommand,
132135
ReturnCommand,
@@ -144,6 +147,17 @@ export const
144147
return commands;
145148
},
146149

150+
unavailableCommands = () => {
151+
let commands = {};
152+
AllCommands.forEach(cmd => {
153+
const obj = new cmd, requires = obj.require;
154+
if (requires && !(Array.isArray(requires) ? requires : [requires]).every(string => capa.includes(string))) {
155+
commands[obj.identifier] = cmd;
156+
}
157+
});
158+
return commands;
159+
},
160+
147161
availableActions = () => {
148162
let actions = {}, id;
149163
AllCommands.forEach(cmd => {

dev/Sieve/Extensions/rfc5230.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ export class VacationCommand extends ActionCommand
8080
this.addresses = arg; // GrammarStringList
8181
} else if (i && ':' === args[i-1][0]) {
8282
// :days, :seconds, :subject, :from, :handle
83-
this[args[i-1].replace(':','_')].value = arg.value;
83+
let p = args[i-1].replace(':','_');
84+
this[p] ? (this[p].value = arg.value) : console.log('Unknown VacationCommand :' + p);
8485
}
8586
});
8687
}

dev/Sieve/Extensions/rfc5235.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class VirusTestTest extends TestCommand
5151
this._value = new GrammarQuotedString; // 1 - 5
5252
}
5353

54-
get require() { return /:value|:count/.test(this.match_type) ? ['virustest','relational'] : 'virustest'; }
54+
get require() { return /:value/.test(this.match_type) ? ['virustest','relational'] : 'virustest'; }
5555

5656
get value() { return this._value.value; }
5757
set value(v) { this._value.value = v; }

dev/Sieve/Extensions/rfc5435.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ export class NotifyCommand extends ActionCommand
6565
this.options = arg; // GrammarStringList
6666
} else if (i && ':' === args[i-1][0]) {
6767
// :from, :importance, :message
68-
this[args[i-1].replace(':','_')].value = arg.value;
68+
let p = args[i-1].replace(':','_');
69+
this[p] ? (this[p].value = arg.value) : console.log('Unknown VacationCommand :' + p);
6970
}
7071
});
7172
}

dev/Sieve/Extensions/rfc5703.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ export class ReplaceCommand extends ActionCommand
108108
this.mime = true;
109109
} else if (i && ':' === args[i-1][0]) {
110110
// :subject, :from
111-
this[args[i-1].replace(':','_')].value = arg.value;
111+
let p = args[i-1].replace(':','_');
112+
this[p] ? (this[p].value = arg.value) : console.log('Unknown VacationCommand :' + p);
112113
}
113114
});
114115
}
@@ -148,7 +149,8 @@ export class EncloseCommand extends ActionCommand
148149
args.forEach((arg, i) => {
149150
if (i && ':' === args[i-1][0]) {
150151
// :subject, :headers
151-
this[args[i-1].replace(':','_')].value = arg.value;
152+
let p = args[i-1].replace(':','_');
153+
this[p] ? (this[p].value = arg.value) : console.log('Unknown VacationCommand :' + p);
152154
}
153155
});
154156
}

dev/Sieve/Extensions/rfc6134.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class ValidExtListTest extends TestCommand
1414
{
1515
constructor()
1616
{
17-
super();
17+
super('valid_ext_list');
1818
this.ext_list_names = new GrammarStringList;
1919
}
2020

dev/Sieve/Parser.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
GrammarTestList
2929
} from 'Sieve/Grammar';
3030

31-
import { availableCommands } from 'Sieve/Commands';
31+
import { availableCommands, unavailableCommands } from 'Sieve/Commands';
3232
import { ConditionalCommand, IfCommand, RequireCommand } from 'Sieve/Commands/Controls';
3333
import { NotTest } from 'Sieve/Commands/Tests';
3434

@@ -93,6 +93,7 @@ export const parseScript = (script, name = 'script.sieve') => {
9393

9494
// Only activate available commands
9595
const Commands = availableCommands();
96+
const disabledCommands = unavailableCommands();
9697

9798
let match,
9899
line = 1,
@@ -173,17 +174,12 @@ export const parseScript = (script, name = 'script.sieve') => {
173174
// (command instanceof ConditionalCommand || command instanceof NotTest) || error('Test-list not in conditional');
174175
}
175176
new_command = new Commands[value]();
177+
} else if (disabledCommands[value]) {
178+
console.error('Unsupported command: ' + value);
179+
new_command = new disabledCommands[value]();
176180
} else {
177-
if (command && (
178-
command instanceof ConditionalCommand
179-
|| command instanceof NotTest
180-
|| command.tests instanceof GrammarTestList)) {
181-
console.error('Unknown test: ' + value);
182-
new_command = new TestCommand(value);
183-
} else {
184-
console.error('Unknown command: ' + value);
185-
new_command = new GrammarCommand(value);
186-
}
181+
console.error('Unknown command: ' + value);
182+
new_command = new GrammarCommand(value);
187183
}
188184

189185
if (new_command instanceof TestCommand) {
@@ -201,7 +197,7 @@ export const parseScript = (script, name = 'script.sieve') => {
201197
if (command.commands) {
202198
command.commands.push(new_command);
203199
} else {
204-
error('commands not allowed in "' + command.identifier + '" command');
200+
error('command "' + new_command.identifier + '" not allowed in "' + command.identifier + '" command');
205201
}
206202
} else {
207203
tree.push(new_command);

0 commit comments

Comments
 (0)