mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-02 14:07:04 +03:00
Simplify Sieve Parser and added RFC5235
This commit is contained in:
parent
22964f1fde
commit
d9865e3a46
11 changed files with 308 additions and 92 deletions
95
dev/Sieve/Extensions/rfc5235.js
Normal file
95
dev/Sieve/Extensions/rfc5235.js
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
/**
|
||||
* https://tools.ietf.org/html/rfc5235
|
||||
*/
|
||||
|
||||
(Sieve => {
|
||||
|
||||
const Grammar = Sieve.Grammar;
|
||||
|
||||
class SpamTest extends Grammar.Test
|
||||
{
|
||||
constructor()
|
||||
{
|
||||
super('spamtest');
|
||||
this.percent = false, // 0 - 100 else 0 - 10
|
||||
this.comparator = 'i;ascii-casemap',
|
||||
this.match_type = ':is',
|
||||
this.value = new Grammar.QuotedString;
|
||||
// this.require = this.percent ? 'spamtestplus' : 'spamtest';
|
||||
}
|
||||
|
||||
toString()
|
||||
{
|
||||
return 'spamtest'
|
||||
+ (this.percent ? ' :percent' : '')
|
||||
// + ' ' + this.comparator
|
||||
+ ' ' + this.match_type
|
||||
+ ' ' + this.value;
|
||||
}
|
||||
|
||||
pushArguments(args)
|
||||
{
|
||||
args.forEach((arg, i) => {
|
||||
if (':is' === arg || ':contains' === arg || ':matches' === arg) {
|
||||
this.match_type = arg;
|
||||
} else if (':percent' === arg) {
|
||||
this.percent = true;
|
||||
} else if (arg instanceof Grammar.StringType) {
|
||||
if (':comparator' === args[i-1]) {
|
||||
this.comparator = arg;
|
||||
} else if (':value' === args[i-1] || ':count' === args[i-1]) {
|
||||
// Sieve relational [RFC5231] match types
|
||||
this.match_type = args[i-1] + ' ' + arg;
|
||||
} else {
|
||||
this.value = arg;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class VirusTest extends Grammar.Test
|
||||
{
|
||||
constructor()
|
||||
{
|
||||
super('virustest');
|
||||
this.comparator = 'i;ascii-casemap',
|
||||
this.match_type = ':is',
|
||||
this.value = new Grammar.QuotedString; // 1 - 5
|
||||
// this.require = 'virustest';
|
||||
}
|
||||
|
||||
toString()
|
||||
{
|
||||
return 'virustest'
|
||||
// + ' ' + this.comparator
|
||||
+ ' ' + this.match_type
|
||||
+ ' ' + this.value;
|
||||
}
|
||||
|
||||
pushArguments(args)
|
||||
{
|
||||
args.forEach((arg, i) => {
|
||||
if (':is' === arg || ':contains' === arg || ':matches' === arg) {
|
||||
this.match_type = arg;
|
||||
} else if (arg instanceof Grammar.StringType) {
|
||||
if (':comparator' === args[i-1]) {
|
||||
this.comparator = arg;
|
||||
} else if (':value' === args[i-1] || ':count' === args[i-1]) {
|
||||
// Sieve relational [RFC5231] match types
|
||||
this.match_type = args[i-1] + ' ' + arg;
|
||||
} else {
|
||||
this.value = arg;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Object.assign(Sieve.Commands, {
|
||||
spamtest: SpamTest,
|
||||
virustest: VirusTest
|
||||
});
|
||||
|
||||
|
||||
})(this.Sieve);
|
||||
Loading…
Add table
Add a link
Reference in a new issue