summaryrefslogtreecommitdiff
path: root/plugins/managesieve
diff options
context:
space:
mode:
authoralec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c>2011-01-23 10:35:29 +0000
committeralec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c>2011-01-23 10:35:29 +0000
commit8148ffbbc015f3aeccfe1c7b6c460c5866f513c5 (patch)
tree5ecf884c5174a98d524d84751b12ab2d9da99ae5 /plugins/managesieve
parent6fe2e9bb18c88740a4cfb70c8b84cce394997898 (diff)
- More tests + some script output improvments
git-svn-id: https://svn.roundcube.net/trunk@4451 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'plugins/managesieve')
-rw-r--r--plugins/managesieve/lib/rcube_sieve.php34
-rw-r--r--plugins/managesieve/tests/parser.phpt35
2 files changed, 49 insertions, 20 deletions
diff --git a/plugins/managesieve/lib/rcube_sieve.php b/plugins/managesieve/lib/rcube_sieve.php
index 7389470ec..4fde86a53 100644
--- a/plugins/managesieve/lib/rcube_sieve.php
+++ b/plugins/managesieve/lib/rcube_sieve.php
@@ -538,17 +538,26 @@ class rcube_sieve_script
$i++;
}
-// $script .= ($idx>0 ? 'els' : '').($rule['join'] ? 'if allof (' : 'if anyof (');
// disabled rule: if false #....
- $script .= 'if' . ($rule['disabled'] ? ' false #' : '');
- $script .= $rule['join'] ? ' allof (' : ' anyof (';
- if (sizeof($tests) > 1)
- $script .= implode(", ", $tests);
- else if (sizeof($tests))
- $script .= $tests[0];
- else
- $script .= 'true';
- $script .= ")\n{\n";
+ $script .= 'if ' . ($rule['disabled'] ? 'false # ' : '');
+
+ if (empty($tests)) {
+ $tests_str = 'true';
+ }
+ else if (count($tests) > 1) {
+ $tests_str = implode(', ', $tests);
+ }
+ else {
+ $tests_str = $tests[0];
+ }
+
+ if ($rule['join'] || count($tests) > 1) {
+ $script .= sprintf('%s (%s)', $rule['join'] ? 'allof' : 'anyof', $tests_str);
+ }
+ else {
+ $script .= $tests_str;
+ }
+ $script .= "\n{\n";
// action(s)
foreach ($rule['actions'] as $action) {
@@ -879,12 +888,15 @@ class rcube_sieve_script
*/
static function escape_string($str)
{
- if (is_array($str)) {
+ if (is_array($str) && count($str) > 1) {
foreach($str as $idx => $val)
$str[$idx] = self::escape_string($val);
return '[' . implode(',', $str) . ']';
}
+ else if (is_array($str)) {
+ $str = array_pop($str);
+ }
// multi-line string
if (preg_match('/[\r\n\0]/', $str)) {
diff --git a/plugins/managesieve/tests/parser.phpt b/plugins/managesieve/tests/parser.phpt
index 27952eb1f..a3b820d45 100644
--- a/plugins/managesieve/tests/parser.phpt
+++ b/plugins/managesieve/tests/parser.phpt
@@ -6,7 +6,7 @@ Main test of script parser
include('../lib/rcube_sieve.php');
$txt = '
-require ["fileinto","vacation"];
+require ["fileinto","vacation","reject","relational","comparator-i;ascii-numeric"];
# rule:[spam]
if anyof (header :contains "X-DSPAM-Result" "Spam")
{
@@ -16,11 +16,11 @@ if anyof (header :contains "X-DSPAM-Result" "Spam")
# rule:[test1]
if anyof (header :contains ["From","To"] "test@domain.tld")
{
- fileinto "roundcube-trac";
+ discard;
stop;
}
# rule:[test2]
-if anyof (not header :contains "Subject" "[test]", header :contains "Subject" "[test2]")
+if anyof (not header :contains ["Subject"] "[test]", header :contains "Subject" "[test2]")
{
fileinto "test";
stop;
@@ -42,6 +42,13 @@ if anyof (true) /* comment
/* comment */ stop;
# comment
}
+# rule:[reject]
+if size :over 5000K {
+ reject "Message over 5MB size limit. Please contact me before sending this.";
+}
+# rule:[redirect]
+if header :value "ge" :comparator "i;ascii-numeric"
+ ["X-Spam-score"] ["14"] {redirect "test@test.tld";}
';
$s = new rcube_sieve_script($txt);
@@ -49,17 +56,17 @@ echo $s->as_text();
?>
--EXPECT--
-require ["fileinto","vacation"];
+require ["fileinto","vacation","reject","relational","comparator-i;ascii-numeric"];
# rule:[spam]
-if anyof (header :contains "X-DSPAM-Result" "Spam")
+if header :contains "X-DSPAM-Result" "Spam"
{
fileinto "Spam";
stop;
}
# rule:[test1]
-if anyof (header :contains ["From","To"] "test@domain.tld")
+if header :contains ["From","To"] "test@domain.tld"
{
- fileinto "roundcube-trac";
+ discard;
stop;
}
# rule:[test2]
@@ -69,7 +76,7 @@ if anyof (not header :contains "Subject" "[test]", header :contains "Subject" "[
stop;
}
# rule:[test-vacation]
-if anyof (header :contains "Subject" "vacation")
+if header :contains "Subject" "vacation"
{
vacation :days 1 text:
# test
@@ -80,7 +87,17 @@ test
stop;
}
# rule:[comments]
-if anyof (true)
+if true
{
stop;
}
+# rule:[reject]
+if size :over 5000K
+{
+ reject "Message over 5MB size limit. Please contact me before sending this.";
+}
+# rule:[redirect]
+if header :value "ge" :comparator "i;ascii-numeric" "X-Spam-score" "14"
+{
+ redirect "test@test.tld";
+}