mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-30 04:29:21 +03:00
Prepare some Sieve restructuring for GUI
This commit is contained in:
parent
37bb9a9a97
commit
ff9a89380c
15 changed files with 259 additions and 194 deletions
|
|
@ -56,7 +56,7 @@ export class GrammarCommand
|
|||
{
|
||||
constructor(identifier)
|
||||
{
|
||||
this.identifier = identifier || this.constructor.name.toLowerCase().replace('command', '');
|
||||
this.identifier = identifier || this.constructor.name.toLowerCase().replace(/(test|command|action)$/, '');
|
||||
this.arguments = [];
|
||||
this.commands = new GrammarCommands;
|
||||
}
|
||||
|
|
@ -105,6 +105,114 @@ export class GrammarCommands extends Array
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* https://tools.ietf.org/html/rfc5228#section-3
|
||||
*/
|
||||
export class ControlCommand extends GrammarCommand
|
||||
{
|
||||
constructor(identifier)
|
||||
{
|
||||
super(identifier);
|
||||
this.commands = new GrammarCommands;
|
||||
}
|
||||
|
||||
toString()
|
||||
{
|
||||
let result = this.identifier;
|
||||
if (this.arguments.length) {
|
||||
result += ' ' + arrayToString(this.arguments, ' ');
|
||||
}
|
||||
return result + (
|
||||
this.commands.length ? ' ' + this.commands : ';'
|
||||
);
|
||||
}
|
||||
|
||||
getComparators()
|
||||
{
|
||||
return ['i;ascii-casemap'];
|
||||
}
|
||||
|
||||
getMatchTypes()
|
||||
{
|
||||
return [':is', ':contains', ':matches'];
|
||||
}
|
||||
|
||||
pushArguments(args)
|
||||
{
|
||||
this.arguments = args;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* https://tools.ietf.org/html/rfc5228#section-4
|
||||
*/
|
||||
export class ActionCommand extends GrammarCommand
|
||||
{
|
||||
constructor(identifier)
|
||||
{
|
||||
super(identifier);
|
||||
}
|
||||
|
||||
toString()
|
||||
{
|
||||
let result = this.identifier;
|
||||
if (this.arguments.length) {
|
||||
result += ' ' + arrayToString(this.arguments, ' ');
|
||||
}
|
||||
return result + ';'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* https://tools.ietf.org/html/rfc5228#section-5
|
||||
*/
|
||||
export class TestCommand extends GrammarCommand
|
||||
{
|
||||
constructor(identifier)
|
||||
{
|
||||
super(identifier);
|
||||
// Almost every test has a comparator and match_type, so define them here
|
||||
this.comparator = '';
|
||||
this.match_type = ':is';
|
||||
}
|
||||
|
||||
toString()
|
||||
{
|
||||
// https://datatracker.ietf.org/doc/html/rfc6134#section-2.3
|
||||
if (!getMatchTypes().includes(this.match_type)) {
|
||||
throw 'Unsupported match-type ' + this.match_type;
|
||||
}
|
||||
return (this.identifier
|
||||
+ (this.comparator ? ' :comparator ' + this.comparator : '')
|
||||
+ (this.match_type ? ' ' + this.match_type : '')
|
||||
+ ' ' + arrayToString(this.arguments, ' ')).trim();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* https://tools.ietf.org/html/rfc5228#section-5.2
|
||||
* https://tools.ietf.org/html/rfc5228#section-5.3
|
||||
*/
|
||||
export class GrammarTestList extends Array
|
||||
{
|
||||
toString()
|
||||
{
|
||||
if (1 < this.length) {
|
||||
// return '(\r\n\t' + arrayToString(this, ',\r\n\t') + '\r\n)';
|
||||
return '(' + this.join(', ') + ')';
|
||||
}
|
||||
return this.length ? this[0] : '';
|
||||
}
|
||||
|
||||
push(value)
|
||||
{
|
||||
if (!(value instanceof TestCommand)) {
|
||||
throw 'Not an instanceof Test';
|
||||
}
|
||||
super.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
export class GrammarBracketComment extends GrammarComment
|
||||
{
|
||||
toString()
|
||||
|
|
@ -221,59 +329,3 @@ GrammarMultiLine.fromString = string => {
|
|||
}
|
||||
return new GrammarMultiLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* https://tools.ietf.org/html/rfc5228#section-5
|
||||
*/
|
||||
export class GrammarTest
|
||||
{
|
||||
constructor(identifier)
|
||||
{
|
||||
this.identifier = identifier || this.constructor.name.toLowerCase().replace(/test$/, '');
|
||||
// Almost every test has a comparator and match_type, so define them here
|
||||
this.comparator = '',
|
||||
this.match_type = ':is',
|
||||
this.arguments = [];
|
||||
}
|
||||
|
||||
toString()
|
||||
{
|
||||
// https://datatracker.ietf.org/doc/html/rfc6134#section-2.3
|
||||
if (!getMatchTypes().includes(this.match_type)) {
|
||||
throw 'Unsupported match-type ' + this.match_type;
|
||||
}
|
||||
return (this.identifier
|
||||
+ (this.comparator ? ' :comparator ' + this.comparator : '')
|
||||
+ (this.match_type ? ' ' + this.match_type : '')
|
||||
+ ' ' + arrayToString(this.arguments, ' ')).trim();
|
||||
}
|
||||
|
||||
pushArguments(args)
|
||||
{
|
||||
this.arguments = args;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* https://tools.ietf.org/html/rfc5228#section-5.2
|
||||
* https://tools.ietf.org/html/rfc5228#section-5.3
|
||||
*/
|
||||
export class GrammarTestList extends Array
|
||||
{
|
||||
toString()
|
||||
{
|
||||
if (1 < this.length) {
|
||||
// return '(\r\n\t' + arrayToString(this, ',\r\n\t') + '\r\n)';
|
||||
return '(' + this.join(', ') + ')';
|
||||
}
|
||||
return this.length ? this[0] : '';
|
||||
}
|
||||
|
||||
push(value)
|
||||
{
|
||||
if (!(value instanceof GrammarTest)) {
|
||||
throw 'Not an instanceof Test';
|
||||
}
|
||||
super.push(value);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue