summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/managesieve/Changelog1
-rw-r--r--plugins/managesieve/lib/rcube_sieve.php35
-rw-r--r--plugins/managesieve/localization/en_US.inc12
-rw-r--r--plugins/managesieve/localization/pl_PL.inc12
-rw-r--r--plugins/managesieve/managesieve.php26
5 files changed, 74 insertions, 12 deletions
diff --git a/plugins/managesieve/Changelog b/plugins/managesieve/Changelog
index fad275ae4..07ac6a2d9 100644
--- a/plugins/managesieve/Changelog
+++ b/plugins/managesieve/Changelog
@@ -1,5 +1,6 @@
- Fixed import from Avelsieve
- Use localized size units (#1486976)
+- Added support for relational operators and i;ascii-numeric comparator
* version 2.9 [2010-08-02]
-----------------------------------------------------------
diff --git a/plugins/managesieve/lib/rcube_sieve.php b/plugins/managesieve/lib/rcube_sieve.php
index 926e8a7e0..4c7eaad58 100644
--- a/plugins/managesieve/lib/rcube_sieve.php
+++ b/plugins/managesieve/lib/rcube_sieve.php
@@ -392,6 +392,7 @@ class rcube_sieve_script
'ereject',
'copy', // RFC3894
'vacation', // RFC5230
+ 'relational', // RFC3431
// TODO: (most wanted first) body, imapflags, notify, regex
);
@@ -511,15 +512,26 @@ class rcube_sieve_script
break;
case 'header':
$tests[$i] .= ($test['not'] ? 'not ' : '');
- $tests[$i] .= 'header :' . $test['type'];
+
+ // relational operator + comparator
+ if (preg_match('/^(value|count)-([gteqnl]{2})/', $test['type'], $m)) {
+ array_push($exts, 'relational');
+ array_push($exts, 'comparator-i;ascii-numeric');
+ $tests[$i] .= 'header :' . $m[1] . ' "' . $m[2] . '" :comparator "i;ascii-numeric"';
+ }
+ else
+ $tests[$i] .= 'header :' . $test['type'];
+
if (is_array($test['arg1']))
$tests[$i] .= ' ["' . implode('", "', $this->_escape_string($test['arg1'])) . '"]';
else
$tests[$i] .= ' "' . $this->_escape_string($test['arg1']) . '"';
+
if (is_array($test['arg2']))
$tests[$i] .= ' ["' . implode('", "', $this->_escape_string($test['arg2'])) . '"]';
else
$tests[$i] .= ' "' . $this->_escape_string($test['arg2']) . '"';
+
break;
}
$i++;
@@ -818,10 +830,14 @@ class rcube_sieve_script
$patterns[] = '(not\s+)?(exists)\s+(".*?[^\\\]")';
$patterns[] = '(not\s+)?(true)';
$patterns[] = '(not\s+)?(size)\s+:(under|over)\s+([0-9]+[KGM]{0,1})';
- $patterns[] = '(not\s+)?(header)\s+:(contains|is|matches)\s+\[(.*?[^\\\]")\]\s+\[(.*?[^\\\]")\]';
- $patterns[] = '(not\s+)?(header)\s+:(contains|is|matches)\s+(".*?[^\\\]")\s+(".*?[^\\\]")';
- $patterns[] = '(not\s+)?(header)\s+:(contains|is|matches)\s+\[(.*?[^\\\]")\]\s+(".*?[^\\\]")';
- $patterns[] = '(not\s+)?(header)\s+:(contains|is|matches)\s+(".*?[^\\\]")\s+\[(.*?[^\\\]")\]';
+ $patterns[] = '(not\s+)?(header)\s+:(contains|is|matches)((\s+))\[(.*?[^\\\]")\]\s+\[(.*?[^\\\]")\]';
+ $patterns[] = '(not\s+)?(header)\s+:(contains|is|matches)((\s+))(".*?[^\\\]")\s+(".*?[^\\\]")';
+ $patterns[] = '(not\s+)?(header)\s+:(contains|is|matches)((\s+))\[(.*?[^\\\]")\]\s+(".*?[^\\\]")';
+ $patterns[] = '(not\s+)?(header)\s+:(contains|is|matches)((\s+))(".*?[^\\\]")\s+\[(.*?[^\\\]")\]';
+ $patterns[] = '(not\s+)?(header)\s+:(count\s+"[gtleqn]{2}"|value\s+"[gtleqn]{2}")(\s+:comparator\s+"(.*?[^\\\])")?\s+\[(.*?[^\\\]")\]\s+\[(.*?[^\\\]")\]';
+ $patterns[] = '(not\s+)?(header)\s+:(count\s+"[gtleqn]{2}"|value\s+"[gtleqn]{2}")(\s+:comparator\s+"(.*?[^\\\])")?\s+(".*?[^\\\]")\s+(".*?[^\\\]")';
+ $patterns[] = '(not\s+)?(header)\s+:(count\s+"[gtleqn]{2}"|value\s+"[gtleqn]{2}")(\s+:comparator\s+"(.*?[^\\\])")?\s+\[(.*?[^\\\]")\]\s+(".*?[^\\\]")';
+ $patterns[] = '(not\s+)?(header)\s+:(count\s+"[gtleqn]{2}"|value\s+"[gtleqn]{2}")(\s+:comparator\s+"(.*?[^\\\])")?\s+(".*?[^\\\]")\s+\[(.*?[^\\\]")\]';
// join patterns...
$pattern = '/(' . implode(')|(', $patterns) . ')/';
@@ -840,10 +856,14 @@ class rcube_sieve_script
);
}
else if (preg_match('/^(not\s+)?header/', $match[0])) {
+ $type = $match[$size-5];
+ if (preg_match('/^(count|value)\s+"([gtleqn]{2})"/', $type, $m))
+ $type = $m[1] . '-' . $m[2];
+
$result[] = array(
'test' => 'header',
- 'not' => $match[$size-5] ? true : false,
- 'type' => $match[$size-3], // is/contains/matches
+ 'type' => $type, // is/contains/matches
+ 'not' => $match[$size-7] ? true : false,
'arg1' => $this->_parse_list($match[$size-2]), // header(s)
'arg2' => $this->_parse_list($match[$size-1]), // string(s)
);
@@ -956,4 +976,3 @@ class rcube_sieve_script
return '["' . implode('","', $list) . '"]';
}
}
-
diff --git a/plugins/managesieve/localization/en_US.inc b/plugins/managesieve/localization/en_US.inc
index 65fd70a70..1bfc88d8c 100644
--- a/plugins/managesieve/localization/en_US.inc
+++ b/plugins/managesieve/localization/en_US.inc
@@ -52,6 +52,18 @@ $labels['none'] = 'none';
$labels['fromset'] = 'from set';
$labels['fromfile'] = 'from file';
$labels['filterdisabled'] = 'Filter disabled';
+$labels['countisgreaterthan'] = 'count is greater than';
+$labels['countisgreaterthanequal'] = 'count is greater than or equal to';
+$labels['countislessthan'] = 'count is less than';
+$labels['countislessthanequal'] = 'count is less than or equal to';
+$labels['countequals'] = 'count is equal to';
+$labels['countnotequals'] = 'count does not equal';
+$labels['valueisgreaterthan'] = 'value is greater than';
+$labels['valueisgreaterthanequal'] = 'value is greater than or equal to';
+$labels['valueislessthan'] = 'value is less than';
+$labels['valueislessthanequal'] = 'value is less than or equal to';
+$labels['valueequals'] = 'value is equal to';
+$labels['valuenotequals'] = 'value does not equal';
$messages = array();
$messages['filterunknownerror'] = 'Unknown server error';
diff --git a/plugins/managesieve/localization/pl_PL.inc b/plugins/managesieve/localization/pl_PL.inc
index 3a7fc9e47..e7fc07dea 100644
--- a/plugins/managesieve/localization/pl_PL.inc
+++ b/plugins/managesieve/localization/pl_PL.inc
@@ -53,6 +53,18 @@ $labels['none'] = 'brak';
$labels['fromset'] = 'ze zbioru';
$labels['fromfile'] = 'z pliku';
$labels['filterdisabled'] = 'Filtr wyłączony';
+$labels['countisgreaterthan'] = 'ilość jest większa od';
+$labels['countisgreaterthanequal'] = 'ilość jest róna lub większa od';
+$labels['countislessthan'] = 'ilość jest mniejsza od';
+$labels['countislessthanequal'] = 'ilość jest równa lub mniejsza od';
+$labels['countequals'] = 'ilość jest równa';
+$labels['countnotequals'] = 'ilość jest różna od';
+$labels['valueisgreaterthan'] = 'wartość jest większa od';
+$labels['valueisgreaterthanequal'] = 'wartość jest równa lub większa od';
+$labels['valueislessthan'] = 'wartość jest mniejsza od';
+$labels['valueislessthanequal'] = 'wartość jest równa lub mniejsza od';
+$labels['valueequals'] = 'wartość jest równa';
+$labels['valuenotequals'] = 'wartość jest różna od';
$messages = array();
$messages['filterunknownerror'] = 'Nieznany błąd serwera';
diff --git a/plugins/managesieve/managesieve.php b/plugins/managesieve/managesieve.php
index 81e6eb7f9..b959c3c93 100644
--- a/plugins/managesieve/managesieve.php
+++ b/plugins/managesieve/managesieve.php
@@ -383,14 +383,14 @@ class managesieve extends rcube_plugin
$this->form['tests'][0]['test'] = 'true';
}
else {
- foreach($headers as $idx => $header) {
+ foreach ($headers as $idx => $header) {
$header = $this->strip_value($header);
$target = $this->strip_value($targets[$idx], true);
$op = $this->strip_value($ops[$idx]);
// normal header
if (in_array($header, $this->headers)) {
- if(preg_match('/^not/', $op))
+ if (preg_match('/^not/', $op))
$this->form['tests'][$i]['not'] = true;
$type = preg_replace('/^not/', '', $op);
@@ -406,6 +406,8 @@ class managesieve extends rcube_plugin
if ($target == '')
$this->errors['tests'][$i]['target'] = $this->gettext('cannotbeempty');
+ else if (preg_match('/^(value|count)-/', $type) && !preg_match('/[0-9]+/', $target))
+ $this->errors['tests'][$i]['target'] = $this->gettext('forbiddenchars');
}
}
else
@@ -425,7 +427,7 @@ class managesieve extends rcube_plugin
case '...':
$cust_header = $headers = $this->strip_value($cust_headers[$idx]);
- if(preg_match('/^not/', $op))
+ if (preg_match('/^not/', $op))
$this->form['tests'][$i]['not'] = true;
$type = preg_replace('/^not/', '', $op);
@@ -458,6 +460,8 @@ class managesieve extends rcube_plugin
if ($target == '')
$this->errors['tests'][$i]['target'] = $this->gettext('cannotbeempty');
+ else if (preg_match('/^(value|count)-/', $type) && !preg_match('/[0-9]+/', $target))
+ $this->errors['tests'][$i]['target'] = $this->gettext('forbiddenchars');
}
break;
}
@@ -888,6 +892,20 @@ class managesieve extends rcube_plugin
$select_op->add(Q($this->gettext('filternotexists')), 'notexists');
// $select_op->add(Q($this->gettext('filtermatches')), 'matches');
// $select_op->add(Q($this->gettext('filternotmatches')), 'notmatches');
+ if (in_array('relational', $this->exts)) {
+ $select_op->add(Q($this->gettext('countisgreaterthan')), 'count-gt');
+ $select_op->add(Q($this->gettext('countisgreaterthanequal')), 'count-ge');
+ $select_op->add(Q($this->gettext('countislessthan')), 'count-lt');
+ $select_op->add(Q($this->gettext('countislessthanequal')), 'count-le');
+ $select_op->add(Q($this->gettext('countequals')), 'count-eq');
+ $select_op->add(Q($this->gettext('countnotequals')), 'count-ne');
+ $select_op->add(Q($this->gettext('valueisgreaterthan')), 'value-gt');
+ $select_op->add(Q($this->gettext('valueisgreaterthanequal')), 'value-ge');
+ $select_op->add(Q($this->gettext('valueislessthan')), 'value-lt');
+ $select_op->add(Q($this->gettext('valueislessthanequal')), 'value-le');
+ $select_op->add(Q($this->gettext('valueequals')), 'value-eq');
+ $select_op->add(Q($this->gettext('valuenotequals')), 'value-ne');
+ }
// target input (TODO: lists)
@@ -897,7 +915,7 @@ class managesieve extends rcube_plugin
}
else if ($rule['test'] == 'size') {
$out .= $select_op->show();
- if(preg_match('/^([0-9]+)(K|M|G)*$/', $rule['arg'], $matches)) {
+ if (preg_match('/^([0-9]+)(K|M|G)*$/', $rule['arg'], $matches)) {
$sizetarget = $matches[1];
$sizeitem = $matches[2];
}