diff options
| author | Tristan Zur <tzur@web.web.ccwn.org> | 2014-03-27 22:27:47 +0100 |
|---|---|---|
| committer | Tristan Zur <tzur@web.web.ccwn.org> | 2014-03-27 22:27:47 +0100 |
| commit | b62676ca5d3d6f6ba3f019ea3f99722e165a98d8 (patch) | |
| tree | 86722cb80f07d4569f90088eeaea2fc2f6e2ef94 /webmail/plugins/managesieve/tests | |
Diffstat (limited to 'webmail/plugins/managesieve/tests')
31 files changed, 861 insertions, 0 deletions
diff --git a/webmail/plugins/managesieve/tests/Makefile b/webmail/plugins/managesieve/tests/Makefile new file mode 100644 index 0000000..072be2f --- /dev/null +++ b/webmail/plugins/managesieve/tests/Makefile @@ -0,0 +1,7 @@ + +clean: + rm -f *.log *.php *.diff *.exp *.out + + +test: + pear run-tests *.phpt diff --git a/webmail/plugins/managesieve/tests/Managesieve.php b/webmail/plugins/managesieve/tests/Managesieve.php new file mode 100644 index 0000000..d802f56 --- /dev/null +++ b/webmail/plugins/managesieve/tests/Managesieve.php @@ -0,0 +1,23 @@ +<?php + +class Managesieve_Plugin extends PHPUnit_Framework_TestCase +{ + + function setUp() + { + include_once dirname(__FILE__) . '/../managesieve.php'; + } + + /** + * Plugin object construction test + */ + function test_constructor() + { + $rcube = rcube::get_instance(); + $plugin = new managesieve($rcube->api); + + $this->assertInstanceOf('managesieve', $plugin); + $this->assertInstanceOf('rcube_plugin', $plugin); + } +} + diff --git a/webmail/plugins/managesieve/tests/Parser.php b/webmail/plugins/managesieve/tests/Parser.php new file mode 100644 index 0000000..9050f09 --- /dev/null +++ b/webmail/plugins/managesieve/tests/Parser.php @@ -0,0 +1,62 @@ +<?php + +class Parser extends PHPUnit_Framework_TestCase +{ + + function setUp() + { + include_once dirname(__FILE__) . '/../lib/Roundcube/rcube_sieve_script.php'; + } + + /** + * Sieve script parsing + * + * @dataProvider data_parser + */ + function test_parser($input, $output, $message) + { + // get capabilities list from the script + $caps = array(); + if (preg_match('/require \[([a-z0-9", ]+)\]/', $input, $m)) { + foreach (explode(',', $m[1]) as $cap) { + $caps[] = trim($cap, '" '); + } + } + + $script = new rcube_sieve_script($input, $caps); + $result = $script->as_text(); + + $this->assertEquals(trim($result), trim($output), $message); + } + + /** + * Data provider for test_parser() + */ + function data_parser() + { + $dir_path = realpath(dirname(__FILE__) . '/src'); + $dir = opendir($dir_path); + $result = array(); + + while ($file = readdir($dir)) { + if (preg_match('/^[a-z0-9_]+$/', $file)) { + $input = file_get_contents($dir_path . '/' . $file); + + if (file_exists($dir_path . '/' . $file . '.out')) { + $output = file_get_contents($dir_path . '/' . $file . '.out'); + } + else { + $output = $input; + } + + $result[] = array( + 'input' => $input, + 'output' => $output, + 'message' => "Error in parsing '$file' file", + ); + } + } + + return $result; + } +} diff --git a/webmail/plugins/managesieve/tests/Tokenizer.php b/webmail/plugins/managesieve/tests/Tokenizer.php new file mode 100644 index 0000000..e71bae0 --- /dev/null +++ b/webmail/plugins/managesieve/tests/Tokenizer.php @@ -0,0 +1,33 @@ +<?php + +class Tokenizer extends PHPUnit_Framework_TestCase +{ + + function setUp() + { + include_once dirname(__FILE__) . '/../lib/Roundcube/rcube_sieve_script.php'; + } + + function data_tokenizer() + { + return array( + array(1, "text: #test\nThis is test ; message;\nMulti line\n.\n;\n", '"This is test ; message;\nMulti line"'), + array(0, '["test1","test2"]', '[["test1","test2"]]'), + array(1, '["test"]', '["test"]'), + array(1, '"te\\"st"', '"te\\"st"'), + array(0, 'test #comment', '["test"]'), + array(0, "text:\ntest\n.\ntext:\ntest\n.\n", '["test","test"]'), + array(1, '"\\a\\\\\\"a"', '"a\\\\\\"a"'), + ); + } + + /** + * @dataProvider data_tokenizer + */ + function test_tokenizer($num, $input, $output) + { + $res = json_encode(rcube_sieve_script::tokenize($input, $num)); + + $this->assertEquals(trim($res), trim($output)); + } +} diff --git a/webmail/plugins/managesieve/tests/parser.phpt b/webmail/plugins/managesieve/tests/parser.phpt new file mode 100644 index 0000000..aec0421 --- /dev/null +++ b/webmail/plugins/managesieve/tests/parser.phpt @@ -0,0 +1,120 @@ +--TEST-- +Main test of script parser +--SKIPIF-- +--FILE-- +<?php +include '../lib/rcube_sieve_script.php'; + +$txt = ' +require ["fileinto","reject","envelope"]; +# rule:[spam] +if anyof (header :contains "X-DSPAM-Result" "Spam") +{ + fileinto "Spam"; + stop; +} +# rule:[test1] +if anyof (header :comparator "i;ascii-casemap" :contains ["From","To"] "test@domain.tld") +{ + discard; + stop; +} +# rule:[test2] +if anyof (not header :comparator "i;octet" :contains ["Subject"] "[test]", header :contains "Subject" "[test2]") +{ + fileinto "test"; + stop; +} +# rule:[comments] +if anyof (true) /* comment + * "comment" #comment */ { + /* comment */ stop; +# comment +} +# rule:[reject] +if size :over 5000K { + 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; +} +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","reject","envelope"]; +# rule:[spam] +if header :contains "X-DSPAM-Result" "Spam" +{ + fileinto "Spam"; + stop; +} +# rule:[test1] +if header :contains ["From","To"] "test@domain.tld" +{ + discard; + stop; +} +# rule:[test2] +if anyof (not header :comparator "i;octet" :contains "Subject" "[test]", header :contains "Subject" "[test2]") +{ + fileinto "test"; + stop; +} +# rule:[comments] +if true +{ + stop; +} +# rule:[reject] +if size :over 5000K +{ + reject "Message over 5MB size limit. Please contact me before sending this."; +} +# rule:[false] +if false # size :over 5000K +{ + stop; +} +# rule:[true] +if true +{ + 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/webmail/plugins/managesieve/tests/parser_body.phpt b/webmail/plugins/managesieve/tests/parser_body.phpt new file mode 100644 index 0000000..08ad549 --- /dev/null +++ b/webmail/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/webmail/plugins/managesieve/tests/parser_imapflags.phpt b/webmail/plugins/managesieve/tests/parser_imapflags.phpt new file mode 100644 index 0000000..a4bc465 --- /dev/null +++ b/webmail/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/webmail/plugins/managesieve/tests/parser_include.phpt b/webmail/plugins/managesieve/tests/parser_include.phpt new file mode 100644 index 0000000..addc0d4 --- /dev/null +++ b/webmail/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/webmail/plugins/managesieve/tests/parser_kep14.phpt b/webmail/plugins/managesieve/tests/parser_kep14.phpt new file mode 100644 index 0000000..dcdbd48 --- /dev/null +++ b/webmail/plugins/managesieve/tests/parser_kep14.phpt @@ -0,0 +1,19 @@ +--TEST-- +Test of Kolab's KEP:14 implementation +--SKIPIF-- +--FILE-- +<?php +include '../lib/rcube_sieve_script.php'; + +$txt = ' +# EDITOR Roundcube +# EDITOR_VERSION 123 +'; + +$s = new rcube_sieve_script($txt, array('body')); +echo $s->as_text(); + +?> +--EXPECT-- +# EDITOR Roundcube +# EDITOR_VERSION 123 diff --git a/webmail/plugins/managesieve/tests/parser_prefix.phpt b/webmail/plugins/managesieve/tests/parser_prefix.phpt new file mode 100644 index 0000000..c87e965 --- /dev/null +++ b/webmail/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/webmail/plugins/managesieve/tests/parser_relational.phpt b/webmail/plugins/managesieve/tests/parser_relational.phpt new file mode 100644 index 0000000..6b6f29f --- /dev/null +++ b/webmail/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/webmail/plugins/managesieve/tests/parser_vacation.phpt b/webmail/plugins/managesieve/tests/parser_vacation.phpt new file mode 100644 index 0000000..a603ff6 --- /dev/null +++ b/webmail/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/webmail/plugins/managesieve/tests/parser_variables.phpt b/webmail/plugins/managesieve/tests/parser_variables.phpt new file mode 100644 index 0000000..cf1f8fc --- /dev/null +++ b/webmail/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/webmail/plugins/managesieve/tests/parset_subaddress.phpt b/webmail/plugins/managesieve/tests/parset_subaddress.phpt new file mode 100644 index 0000000..6d4d03c --- /dev/null +++ b/webmail/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; +} diff --git a/webmail/plugins/managesieve/tests/src/parser b/webmail/plugins/managesieve/tests/src/parser new file mode 100644 index 0000000..9c4717b --- /dev/null +++ b/webmail/plugins/managesieve/tests/src/parser @@ -0,0 +1,52 @@ +require ["fileinto","reject","envelope"]; +# rule:[spam] +if anyof (header :contains "X-DSPAM-Result" "Spam") +{ + fileinto "Spam"; + stop; +} +# rule:[test1] +if anyof (header :comparator "i;ascii-casemap" :contains ["From","To"] "test@domain.tld") +{ + discard; + stop; +} +# rule:[test2] +if anyof (not header :comparator "i;octet" :contains ["Subject"] "[test]", header :contains "Subject" "[test2]") +{ + fileinto "test"; + stop; +} +# rule:[comments] +if anyof (true) /* comment + * "comment" #comment */ { + /* comment */ stop; +# comment +} +# rule:[reject] +if size :over 5000K { + 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; +} +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/webmail/plugins/managesieve/tests/src/parser.out b/webmail/plugins/managesieve/tests/src/parser.out new file mode 100644 index 0000000..385c889 --- /dev/null +++ b/webmail/plugins/managesieve/tests/src/parser.out @@ -0,0 +1,52 @@ +require ["fileinto","reject","envelope"]; +# rule:[spam] +if header :contains "X-DSPAM-Result" "Spam" +{ + fileinto "Spam"; + stop; +} +# rule:[test1] +if header :contains ["From","To"] "test@domain.tld" +{ + discard; + stop; +} +# rule:[test2] +if anyof (not header :comparator "i;octet" :contains "Subject" "[test]", header :contains "Subject" "[test2]") +{ + fileinto "test"; + stop; +} +# rule:[comments] +if true +{ + stop; +} +# rule:[reject] +if size :over 5000K +{ + reject "Message over 5MB size limit. Please contact me before sending this."; +} +# rule:[false] +if false # size :over 5000K +{ + stop; +} +# rule:[true] +if true +{ + 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/webmail/plugins/managesieve/tests/src/parser_body b/webmail/plugins/managesieve/tests/src/parser_body new file mode 100644 index 0000000..bd142ed --- /dev/null +++ b/webmail/plugins/managesieve/tests/src/parser_body @@ -0,0 +1,17 @@ +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/webmail/plugins/managesieve/tests/src/parser_enotify_a b/webmail/plugins/managesieve/tests/src/parser_enotify_a new file mode 100644 index 0000000..68a9ef5 --- /dev/null +++ b/webmail/plugins/managesieve/tests/src/parser_enotify_a @@ -0,0 +1,19 @@ +require ["enotify","variables"]; +# rule:[notify1] +if header :contains "from" "boss@example.org" +{ + notify :importance "1" :message "This is probably very important" "mailto:alm@example.com"; + stop; +} +# rule:[subject] +if header :matches "Subject" "*" +{ + set "subject" "${1}"; +} +# rule:[from notify2] +if header :matches "From" "*" +{ + set "from" "${1}"; + notify :importance "3" :message "${from}: ${subject}" "mailto:alm@example.com"; +} + diff --git a/webmail/plugins/managesieve/tests/src/parser_enotify_b b/webmail/plugins/managesieve/tests/src/parser_enotify_b new file mode 100644 index 0000000..8854658 --- /dev/null +++ b/webmail/plugins/managesieve/tests/src/parser_enotify_b @@ -0,0 +1,18 @@ +require ["envelope","variables","enotify"]; +# rule:[from] +if envelope :all :matches "from" "*" +{ + set "env_from" " [really: ${1}]"; +} +# rule:[subject] +if header :matches "Subject" "*" +{ + set "subject" "${1}"; +} +# rule:[from notify] +if address :all :matches "from" "*" +{ + set "from_addr" "${1}"; + notify :message "${from_addr}${env_from}: ${subject}" "mailto:alm@example.com"; +} + diff --git a/webmail/plugins/managesieve/tests/src/parser_imapflags b/webmail/plugins/managesieve/tests/src/parser_imapflags new file mode 100644 index 0000000..e67bf7c --- /dev/null +++ b/webmail/plugins/managesieve/tests/src/parser_imapflags @@ -0,0 +1,7 @@ +require ["imap4flags"]; +# rule:[imapflags] +if header :matches "Subject" "^Test$" +{ + setflag "\\Seen"; + addflag ["\\Answered","\\Deleted"]; +} diff --git a/webmail/plugins/managesieve/tests/src/parser_include b/webmail/plugins/managesieve/tests/src/parser_include new file mode 100644 index 0000000..b5585a4 --- /dev/null +++ b/webmail/plugins/managesieve/tests/src/parser_include @@ -0,0 +1,7 @@ +require ["include"]; +include "script.sieve"; +# rule:[two] +if true +{ + include :optional "second.sieve"; +} diff --git a/webmail/plugins/managesieve/tests/src/parser_kep14 b/webmail/plugins/managesieve/tests/src/parser_kep14 new file mode 100644 index 0000000..1ded8d8 --- /dev/null +++ b/webmail/plugins/managesieve/tests/src/parser_kep14 @@ -0,0 +1,2 @@ +# EDITOR Roundcube +# EDITOR_VERSION 123 diff --git a/webmail/plugins/managesieve/tests/src/parser_kep14.out b/webmail/plugins/managesieve/tests/src/parser_kep14.out new file mode 100644 index 0000000..cb7faa7 --- /dev/null +++ b/webmail/plugins/managesieve/tests/src/parser_kep14.out @@ -0,0 +1,3 @@ +require ["variables"]; +set "EDITOR" "Roundcube"; +set "EDITOR_VERSION" "123"; diff --git a/webmail/plugins/managesieve/tests/src/parser_notify_a b/webmail/plugins/managesieve/tests/src/parser_notify_a new file mode 100644 index 0000000..f1a5754 --- /dev/null +++ b/webmail/plugins/managesieve/tests/src/parser_notify_a @@ -0,0 +1,18 @@ +require ["notify","variables"]; +# rule:[notify1] +if header :contains "from" "boss@example.org" +{ + notify :low :message "This is probably very important"; + stop; +} +# rule:[subject] +if header :matches "Subject" "*" +{ + set "subject" "${1}"; +} +# rule:[from notify2] +if header :matches "From" "*" +{ + set "from" "${1}"; + notify :high :message "${from}: ${subject}" :method "mailto:test@example.org"; +} diff --git a/webmail/plugins/managesieve/tests/src/parser_notify_b b/webmail/plugins/managesieve/tests/src/parser_notify_b new file mode 100644 index 0000000..cf80a97 --- /dev/null +++ b/webmail/plugins/managesieve/tests/src/parser_notify_b @@ -0,0 +1,17 @@ +require ["envelope","variables","notify"]; +# rule:[from] +if envelope :all :matches "from" "*" +{ + set "env_from" " [really: ${1}]"; +} +# rule:[subject] +if header :matches "Subject" "*" +{ + set "subject" "${1}"; +} +# rule:[from notify] +if address :all :matches "from" "*" +{ + set "from_addr" "${1}"; + notify :message "${from_addr}${env_from}: ${subject}" :method "sms:1234567890"; +} diff --git a/webmail/plugins/managesieve/tests/src/parser_prefix b/webmail/plugins/managesieve/tests/src/parser_prefix new file mode 100644 index 0000000..9f6a33a --- /dev/null +++ b/webmail/plugins/managesieve/tests/src/parser_prefix @@ -0,0 +1,5 @@ +# this is a comment +# and the second line + +require ["variables"]; +set "b" "c"; diff --git a/webmail/plugins/managesieve/tests/src/parser_relational b/webmail/plugins/managesieve/tests/src/parser_relational new file mode 100644 index 0000000..0a92fde --- /dev/null +++ b/webmail/plugins/managesieve/tests/src/parser_relational @@ -0,0 +1,6 @@ +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/webmail/plugins/managesieve/tests/src/parser_subaddress b/webmail/plugins/managesieve/tests/src/parser_subaddress new file mode 100644 index 0000000..f106b79 --- /dev/null +++ b/webmail/plugins/managesieve/tests/src/parser_subaddress @@ -0,0 +1,11 @@ +require ["envelope","subaddress","fileinto"]; +if envelope :user "To" "postmaster" +{ + fileinto "postmaster"; + stop; +} +if envelope :detail :is "To" "mta-filters" +{ + fileinto "mta-filters"; + stop; +} diff --git a/webmail/plugins/managesieve/tests/src/parser_vacation b/webmail/plugins/managesieve/tests/src/parser_vacation new file mode 100644 index 0000000..93026db --- /dev/null +++ b/webmail/plugins/managesieve/tests/src/parser_vacation @@ -0,0 +1,12 @@ +require ["vacation"]; +# rule:[test-vacation] +if header :contains "Subject" "vacation" +{ + vacation :days 1 text: +# test +test test /* test */ +test +. +; + stop; +} diff --git a/webmail/plugins/managesieve/tests/src/parser_variables b/webmail/plugins/managesieve/tests/src/parser_variables new file mode 100644 index 0000000..bd5941c --- /dev/null +++ b/webmail/plugins/managesieve/tests/src/parser_variables @@ -0,0 +1,12 @@ +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/webmail/plugins/managesieve/tests/tokenize.phpt b/webmail/plugins/managesieve/tests/tokenize.phpt new file mode 100644 index 0000000..f988653 --- /dev/null +++ b/webmail/plugins/managesieve/tests/tokenize.phpt @@ -0,0 +1,66 @@ +--TEST-- +Script parsing: tokenizer +--SKIPIF-- +--FILE-- +<?php +include '../lib/rcube_sieve_script.php'; + +$txt[1] = array(1, 'text: #test +This is test ; message; +Multi line +. +; +'); +$txt[2] = array(0, '["test1","test2"]'); +$txt[3] = array(1, '["test"]'); +$txt[4] = array(1, '"te\\"st"'); +$txt[5] = array(0, 'test #comment'); +$txt[6] = array(0, 'text: +test +. +text: +test +. +'); +$txt[7] = array(1, '"\\a\\\\\\"a"'); + +foreach ($txt as $idx => $t) { + echo "[$idx]---------------\n"; + var_dump(rcube_sieve_script::tokenize($t[1], $t[0])); +} +?> +--EXPECT-- +[1]--------------- +string(34) "This is test ; message; +Multi line" +[2]--------------- +array(1) { + [0]=> + array(2) { + [0]=> + string(5) "test1" + [1]=> + string(5) "test2" + } +} +[3]--------------- +array(1) { + [0]=> + string(4) "test" +} +[4]--------------- +string(5) "te"st" +[5]--------------- +array(1) { + [0]=> + string(4) "test" +} +[6]--------------- +array(2) { + [0]=> + string(4) "test" + [1]=> + string(4) "test" +} +[7]--------------- +string(4) "a\"a" |
