summaryrefslogtreecommitdiff
path: root/plugins/managesieve/tests
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2011-11-18 14:44:48 +0000
committeralecpl <alec@alec.pl>2011-11-18 14:44:48 +0000
commitc994e0e7cd9f593eb21ff80c7c1ddbeaf2a1b12a (patch)
tree44bf85e3a9f96cd13fb82d263cbf068f317fb21c /plugins/managesieve/tests
parentbdb649067d8cd5bdfa584a21d0a8664f8f89f2d3 (diff)
- Applied fixes from trunk up to r5451
Diffstat (limited to 'plugins/managesieve/tests')
-rw-r--r--plugins/managesieve/tests/parser.phpt90
-rw-r--r--plugins/managesieve/tests/parser_body.phpt49
-rw-r--r--plugins/managesieve/tests/parser_imapflags.phpt28
-rw-r--r--plugins/managesieve/tests/parser_include.phpt30
-rw-r--r--plugins/managesieve/tests/parser_kep14.phpt2
-rw-r--r--plugins/managesieve/tests/parser_prefix.phpt25
-rw-r--r--plugins/managesieve/tests/parser_relational.phpt25
-rw-r--r--plugins/managesieve/tests/parser_vacation.phpt39
-rw-r--r--plugins/managesieve/tests/parser_variables.phpt39
-rw-r--r--plugins/managesieve/tests/parset_subaddress.phpt38
10 files changed, 322 insertions, 43 deletions
diff --git a/plugins/managesieve/tests/parser.phpt b/plugins/managesieve/tests/parser.phpt
index d70353459..aec042187 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_script.php';
$txt = '
-require ["fileinto","vacation","reject","relational","comparator-i;ascii-numeric","imapflags"];
+require ["fileinto","reject","envelope"];
# rule:[spam]
if anyof (header :contains "X-DSPAM-Result" "Spam")
{
@@ -14,28 +14,17 @@ if anyof (header :contains "X-DSPAM-Result" "Spam")
stop;
}
# rule:[test1]
-if anyof (header :contains ["From","To"] "test@domain.tld")
+if anyof (header :comparator "i;ascii-casemap" :contains ["From","To"] "test@domain.tld")
{
discard;
stop;
}
# rule:[test2]
-if anyof (not header :contains ["Subject"] "[test]", header :contains "Subject" "[test2]")
+if anyof (not header :comparator "i;octet" :contains ["Subject"] "[test]", header :contains "Subject" "[test2]")
{
fileinto "test";
stop;
}
-# rule:[test-vacation]
-if anyof (header :contains "Subject" "vacation")
-{
- vacation :days 1 text:
-# test
-test test /* test */
-test
-.
-;
- stop;
-}
# rule:[comments]
if anyof (true) /* comment
* "comment" #comment */ {
@@ -44,24 +33,40 @@ if anyof (true) /* comment
}
# rule:[reject]
if size :over 5000K {
- reject "Message over 5MB size limit. Please contact me before sending this.";
+ reject "Message over 5MB size limit. Please contact me before sending this.";
+}
+# rule:[false]
+if false # size :over 5000K
+{
+ stop; /* rule disabled */
+}
+# rule:[true]
+if true
+{
+ stop;
}
-# rule:[redirect]
-if header :value "ge" :comparator "i;ascii-numeric"
- ["X-Spam-score"] ["14"] {redirect "test@test.tld";}
-# rule:[imapflags]
-if header :matches "Subject" "^Test$" {
- setflag "\\\\Seen";
- addflag ["\\\\Answered","\\\\Deleted"];
+fileinto "Test";
+# rule:[address test]
+if address :all :is "From" "nagios@domain.tld"
+{
+ fileinto "domain.tld";
+ stop;
+}
+# rule:[envelope test]
+if envelope :domain :is "From" "domain.tld"
+{
+ fileinto "domain.tld";
+ stop;
}
';
$s = new rcube_sieve_script($txt);
echo $s->as_text();
+// -------------------------------------------------------------------------------
?>
--EXPECT--
-require ["fileinto","vacation","reject","relational","comparator-i;ascii-numeric","imapflags"];
+require ["fileinto","reject","envelope"];
# rule:[spam]
if header :contains "X-DSPAM-Result" "Spam"
{
@@ -75,22 +80,11 @@ if header :contains ["From","To"] "test@domain.tld"
stop;
}
# rule:[test2]
-if anyof (not header :contains "Subject" "[test]", header :contains "Subject" "[test2]")
+if anyof (not header :comparator "i;octet" :contains "Subject" "[test]", header :contains "Subject" "[test2]")
{
fileinto "test";
stop;
}
-# rule:[test-vacation]
-if header :contains "Subject" "vacation"
-{
- vacation :days 1 text:
-# test
-test test /* test */
-test
-.
-;
- stop;
-}
# rule:[comments]
if true
{
@@ -101,14 +95,26 @@ 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"
+# rule:[false]
+if false # size :over 5000K
{
- redirect "test@test.tld";
+ stop;
}
-# rule:[imapflags]
-if header :matches "Subject" "^Test$"
+# rule:[true]
+if true
{
- setflag "\\Seen";
- addflag ["\\Answered","\\Deleted"];
+ stop;
+}
+fileinto "Test";
+# rule:[address test]
+if address :all :is "From" "nagios@domain.tld"
+{
+ fileinto "domain.tld";
+ stop;
+}
+# rule:[envelope test]
+if envelope :domain :is "From" "domain.tld"
+{
+ fileinto "domain.tld";
+ stop;
}
diff --git a/plugins/managesieve/tests/parser_body.phpt b/plugins/managesieve/tests/parser_body.phpt
new file mode 100644
index 000000000..08ad54959
--- /dev/null
+++ b/plugins/managesieve/tests/parser_body.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Test of Sieve body extension (RFC5173)
+--SKIPIF--
+--FILE--
+<?php
+include '../lib/rcube_sieve_script.php';
+
+$txt = '
+require ["body","fileinto"];
+if body :raw :contains "MAKE MONEY FAST"
+{
+ stop;
+}
+if body :content "text" :contains ["missile","coordinates"]
+{
+ fileinto "secrets";
+}
+if body :content "audio/mp3" :contains ""
+{
+ fileinto "jukebox";
+}
+if body :text :contains "project schedule"
+{
+ fileinto "project/schedule";
+}
+';
+
+$s = new rcube_sieve_script($txt);
+echo $s->as_text();
+
+?>
+--EXPECT--
+require ["body","fileinto"];
+if body :raw :contains "MAKE MONEY FAST"
+{
+ stop;
+}
+if body :content "text" :contains ["missile","coordinates"]
+{
+ fileinto "secrets";
+}
+if body :content "audio/mp3" :contains ""
+{
+ fileinto "jukebox";
+}
+if body :text :contains "project schedule"
+{
+ fileinto "project/schedule";
+}
diff --git a/plugins/managesieve/tests/parser_imapflags.phpt b/plugins/managesieve/tests/parser_imapflags.phpt
new file mode 100644
index 000000000..a4bc465a3
--- /dev/null
+++ b/plugins/managesieve/tests/parser_imapflags.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Test of Sieve vacation extension (RFC5232)
+--SKIPIF--
+--FILE--
+<?php
+include '../lib/rcube_sieve_script.php';
+
+$txt = '
+require ["imapflags"];
+# rule:[imapflags]
+if header :matches "Subject" "^Test$" {
+ setflag "\\\\Seen";
+ addflag ["\\\\Answered","\\\\Deleted"];
+}
+';
+
+$s = new rcube_sieve_script($txt, array('imapflags'));
+echo $s->as_text();
+
+?>
+--EXPECT--
+require ["imapflags"];
+# rule:[imapflags]
+if header :matches "Subject" "^Test$"
+{
+ setflag "\\Seen";
+ addflag ["\\Answered","\\Deleted"];
+}
diff --git a/plugins/managesieve/tests/parser_include.phpt b/plugins/managesieve/tests/parser_include.phpt
new file mode 100644
index 000000000..addc0d449
--- /dev/null
+++ b/plugins/managesieve/tests/parser_include.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Test of Sieve include extension
+--SKIPIF--
+--FILE--
+<?php
+include '../lib/rcube_sieve_script.php';
+
+$txt = '
+require ["include"];
+
+include "script.sieve";
+# rule:[two]
+if true
+{
+ include :optional "second.sieve";
+}
+';
+
+$s = new rcube_sieve_script($txt, array(), array('variables'));
+echo $s->as_text();
+
+?>
+--EXPECT--
+require ["include"];
+include "script.sieve";
+# rule:[two]
+if true
+{
+ include :optional "second.sieve";
+}
diff --git a/plugins/managesieve/tests/parser_kep14.phpt b/plugins/managesieve/tests/parser_kep14.phpt
index 06beaeda1..dcdbd48a0 100644
--- a/plugins/managesieve/tests/parser_kep14.phpt
+++ b/plugins/managesieve/tests/parser_kep14.phpt
@@ -10,7 +10,7 @@ $txt = '
# EDITOR_VERSION 123
';
-$s = new rcube_sieve_script($txt, array());
+$s = new rcube_sieve_script($txt, array('body'));
echo $s->as_text();
?>
diff --git a/plugins/managesieve/tests/parser_prefix.phpt b/plugins/managesieve/tests/parser_prefix.phpt
new file mode 100644
index 000000000..c87e9658f
--- /dev/null
+++ b/plugins/managesieve/tests/parser_prefix.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Test of prefix comments handling
+--SKIPIF--
+--FILE--
+<?php
+include '../lib/rcube_sieve_script.php';
+
+$txt = '
+# this is a comment
+# and the second line
+
+require ["variables"];
+set "b" "c";
+';
+
+$s = new rcube_sieve_script($txt, array(), array('variables'));
+echo $s->as_text();
+
+?>
+--EXPECT--
+# this is a comment
+# and the second line
+
+require ["variables"];
+set "b" "c";
diff --git a/plugins/managesieve/tests/parser_relational.phpt b/plugins/managesieve/tests/parser_relational.phpt
new file mode 100644
index 000000000..6b6f29f4c
--- /dev/null
+++ b/plugins/managesieve/tests/parser_relational.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Test of Sieve relational extension (RFC5231)
+--SKIPIF--
+--FILE--
+<?php
+include '../lib/rcube_sieve_script.php';
+
+$txt = '
+require ["relational","comparator-i;ascii-numeric"];
+# rule:[redirect]
+if header :value "ge" :comparator "i;ascii-numeric"
+ ["X-Spam-score"] ["14"] {redirect "test@test.tld";}
+';
+
+$s = new rcube_sieve_script($txt);
+echo $s->as_text();
+
+?>
+--EXPECT--
+require ["relational","comparator-i;ascii-numeric"];
+# rule:[redirect]
+if header :value "ge" :comparator "i;ascii-numeric" "X-Spam-score" "14"
+{
+ redirect "test@test.tld";
+}
diff --git a/plugins/managesieve/tests/parser_vacation.phpt b/plugins/managesieve/tests/parser_vacation.phpt
new file mode 100644
index 000000000..a603ff6c1
--- /dev/null
+++ b/plugins/managesieve/tests/parser_vacation.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Test of Sieve vacation extension (RFC5230)
+--SKIPIF--
+--FILE--
+<?php
+include '../lib/rcube_sieve_script.php';
+
+$txt = '
+require ["vacation"];
+# rule:[test-vacation]
+if anyof (header :contains "Subject" "vacation")
+{
+ vacation :days 1 text:
+# test
+test test /* test */
+test
+.
+;
+ stop;
+}
+';
+
+$s = new rcube_sieve_script($txt);
+echo $s->as_text();
+
+?>
+--EXPECT--
+require ["vacation"];
+# rule:[test-vacation]
+if header :contains "Subject" "vacation"
+{
+ vacation :days 1 text:
+# test
+test test /* test */
+test
+.
+;
+ stop;
+}
diff --git a/plugins/managesieve/tests/parser_variables.phpt b/plugins/managesieve/tests/parser_variables.phpt
new file mode 100644
index 000000000..cf1f8fcad
--- /dev/null
+++ b/plugins/managesieve/tests/parser_variables.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Test of Sieve variables extension
+--SKIPIF--
+--FILE--
+<?php
+include '../lib/rcube_sieve_script.php';
+
+$txt = '
+require ["variables"];
+set "honorific" "Mr";
+set "vacation" text:
+Dear ${HONORIFIC} ${last_name},
+I am out, please leave a message after the meep.
+.
+;
+set :length "b" "${a}";
+set :lower "b" "${a}";
+set :upperfirst "b" "${a}";
+set :upperfirst :lower "b" "${a}";
+set :quotewildcard "b" "Rock*";
+';
+
+$s = new rcube_sieve_script($txt, array(), array('variables'));
+echo $s->as_text();
+
+?>
+--EXPECT--
+require ["variables"];
+set "honorific" "Mr";
+set "vacation" text:
+Dear ${HONORIFIC} ${last_name},
+I am out, please leave a message after the meep.
+.
+;
+set :length "b" "${a}";
+set :lower "b" "${a}";
+set :upperfirst "b" "${a}";
+set :upperfirst :lower "b" "${a}";
+set :quotewildcard "b" "Rock*";
diff --git a/plugins/managesieve/tests/parset_subaddress.phpt b/plugins/managesieve/tests/parset_subaddress.phpt
new file mode 100644
index 000000000..6d4d03c6e
--- /dev/null
+++ b/plugins/managesieve/tests/parset_subaddress.phpt
@@ -0,0 +1,38 @@
+--TEST--
+Test of Sieve subaddress extension (RFC5233)
+--SKIPIF--
+--FILE--
+<?php
+include '../lib/rcube_sieve_script.php';
+
+$txt = '
+require ["envelope","subaddress","fileinto"];
+if envelope :user "To" "postmaster"
+{
+ fileinto "postmaster";
+ stop;
+}
+if envelope :detail :is "To" "mta-filters"
+{
+ fileinto "mta-filters";
+ stop;
+}
+';
+
+$s = new rcube_sieve_script($txt);
+echo $s->as_text();
+
+// -------------------------------------------------------------------------------
+?>
+--EXPECT--
+require ["envelope","subaddress","fileinto"];
+if envelope :user "To" "postmaster"
+{
+ fileinto "postmaster";
+ stop;
+}
+if envelope :detail :is "To" "mta-filters"
+{
+ fileinto "mta-filters";
+ stop;
+}