Draf of Sieve parser/lexer for a new Sieve GUI

This commit is contained in:
djmaze 2021-01-13 21:23:19 +01:00
parent e023a5d6ab
commit b2e77f3f67
13 changed files with 1353 additions and 1 deletions

View file

@ -0,0 +1,28 @@
/**
* https://tools.ietf.org/html/rfc5173
*/
(Sieve => {
Sieve.Extensions.Body = class
{
constructor()
{
this.comparator = 'i;ascii-casemap',
this.match_type = ':is',
this.body_transform = ''; // :raw, :content <string-list>, :text
this.key_list = new Sieve.Grammar.StringList;
}
toString()
{
return 'body'
// + ' ' + this.comparator
+ ' ' + this.match_type
+ ' ' + this.body_transform
+ ' ' + this.key_list;
}
};
})(this.Sieve);

View file

@ -0,0 +1,30 @@
/**
* https://tools.ietf.org/html/rfc5429#section-2.1
*/
(Sieve => {
Sieve.Extensions.Ereject = class
{
constructor()
{
this.reason = new Sieve.Grammar.QuotedString;
}
toString()
{
return 'ereject ' + this.reason;
}
get reason()
{
return this.reason.value;
}
set reason(value)
{
this.reason.value = value;
}
};
})(this.Sieve);

View file

@ -0,0 +1,17 @@
/**
* https://tools.ietf.org/html/rfc5232
*/
(Sieve => {
Sieve.Extensions.Imap4flags = class
{
/**
* setflag [<variablename: string>] <list-of-flags: string-list>
* addflag [<variablename: string>] <list-of-flags: string-list>
* removeflag [<variablename: string>] <list-of-flags: string-list>
* hasflag [MATCH-TYPE] [COMPARATOR] [<variable-list: string-list>] <list-of-flags: string-list>
*/
};
})(this.Sieve);

View file

@ -0,0 +1,30 @@
/**
* https://tools.ietf.org/html/rfc5429#section-2.2
*/
(Sieve => {
Sieve.Extensions.Reject = class
{
constructor()
{
this.reason = new Sieve.Grammar.QuotedString;
}
toString()
{
return 'reject ' + this.reason;
}
get reason()
{
return this.reason.value;
}
set reason(value)
{
this.reason.value = value;
}
};
})(this.Sieve);

View file

@ -0,0 +1,84 @@
/**
* https://tools.ietf.org/html/rfc5230
*/
(Sieve => {
Sieve.Extensions.Vacation = class
{
constructor()
{
this.arguments = {
':days' : new Sieve.Grammar.Number,
':subject' : new Sieve.Grammar.QuotedString,
':from' : new Sieve.Grammar.QuotedString,
':addresses': new Sieve.Grammar.StringList,
':mime' : false,
':handle' : new Sieve.Grammar.QuotedString
};
this.reason = ''; // QuotedString / MultiLine
}
toString()
{
let result = 'vacation';
if (0 < this.arguments[':days'].value) {
result += ' :days ' + this.arguments[':days'];
}
if (this.arguments[':subject'].length()) {
result += ' :subject ' + this.arguments[':subject'];
}
if (this.arguments[':from'].length()) {
result += ' :from ' + this.arguments[':from'];
}
if (this.arguments[':addresses'].length) {
result += ' :addresses ' + this.arguments[':addresses'];
}
if (this.arguments[':mime']) {
result += ' :mime';
}
if (this.arguments[':handle'].length()) {
result += ' :handle ' + this.arguments[':handle'];
}
return result + ' ' + this.reason;
}
/*
function __get($key)
{
if ('reason' === $key) {
return this.reason;
}
if (isset(this.arguments[":{$key}"])) {
return this.arguments[":{$key}"];
}
}
function __set($key, $value)
{
if ('days' === $key) {
this.arguments[":{$key}"] = (int) $value;
} else if ('mime' === $key) {
this.arguments[":{$key}"] = (bool) $value;
} else if ('reason' === $key) {
this.reason = (string) $value;
} else if ('addresses' !== $key && isset(this.arguments[":{$key}"])) {
this.arguments[":{$key}"] = (string) $value;
}
}
public function pushArguments(array $args): void
{
foreach ($args as $i => $arg) {
if (\in_array($arg, [':days',':subject',':from',':addresses', ':handle'])) {
this.arguments[$arg] = $args[$i+1];
} else if (':mime' === $arg) {
this.arguments[':mime'] = true;
} else if (!isset($args[$i+1])) {
this.reason = $arg;
}
}
}
*/
};
})(this.Sieve);