mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Some Sieve parser improvements
This commit is contained in:
parent
61c2eefec1
commit
4022d39f76
7 changed files with 32 additions and 18 deletions
|
|
@ -48,6 +48,7 @@ import { NotifyCommand, ValidNotifyMethodTest, NotifyMethodCapabilityTest } from
|
||||||
import { IHaveTest, ErrorCommand } from 'Sieve/Extensions/rfc5463';
|
import { IHaveTest, ErrorCommand } from 'Sieve/Extensions/rfc5463';
|
||||||
import { MailboxExistsTest, MetadataTest, MetadataExistsTest } from 'Sieve/Extensions/rfc5490';
|
import { MailboxExistsTest, MetadataTest, MetadataExistsTest } from 'Sieve/Extensions/rfc5490';
|
||||||
import { ForEveryPartCommand, BreakCommand, ReplaceCommand, EncloseCommand, ExtractTextCommand } from 'Sieve/Extensions/rfc5703';
|
import { ForEveryPartCommand, BreakCommand, ReplaceCommand, EncloseCommand, ExtractTextCommand } from 'Sieve/Extensions/rfc5703';
|
||||||
|
import { ValidExtListTest } from 'Sieve/Extensions/rfc6134';
|
||||||
import { IncludeCommand, ReturnCommand, GlobalCommand } from 'Sieve/Extensions/rfc6609';
|
import { IncludeCommand, ReturnCommand, GlobalCommand } from 'Sieve/Extensions/rfc6609';
|
||||||
|
|
||||||
export const
|
export const
|
||||||
|
|
@ -127,6 +128,8 @@ export const
|
||||||
ReplaceCommand,
|
ReplaceCommand,
|
||||||
EncloseCommand,
|
EncloseCommand,
|
||||||
ExtractTextCommand,
|
ExtractTextCommand,
|
||||||
|
// rfc6134
|
||||||
|
ValidExtListTest,
|
||||||
// rfc6609
|
// rfc6609
|
||||||
IncludeCommand,
|
IncludeCommand,
|
||||||
ReturnCommand,
|
ReturnCommand,
|
||||||
|
|
@ -144,6 +147,17 @@ export const
|
||||||
return commands;
|
return commands;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
unavailableCommands = () => {
|
||||||
|
let commands = {};
|
||||||
|
AllCommands.forEach(cmd => {
|
||||||
|
const obj = new cmd, requires = obj.require;
|
||||||
|
if (requires && !(Array.isArray(requires) ? requires : [requires]).every(string => capa.includes(string))) {
|
||||||
|
commands[obj.identifier] = cmd;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return commands;
|
||||||
|
},
|
||||||
|
|
||||||
availableActions = () => {
|
availableActions = () => {
|
||||||
let actions = {}, id;
|
let actions = {}, id;
|
||||||
AllCommands.forEach(cmd => {
|
AllCommands.forEach(cmd => {
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,8 @@ export class VacationCommand extends ActionCommand
|
||||||
this.addresses = arg; // GrammarStringList
|
this.addresses = arg; // GrammarStringList
|
||||||
} else if (i && ':' === args[i-1][0]) {
|
} else if (i && ':' === args[i-1][0]) {
|
||||||
// :days, :seconds, :subject, :from, :handle
|
// :days, :seconds, :subject, :from, :handle
|
||||||
this[args[i-1].replace(':','_')].value = arg.value;
|
let p = args[i-1].replace(':','_');
|
||||||
|
this[p] ? (this[p].value = arg.value) : console.log('Unknown VacationCommand :' + p);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ export class VirusTestTest extends TestCommand
|
||||||
this._value = new GrammarQuotedString; // 1 - 5
|
this._value = new GrammarQuotedString; // 1 - 5
|
||||||
}
|
}
|
||||||
|
|
||||||
get require() { return /:value|:count/.test(this.match_type) ? ['virustest','relational'] : 'virustest'; }
|
get require() { return /:value/.test(this.match_type) ? ['virustest','relational'] : 'virustest'; }
|
||||||
|
|
||||||
get value() { return this._value.value; }
|
get value() { return this._value.value; }
|
||||||
set value(v) { this._value.value = v; }
|
set value(v) { this._value.value = v; }
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,8 @@ export class NotifyCommand extends ActionCommand
|
||||||
this.options = arg; // GrammarStringList
|
this.options = arg; // GrammarStringList
|
||||||
} else if (i && ':' === args[i-1][0]) {
|
} else if (i && ':' === args[i-1][0]) {
|
||||||
// :from, :importance, :message
|
// :from, :importance, :message
|
||||||
this[args[i-1].replace(':','_')].value = arg.value;
|
let p = args[i-1].replace(':','_');
|
||||||
|
this[p] ? (this[p].value = arg.value) : console.log('Unknown VacationCommand :' + p);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,8 @@ export class ReplaceCommand extends ActionCommand
|
||||||
this.mime = true;
|
this.mime = true;
|
||||||
} else if (i && ':' === args[i-1][0]) {
|
} else if (i && ':' === args[i-1][0]) {
|
||||||
// :subject, :from
|
// :subject, :from
|
||||||
this[args[i-1].replace(':','_')].value = arg.value;
|
let p = args[i-1].replace(':','_');
|
||||||
|
this[p] ? (this[p].value = arg.value) : console.log('Unknown VacationCommand :' + p);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -148,7 +149,8 @@ export class EncloseCommand extends ActionCommand
|
||||||
args.forEach((arg, i) => {
|
args.forEach((arg, i) => {
|
||||||
if (i && ':' === args[i-1][0]) {
|
if (i && ':' === args[i-1][0]) {
|
||||||
// :subject, :headers
|
// :subject, :headers
|
||||||
this[args[i-1].replace(':','_')].value = arg.value;
|
let p = args[i-1].replace(':','_');
|
||||||
|
this[p] ? (this[p].value = arg.value) : console.log('Unknown VacationCommand :' + p);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ export class ValidExtListTest extends TestCommand
|
||||||
{
|
{
|
||||||
constructor()
|
constructor()
|
||||||
{
|
{
|
||||||
super();
|
super('valid_ext_list');
|
||||||
this.ext_list_names = new GrammarStringList;
|
this.ext_list_names = new GrammarStringList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import {
|
||||||
GrammarTestList
|
GrammarTestList
|
||||||
} from 'Sieve/Grammar';
|
} from 'Sieve/Grammar';
|
||||||
|
|
||||||
import { availableCommands } from 'Sieve/Commands';
|
import { availableCommands, unavailableCommands } from 'Sieve/Commands';
|
||||||
import { ConditionalCommand, IfCommand, RequireCommand } from 'Sieve/Commands/Controls';
|
import { ConditionalCommand, IfCommand, RequireCommand } from 'Sieve/Commands/Controls';
|
||||||
import { NotTest } from 'Sieve/Commands/Tests';
|
import { NotTest } from 'Sieve/Commands/Tests';
|
||||||
|
|
||||||
|
|
@ -93,6 +93,7 @@ export const parseScript = (script, name = 'script.sieve') => {
|
||||||
|
|
||||||
// Only activate available commands
|
// Only activate available commands
|
||||||
const Commands = availableCommands();
|
const Commands = availableCommands();
|
||||||
|
const disabledCommands = unavailableCommands();
|
||||||
|
|
||||||
let match,
|
let match,
|
||||||
line = 1,
|
line = 1,
|
||||||
|
|
@ -173,18 +174,13 @@ export const parseScript = (script, name = 'script.sieve') => {
|
||||||
// (command instanceof ConditionalCommand || command instanceof NotTest) || error('Test-list not in conditional');
|
// (command instanceof ConditionalCommand || command instanceof NotTest) || error('Test-list not in conditional');
|
||||||
}
|
}
|
||||||
new_command = new Commands[value]();
|
new_command = new Commands[value]();
|
||||||
} else {
|
} else if (disabledCommands[value]) {
|
||||||
if (command && (
|
console.error('Unsupported command: ' + value);
|
||||||
command instanceof ConditionalCommand
|
new_command = new disabledCommands[value]();
|
||||||
|| command instanceof NotTest
|
|
||||||
|| command.tests instanceof GrammarTestList)) {
|
|
||||||
console.error('Unknown test: ' + value);
|
|
||||||
new_command = new TestCommand(value);
|
|
||||||
} else {
|
} else {
|
||||||
console.error('Unknown command: ' + value);
|
console.error('Unknown command: ' + value);
|
||||||
new_command = new GrammarCommand(value);
|
new_command = new GrammarCommand(value);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (new_command instanceof TestCommand) {
|
if (new_command instanceof TestCommand) {
|
||||||
if (command instanceof ConditionalCommand || command instanceof NotTest) {
|
if (command instanceof ConditionalCommand || command instanceof NotTest) {
|
||||||
|
|
@ -201,7 +197,7 @@ export const parseScript = (script, name = 'script.sieve') => {
|
||||||
if (command.commands) {
|
if (command.commands) {
|
||||||
command.commands.push(new_command);
|
command.commands.push(new_command);
|
||||||
} else {
|
} else {
|
||||||
error('commands not allowed in "' + command.identifier + '" command');
|
error('command "' + new_command.identifier + '" not allowed in "' + command.identifier + '" command');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tree.push(new_command);
|
tree.push(new_command);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue