mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-06-26 16:26:44 +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 { MailboxExistsTest, MetadataTest, MetadataExistsTest } from 'Sieve/Extensions/rfc5490';
|
||||
import { ForEveryPartCommand, BreakCommand, ReplaceCommand, EncloseCommand, ExtractTextCommand } from 'Sieve/Extensions/rfc5703';
|
||||
import { ValidExtListTest } from 'Sieve/Extensions/rfc6134';
|
||||
import { IncludeCommand, ReturnCommand, GlobalCommand } from 'Sieve/Extensions/rfc6609';
|
||||
|
||||
export const
|
||||
|
|
@ -127,6 +128,8 @@ export const
|
|||
ReplaceCommand,
|
||||
EncloseCommand,
|
||||
ExtractTextCommand,
|
||||
// rfc6134
|
||||
ValidExtListTest,
|
||||
// rfc6609
|
||||
IncludeCommand,
|
||||
ReturnCommand,
|
||||
|
|
@ -144,6 +147,17 @@ export const
|
|||
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 = () => {
|
||||
let actions = {}, id;
|
||||
AllCommands.forEach(cmd => {
|
||||
|
|
|
|||
|
|
@ -80,7 +80,8 @@ export class VacationCommand extends ActionCommand
|
|||
this.addresses = arg; // GrammarStringList
|
||||
} else if (i && ':' === args[i-1][0]) {
|
||||
// :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
|
||||
}
|
||||
|
||||
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; }
|
||||
set value(v) { this._value.value = v; }
|
||||
|
|
|
|||
|
|
@ -65,7 +65,8 @@ export class NotifyCommand extends ActionCommand
|
|||
this.options = arg; // GrammarStringList
|
||||
} else if (i && ':' === args[i-1][0]) {
|
||||
// :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;
|
||||
} else if (i && ':' === args[i-1][0]) {
|
||||
// :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) => {
|
||||
if (i && ':' === args[i-1][0]) {
|
||||
// :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()
|
||||
{
|
||||
super();
|
||||
super('valid_ext_list');
|
||||
this.ext_list_names = new GrammarStringList;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import {
|
|||
GrammarTestList
|
||||
} from 'Sieve/Grammar';
|
||||
|
||||
import { availableCommands } from 'Sieve/Commands';
|
||||
import { availableCommands, unavailableCommands } from 'Sieve/Commands';
|
||||
import { ConditionalCommand, IfCommand, RequireCommand } from 'Sieve/Commands/Controls';
|
||||
import { NotTest } from 'Sieve/Commands/Tests';
|
||||
|
||||
|
|
@ -93,6 +93,7 @@ export const parseScript = (script, name = 'script.sieve') => {
|
|||
|
||||
// Only activate available commands
|
||||
const Commands = availableCommands();
|
||||
const disabledCommands = unavailableCommands();
|
||||
|
||||
let match,
|
||||
line = 1,
|
||||
|
|
@ -173,17 +174,12 @@ export const parseScript = (script, name = 'script.sieve') => {
|
|||
// (command instanceof ConditionalCommand || command instanceof NotTest) || error('Test-list not in conditional');
|
||||
}
|
||||
new_command = new Commands[value]();
|
||||
} else if (disabledCommands[value]) {
|
||||
console.error('Unsupported command: ' + value);
|
||||
new_command = new disabledCommands[value]();
|
||||
} else {
|
||||
if (command && (
|
||||
command instanceof ConditionalCommand
|
||||
|| command instanceof NotTest
|
||||
|| command.tests instanceof GrammarTestList)) {
|
||||
console.error('Unknown test: ' + value);
|
||||
new_command = new TestCommand(value);
|
||||
} else {
|
||||
console.error('Unknown command: ' + value);
|
||||
new_command = new GrammarCommand(value);
|
||||
}
|
||||
console.error('Unknown command: ' + value);
|
||||
new_command = new GrammarCommand(value);
|
||||
}
|
||||
|
||||
if (new_command instanceof TestCommand) {
|
||||
|
|
@ -201,7 +197,7 @@ export const parseScript = (script, name = 'script.sieve') => {
|
|||
if (command.commands) {
|
||||
command.commands.push(new_command);
|
||||
} else {
|
||||
error('commands not allowed in "' + command.identifier + '" command');
|
||||
error('command "' + new_command.identifier + '" not allowed in "' + command.identifier + '" command');
|
||||
}
|
||||
} else {
|
||||
tree.push(new_command);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue