Added Sieve rfc5490

Renamed tests classes *Command as *Test
This commit is contained in:
the-djmaze 2022-03-14 12:39:11 +01:00
parent 40adf992ed
commit 668a5f1fa5
12 changed files with 224 additions and 57 deletions

View file

@ -102,6 +102,10 @@ export class FileIntoCommand extends GrammarCommand
toString() toString()
{ {
// https://datatracker.ietf.org/doc/html/rfc3894
// :copy
// https://datatracker.ietf.org/doc/html/rfc5490#section-3.2
// :create
return 'fileinto ' + this._mailbox + ';'; return 'fileinto ' + this._mailbox + ';';
} }
@ -137,6 +141,8 @@ export class RedirectCommand extends GrammarCommand
toString() toString()
{ {
// https://datatracker.ietf.org/doc/html/rfc3894
// :copy
return 'redirect ' + this._address + ';'; return 'redirect ' + this._address + ';';
} }

View file

@ -8,7 +8,7 @@ import {
GrammarTest GrammarTest
} from 'Sieve/Grammar'; } from 'Sieve/Grammar';
export class BodyCommand extends GrammarTest export class BodyTest extends GrammarTest
{ {
constructor() constructor()
{ {

View file

@ -8,7 +8,7 @@ import {
GrammarTest GrammarTest
} from 'Sieve/Grammar'; } from 'Sieve/Grammar';
export class EnvironmentCommand extends GrammarTest export class EnvironmentTest extends GrammarTest
{ {
constructor() constructor()
{ {

View file

@ -45,7 +45,7 @@ export class SetCommand extends GrammarCommand
} }
} }
export class StringCommand extends GrammarTest export class StringTest extends GrammarTest
{ {
constructor() constructor()
{ {

View file

@ -63,7 +63,7 @@ export class RemoveFlagCommand extends FlagCommand
{ {
} }
export class HasFlagCommand extends GrammarTest export class HasFlagTest extends GrammarTest
{ {
constructor() constructor()
{ {

View file

@ -8,7 +8,7 @@ import {
GrammarTest GrammarTest
} from 'Sieve/Grammar'; } from 'Sieve/Grammar';
export class SpamTestCommand extends GrammarTest export class SpamTestTest extends GrammarTest
{ {
constructor() constructor()
{ {
@ -41,7 +41,7 @@ export class SpamTestCommand extends GrammarTest
} }
} }
export class VirusTestCommand extends GrammarTest export class VirusTestTest extends GrammarTest
{ {
constructor() constructor()
{ {

View file

@ -9,7 +9,7 @@ import {
GrammarTest GrammarTest
} from 'Sieve/Grammar'; } from 'Sieve/Grammar';
export class DateCommand extends GrammarTest export class DateTest extends GrammarTest
{ {
constructor() constructor()
{ {
@ -62,7 +62,7 @@ export class DateCommand extends GrammarTest
} }
} }
export class CurrentDateCommand extends GrammarTest export class CurrentDateTest extends GrammarTest
{ {
constructor() constructor()
{ {

View file

@ -0,0 +1,151 @@
/**
* https://tools.ietf.org/html/rfc5490
*/
import {
GrammarTest,
GrammarString,
GrammarStringList
} from 'Sieve/Grammar';
/**
* https://datatracker.ietf.org/doc/html/rfc5490#section-3.1
*/
export class MailboxExistsTest extends GrammarTest
{
constructor()
{
super();
this.mailbox_names = new GrammarStringList;
}
get require() { return 'mailbox'; }
toString()
{
return 'mailboxexists ' + this.mailbox_names + ';';
}
pushArguments(args)
{
if (args[0] instanceof GrammarStringList) {
this.mailbox_names = args[0];
}
}
}
/**
* https://datatracker.ietf.org/doc/html/rfc5490#section-3.3
*/
export class MetadataTest extends GrammarTest
{
constructor()
{
super();
this.mailbox = new GrammarString;
this.annotation_name = new GrammarString;
this.key_list = new GrammarStringList;
}
get require() { return 'mboxmetadata'; }
toString()
{
return 'metadata '
+ ' ' + this.match_type
+ (this.comparator ? ' :comparator ' + this.comparator : '')
+ ' ' + this.mailbox
+ ' ' + this.annotation_name
+ ' ' + this.key_list.toString();
}
pushArguments(args)
{
this.mailbox = args[args.length-3];
this.annotation_name = args[args.length-2];
this.key_list = args[args.length-1];
}
}
/**
* https://datatracker.ietf.org/doc/html/rfc5490#section-3.4
*/
export class MetadataExistsTest extends GrammarTest
{
constructor()
{
super();
this.mailbox = new GrammarString;
this.annotation_names = new GrammarStringList;
}
get require() { return 'mboxmetadata'; }
toString()
{
return 'metadataexists '
+ ' ' + this.mailbox
+ ' ' + this.annotation_names;
}
pushArguments(args)
{
this.mailbox = args[args.length-2];
this.annotation_names = args[args.length-1];
}
}
/**
* https://datatracker.ietf.org/doc/html/rfc5490#section-3.3
*/
export class ServerMetadataTest extends GrammarTest
{
constructor()
{
super();
this.annotation_name = new GrammarString;
this.key_list = new GrammarStringList;
}
get require() { return 'servermetadata'; }
toString()
{
return 'servermetadata '
+ ' ' + this.match_type
+ (this.comparator ? ' :comparator ' + this.comparator : '')
+ ' ' + this.annotation_name
+ ' ' + this.key_list.toString();
}
pushArguments(args)
{
this.annotation_name = args[args.length-2];
this.key_list = args[args.length-1];
}
}
/**
* https://datatracker.ietf.org/doc/html/rfc5490#section-3.4
*/
export class ServerMetadataExistsTest extends GrammarTest
{
constructor()
{
super();
this.annotation_names = new GrammarStringList;
}
get require() { return 'servermetadata'; }
toString()
{
return 'servermetadataexists '
+ ' ' + this.annotation_names;
}
pushArguments(args)
{
this.annotation_names = args[args.length-1];
}
}

View file

@ -231,7 +231,7 @@ export class GrammarTest
{ {
constructor(identifier) constructor(identifier)
{ {
this.identifier = identifier || this.constructor.name.toLowerCase().replace('command', ''); this.identifier = identifier || this.constructor.name.toLowerCase().replace(/test$/, '');
// Almost every test has a comparator and match_type, so define them here // Almost every test has a comparator and match_type, so define them here
this.comparator = '', this.comparator = '',
this.match_type = ':is', this.match_type = ':is',

View file

@ -39,32 +39,32 @@ import {
} from 'Sieve/Commands'; } from 'Sieve/Commands';
import { import {
AddressCommand, AddressTest,
AllOfCommand, AllOfTest,
AnyOfCommand, AnyOfTest,
EnvelopeCommand, EnvelopeTest,
ExistsCommand, ExistsTest,
FalseCommand, FalseTest,
HeaderCommand, HeaderTest,
NotCommand, NotTest,
SizeCommand, SizeTest,
TrueCommand TrueTest
} from 'Sieve/Tests'; } from 'Sieve/Tests';
import { BodyCommand } from 'Sieve/Extensions/rfc5173'; import { BodyTest } from 'Sieve/Extensions/rfc5173';
import { EnvironmentCommand } from 'Sieve/Extensions/rfc5183'; import { EnvironmentTest } from 'Sieve/Extensions/rfc5183';
import { SetCommand, StringCommand } from 'Sieve/Extensions/rfc5229'; import { SetCommand, StringTest } from 'Sieve/Extensions/rfc5229';
import { VacationCommand } from 'Sieve/Extensions/rfc5230'; import { VacationCommand } from 'Sieve/Extensions/rfc5230';
import { import {
SetFlagCommand, SetFlagCommand,
AddFlagCommand, AddFlagCommand,
RemoveFlagCommand, RemoveFlagCommand,
HasFlagCommand HasFlagTest
} from 'Sieve/Extensions/rfc5232'; } from 'Sieve/Extensions/rfc5232';
import { SpamTestCommand, VirusTestCommand } from 'Sieve/Extensions/rfc5235'; import { SpamTestTest, VirusTestTest } from 'Sieve/Extensions/rfc5235';
import { DateCommand, CurrentDateCommand } from 'Sieve/Extensions/rfc5260'; import { DateTest, CurrentDateTest } from 'Sieve/Extensions/rfc5260';
import { AddHeaderCommand, DeleteHeaderCommand } from 'Sieve/Extensions/rfc5293'; import { AddHeaderCommand, DeleteHeaderCommand } from 'Sieve/Extensions/rfc5293';
import { import {
@ -72,6 +72,12 @@ import {
RejectCommand RejectCommand
} from 'Sieve/Extensions/rfc5429'; } from 'Sieve/Extensions/rfc5429';
import {
MailboxExistsTest,
MetadataTest,
MetadataExistsTest
} from 'Sieve/Extensions/rfc5490';
import { import {
IncludeCommand, IncludeCommand,
ReturnCommand ReturnCommand
@ -92,42 +98,46 @@ const
keep: KeepCommand, keep: KeepCommand,
redirect: RedirectCommand, redirect: RedirectCommand,
// Test commands // Test commands
address: AddressCommand, address: AddressTest,
allof: AllOfCommand, allof: AllOfTest,
anyof: AnyOfCommand, anyof: AnyOfTest,
envelope: EnvelopeCommand, envelope: EnvelopeTest,
exists: ExistsCommand, exists: ExistsTest,
false: FalseCommand, false: FalseTest,
header: HeaderCommand, header: HeaderTest,
not: NotCommand, not: NotTest,
size: SizeCommand, size: SizeTest,
true: TrueCommand, true: TrueTest,
// rfc5173 // rfc5173
body: BodyCommand, body: BodyTest,
// rfc5183 // rfc5183
environment: EnvironmentCommand, environment: EnvironmentTest,
// rfc5229 // rfc5229
set: SetCommand, set: SetCommand,
string: StringCommand, string: StringTest,
// rfc5230 // rfc5230
vacation: VacationCommand, vacation: VacationCommand,
// rfc5232 // rfc5232
setflag: SetFlagCommand, setflag: SetFlagCommand,
addflag: AddFlagCommand, addflag: AddFlagCommand,
removeflag: RemoveFlagCommand, removeflag: RemoveFlagCommand,
hasflag: HasFlagCommand, hasflag: HasFlagTest,
// rfc5235 // rfc5235
spamtest: SpamTestCommand, spamtest: SpamTestTest,
virustest: VirusTestCommand, virustest: VirusTestTest,
// rfc5260 // rfc5260
date: DateCommand, date: DateTest,
currentdate: CurrentDateCommand, currentdate: CurrentDateTest,
// rfc5293 // rfc5293
AddHeaderCommand, AddHeaderCommand,
DeleteHeaderCommand, DeleteHeaderCommand,
// rfc5429 // rfc5429
ereject: ErejectCommand, ereject: ErejectCommand,
reject: RejectCommand, reject: RejectCommand,
// rfc5490
mailboxexists: MailboxExistsTest,
metadata: MetadataTest,
metadataexists: MetadataExistsTest,
// rfc6609 // rfc6609
include: IncludeCommand, include: IncludeCommand,
return: ReturnCommand return: ReturnCommand
@ -237,14 +247,14 @@ export const parseScript = (script, name = 'script.sieve') => {
new_command = new ConditionalCommand(value); new_command = new ConditionalCommand(value);
} else if (Commands[value]) { } else if (Commands[value]) {
if ('allof' === value || 'anyof' === value) { if ('allof' === value || 'anyof' === value) {
// (command instanceof ConditionalCommand || command instanceof NotCommand) || 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 {
console.error('Unknown command: ' + value); console.error('Unknown command: ' + value);
if (command && ( if (command && (
command instanceof ConditionalCommand command instanceof ConditionalCommand
|| command instanceof NotCommand || command instanceof NotTest
|| command.tests instanceof GrammarTestList)) { || command.tests instanceof GrammarTestList)) {
new_command = new GrammarTest(value); new_command = new GrammarTest(value);
} else { } else {
@ -253,7 +263,7 @@ export const parseScript = (script, name = 'script.sieve') => {
} }
if (new_command instanceof GrammarTest) { if (new_command instanceof GrammarTest) {
if (command instanceof ConditionalCommand || command instanceof NotCommand) { if (command instanceof ConditionalCommand || command instanceof NotTest) {
// if/elsif/else new_command // if/elsif/else new_command
// not new_command // not new_command
command.test = new_command; command.test = new_command;

View file

@ -18,7 +18,7 @@ https://www.iana.org/assignments/sieve-extensions/sieve-extensions.xhtml
- [x] RFC5429 ereject / reject - [x] RFC5429 ereject / reject
- [ ] RFC5435 enotify - [ ] RFC5435 enotify
- [ ] RFC5463 ihave - [ ] RFC5463 ihave
- [ ] RFC5490 mailbox / mboxmetadata / servermetadata - [x] RFC5490 mailbox / mboxmetadata / servermetadata
- [ ] RFC5703 enclose / extracttext / foreverypart / mime / replace - [ ] RFC5703 enclose / extracttext / foreverypart / mime / replace
- [ ] RFC6131 vacation-seconds - [ ] RFC6131 vacation-seconds
- [ ] RFC6134 extlists - [ ] RFC6134 extlists

View file

@ -18,7 +18,7 @@ const
/** /**
* https://tools.ietf.org/html/rfc5228#section-5.1 * https://tools.ietf.org/html/rfc5228#section-5.1
*/ */
export class AddressCommand extends GrammarTest export class AddressTest extends GrammarTest
{ {
constructor() constructor()
{ {
@ -69,7 +69,7 @@ export class AddressCommand extends GrammarTest
/** /**
* https://tools.ietf.org/html/rfc5228#section-5.2 * https://tools.ietf.org/html/rfc5228#section-5.2
*/ */
export class AllOfCommand extends GrammarTest export class AllOfTest extends GrammarTest
{ {
constructor() constructor()
{ {
@ -86,7 +86,7 @@ export class AllOfCommand extends GrammarTest
/** /**
* https://tools.ietf.org/html/rfc5228#section-5.3 * https://tools.ietf.org/html/rfc5228#section-5.3
*/ */
export class AnyOfCommand extends GrammarTest export class AnyOfTest extends GrammarTest
{ {
constructor() constructor()
{ {
@ -103,7 +103,7 @@ export class AnyOfCommand extends GrammarTest
/** /**
* https://tools.ietf.org/html/rfc5228#section-5.4 * https://tools.ietf.org/html/rfc5228#section-5.4
*/ */
export class EnvelopeCommand extends GrammarTest export class EnvelopeTest extends GrammarTest
{ {
constructor() constructor()
{ {
@ -141,7 +141,7 @@ export class EnvelopeCommand extends GrammarTest
/** /**
* https://tools.ietf.org/html/rfc5228#section-5.5 * https://tools.ietf.org/html/rfc5228#section-5.5
*/ */
export class ExistsCommand extends GrammarTest export class ExistsTest extends GrammarTest
{ {
constructor() constructor()
{ {
@ -167,7 +167,7 @@ export class ExistsCommand extends GrammarTest
/** /**
* https://tools.ietf.org/html/rfc5228#section-5.6 * https://tools.ietf.org/html/rfc5228#section-5.6
*/ */
export class FalseCommand extends GrammarTest export class FalseTest extends GrammarTest
{ {
toString() toString()
{ {
@ -178,7 +178,7 @@ export class FalseCommand extends GrammarTest
/** /**
* https://tools.ietf.org/html/rfc5228#section-5.7 * https://tools.ietf.org/html/rfc5228#section-5.7
*/ */
export class HeaderCommand extends GrammarTest export class HeaderTest extends GrammarTest
{ {
constructor() constructor()
{ {
@ -228,7 +228,7 @@ export class HeaderCommand extends GrammarTest
/** /**
* https://tools.ietf.org/html/rfc5228#section-5.8 * https://tools.ietf.org/html/rfc5228#section-5.8
*/ */
export class NotCommand extends GrammarTest export class NotTest extends GrammarTest
{ {
constructor() constructor()
{ {
@ -250,7 +250,7 @@ export class NotCommand extends GrammarTest
/** /**
* https://tools.ietf.org/html/rfc5228#section-5.9 * https://tools.ietf.org/html/rfc5228#section-5.9
*/ */
export class SizeCommand extends GrammarTest export class SizeTest extends GrammarTest
{ {
constructor() constructor()
{ {
@ -279,7 +279,7 @@ export class SizeCommand extends GrammarTest
/** /**
* https://tools.ietf.org/html/rfc5228#section-5.10 * https://tools.ietf.org/html/rfc5228#section-5.10
*/ */
export class TrueCommand extends GrammarTest export class TrueTest extends GrammarTest
{ {
toString() toString()
{ {