From b5652641be7ebf4f1b7f115333989d2c971275ea Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Fri, 31 Aug 2012 09:55:00 +0200 Subject: Small improvements in APPEND command handling --- program/include/rcube_imap.php | 4 ++++ program/include/rcube_imap_generic.php | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php index 5dd9c1250..66b5c4bd6 100644 --- a/program/include/rcube_imap.php +++ b/program/include/rcube_imap.php @@ -2222,6 +2222,10 @@ class rcube_imap extends rcube_storage $folder = $this->folder; } + if (!$this->check_connection()) { + return false; + } + // make sure folder exists if ($this->folder_exists($folder)) { if ($is_file) { diff --git a/program/include/rcube_imap_generic.php b/program/include/rcube_imap_generic.php index 915a11aad..c3cfabc3a 100644 --- a/program/include/rcube_imap_generic.php +++ b/program/include/rcube_imap_generic.php @@ -2538,7 +2538,7 @@ class rcube_imap_generic { unset($this->data['APPENDUID']); - if (!$mailbox) { + if ($mailbox === null || $mailbox === '') { return false; } @@ -2603,7 +2603,7 @@ class rcube_imap_generic { unset($this->data['APPENDUID']); - if (!$mailbox) { + if ($mailbox === null || $mailbox === '') { return false; } @@ -2612,6 +2612,7 @@ class rcube_imap_generic if (file_exists(realpath($path))) { $in_fp = fopen($path, 'r'); } + if (!$in_fp) { $this->setError(self::ERROR_UNKNOWN, "Couldn't open $path for reading"); return false; -- cgit v1.2.3 From afa0b1df58d93059686f00017a111185e5ee2674 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Fri, 31 Aug 2012 15:01:21 +0200 Subject: Use setUp() instead of __construct() --- tests/MailFunc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/MailFunc.php b/tests/MailFunc.php index 57a6b9d10..967277c2a 100644 --- a/tests/MailFunc.php +++ b/tests/MailFunc.php @@ -8,7 +8,7 @@ class MailFunc extends PHPUnit_Framework_TestCase { - function __construct() + function setUp() { // simulate environment to successfully include func.inc $GLOBALS['RCMAIL'] = $RCMAIL = rcmail::get_instance(); -- cgit v1.2.3 From 4bb0bffefe3d0772f10bfd4acc3e8ccb1193211d Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Fri, 31 Aug 2012 15:06:33 +0200 Subject: Convert managesieve test scripts to PHPUnit, add them to the suite --- plugins/managesieve/tests/Makefile | 7 -- plugins/managesieve/tests/Parser.php | 54 ++++++++++ plugins/managesieve/tests/Tokenizer.php | 33 +++++++ plugins/managesieve/tests/parser.phpt | 120 ----------------------- plugins/managesieve/tests/parser_body.phpt | 49 --------- plugins/managesieve/tests/parser_imapflags.phpt | 28 ------ plugins/managesieve/tests/parser_include.phpt | 30 ------ plugins/managesieve/tests/parser_kep14.phpt | 19 ---- plugins/managesieve/tests/parser_prefix.phpt | 25 ----- plugins/managesieve/tests/parser_relational.phpt | 25 ----- plugins/managesieve/tests/parser_vacation.phpt | 39 -------- plugins/managesieve/tests/parser_variables.phpt | 39 -------- plugins/managesieve/tests/parset_subaddress.phpt | 38 ------- plugins/managesieve/tests/src/parser | 52 ++++++++++ plugins/managesieve/tests/src/parser.out | 52 ++++++++++ plugins/managesieve/tests/src/parser_body | 17 ++++ plugins/managesieve/tests/src/parser_imapflags | 7 ++ plugins/managesieve/tests/src/parser_include | 7 ++ plugins/managesieve/tests/src/parser_kep14 | 2 + plugins/managesieve/tests/src/parser_prefix | 5 + plugins/managesieve/tests/src/parser_relational | 6 ++ plugins/managesieve/tests/src/parser_subaddress | 11 +++ plugins/managesieve/tests/src/parser_vacation | 12 +++ plugins/managesieve/tests/src/parser_variables | 12 +++ plugins/managesieve/tests/tokenize.phpt | 66 ------------- tests/HtmlToText.php | 4 +- tests/phpunit.xml | 4 + 27 files changed, 276 insertions(+), 487 deletions(-) delete mode 100644 plugins/managesieve/tests/Makefile create mode 100644 plugins/managesieve/tests/Parser.php create mode 100644 plugins/managesieve/tests/Tokenizer.php delete mode 100644 plugins/managesieve/tests/parser.phpt delete mode 100644 plugins/managesieve/tests/parser_body.phpt delete mode 100644 plugins/managesieve/tests/parser_imapflags.phpt delete mode 100644 plugins/managesieve/tests/parser_include.phpt delete mode 100644 plugins/managesieve/tests/parser_kep14.phpt delete mode 100644 plugins/managesieve/tests/parser_prefix.phpt delete mode 100644 plugins/managesieve/tests/parser_relational.phpt delete mode 100644 plugins/managesieve/tests/parser_vacation.phpt delete mode 100644 plugins/managesieve/tests/parser_variables.phpt delete mode 100644 plugins/managesieve/tests/parset_subaddress.phpt create mode 100644 plugins/managesieve/tests/src/parser create mode 100644 plugins/managesieve/tests/src/parser.out create mode 100644 plugins/managesieve/tests/src/parser_body create mode 100644 plugins/managesieve/tests/src/parser_imapflags create mode 100644 plugins/managesieve/tests/src/parser_include create mode 100644 plugins/managesieve/tests/src/parser_kep14 create mode 100644 plugins/managesieve/tests/src/parser_prefix create mode 100644 plugins/managesieve/tests/src/parser_relational create mode 100644 plugins/managesieve/tests/src/parser_subaddress create mode 100644 plugins/managesieve/tests/src/parser_vacation create mode 100644 plugins/managesieve/tests/src/parser_variables delete mode 100644 plugins/managesieve/tests/tokenize.phpt diff --git a/plugins/managesieve/tests/Makefile b/plugins/managesieve/tests/Makefile deleted file mode 100644 index 072be2f2c..000000000 --- a/plugins/managesieve/tests/Makefile +++ /dev/null @@ -1,7 +0,0 @@ - -clean: - rm -f *.log *.php *.diff *.exp *.out - - -test: - pear run-tests *.phpt diff --git a/plugins/managesieve/tests/Parser.php b/plugins/managesieve/tests/Parser.php new file mode 100644 index 000000000..06b644b34 --- /dev/null +++ b/plugins/managesieve/tests/Parser.php @@ -0,0 +1,54 @@ +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-z_]+$/', $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/plugins/managesieve/tests/Tokenizer.php b/plugins/managesieve/tests/Tokenizer.php new file mode 100644 index 000000000..8c0bced23 --- /dev/null +++ b/plugins/managesieve/tests/Tokenizer.php @@ -0,0 +1,33 @@ +assertEquals(trim($res), trim($output)); + } +} diff --git a/plugins/managesieve/tests/parser.phpt b/plugins/managesieve/tests/parser.phpt deleted file mode 100644 index aec042187..000000000 --- a/plugins/managesieve/tests/parser.phpt +++ /dev/null @@ -1,120 +0,0 @@ ---TEST-- -Main test of script parser ---SKIPIF-- ---FILE-- -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/plugins/managesieve/tests/parser_body.phpt b/plugins/managesieve/tests/parser_body.phpt deleted file mode 100644 index 08ad54959..000000000 --- a/plugins/managesieve/tests/parser_body.phpt +++ /dev/null @@ -1,49 +0,0 @@ ---TEST-- -Test of Sieve body extension (RFC5173) ---SKIPIF-- ---FILE-- -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 deleted file mode 100644 index a4bc465a3..000000000 --- a/plugins/managesieve/tests/parser_imapflags.phpt +++ /dev/null @@ -1,28 +0,0 @@ ---TEST-- -Test of Sieve vacation extension (RFC5232) ---SKIPIF-- ---FILE-- -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 deleted file mode 100644 index addc0d449..000000000 --- a/plugins/managesieve/tests/parser_include.phpt +++ /dev/null @@ -1,30 +0,0 @@ ---TEST-- -Test of Sieve include extension ---SKIPIF-- ---FILE-- -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 deleted file mode 100644 index dcdbd48a0..000000000 --- a/plugins/managesieve/tests/parser_kep14.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -Test of Kolab's KEP:14 implementation ---SKIPIF-- ---FILE-- -as_text(); - -?> ---EXPECT-- -# EDITOR Roundcube -# EDITOR_VERSION 123 diff --git a/plugins/managesieve/tests/parser_prefix.phpt b/plugins/managesieve/tests/parser_prefix.phpt deleted file mode 100644 index c87e9658f..000000000 --- a/plugins/managesieve/tests/parser_prefix.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -Test of prefix comments handling ---SKIPIF-- ---FILE-- -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 deleted file mode 100644 index 6b6f29f4c..000000000 --- a/plugins/managesieve/tests/parser_relational.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -Test of Sieve relational extension (RFC5231) ---SKIPIF-- ---FILE-- -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 deleted file mode 100644 index a603ff6c1..000000000 --- a/plugins/managesieve/tests/parser_vacation.phpt +++ /dev/null @@ -1,39 +0,0 @@ ---TEST-- -Test of Sieve vacation extension (RFC5230) ---SKIPIF-- ---FILE-- -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 deleted file mode 100644 index cf1f8fcad..000000000 --- a/plugins/managesieve/tests/parser_variables.phpt +++ /dev/null @@ -1,39 +0,0 @@ ---TEST-- -Test of Sieve variables extension ---SKIPIF-- ---FILE-- -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 deleted file mode 100644 index 6d4d03c6e..000000000 --- a/plugins/managesieve/tests/parset_subaddress.phpt +++ /dev/null @@ -1,38 +0,0 @@ ---TEST-- -Test of Sieve subaddress extension (RFC5233) ---SKIPIF-- ---FILE-- -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/plugins/managesieve/tests/src/parser b/plugins/managesieve/tests/src/parser new file mode 100644 index 000000000..9c4717be4 --- /dev/null +++ b/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/plugins/managesieve/tests/src/parser.out b/plugins/managesieve/tests/src/parser.out new file mode 100644 index 000000000..385c8890d --- /dev/null +++ b/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/plugins/managesieve/tests/src/parser_body b/plugins/managesieve/tests/src/parser_body new file mode 100644 index 000000000..bd142ed8c --- /dev/null +++ b/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/plugins/managesieve/tests/src/parser_imapflags b/plugins/managesieve/tests/src/parser_imapflags new file mode 100644 index 000000000..e67bf7cfc --- /dev/null +++ b/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/plugins/managesieve/tests/src/parser_include b/plugins/managesieve/tests/src/parser_include new file mode 100644 index 000000000..b5585a4ba --- /dev/null +++ b/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/plugins/managesieve/tests/src/parser_kep14 b/plugins/managesieve/tests/src/parser_kep14 new file mode 100644 index 000000000..1ded8d8d4 --- /dev/null +++ b/plugins/managesieve/tests/src/parser_kep14 @@ -0,0 +1,2 @@ +# EDITOR Roundcube +# EDITOR_VERSION 123 diff --git a/plugins/managesieve/tests/src/parser_prefix b/plugins/managesieve/tests/src/parser_prefix new file mode 100644 index 000000000..9f6a33a1c --- /dev/null +++ b/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/plugins/managesieve/tests/src/parser_relational b/plugins/managesieve/tests/src/parser_relational new file mode 100644 index 000000000..0a92fde54 --- /dev/null +++ b/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/plugins/managesieve/tests/src/parser_subaddress b/plugins/managesieve/tests/src/parser_subaddress new file mode 100644 index 000000000..f106b796e --- /dev/null +++ b/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/plugins/managesieve/tests/src/parser_vacation b/plugins/managesieve/tests/src/parser_vacation new file mode 100644 index 000000000..93026db45 --- /dev/null +++ b/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/plugins/managesieve/tests/src/parser_variables b/plugins/managesieve/tests/src/parser_variables new file mode 100644 index 000000000..bd5941c02 --- /dev/null +++ b/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/plugins/managesieve/tests/tokenize.phpt b/plugins/managesieve/tests/tokenize.phpt deleted file mode 100644 index f988653ee..000000000 --- a/plugins/managesieve/tests/tokenize.phpt +++ /dev/null @@ -1,66 +0,0 @@ ---TEST-- -Script parsing: tokenizer ---SKIPIF-- ---FILE-- - $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" diff --git a/tests/HtmlToText.php b/tests/HtmlToText.php index 34e2d1a63..b90c61adf 100644 --- a/tests/HtmlToText.php +++ b/tests/HtmlToText.php @@ -8,7 +8,7 @@ class HtmlToText extends PHPUnit_Framework_TestCase { - function data() + function data_html2text() { return array( 0 => array( @@ -45,7 +45,7 @@ class HtmlToText extends PHPUnit_Framework_TestCase } /** - * @dataProvider data + * @dataProvider data_html2text */ function test_html2text($title, $in, $out) { diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 28f7e7420..8b3883223 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -29,5 +29,9 @@ HtmlToText.php MailFunc.php + + ./../plugins/managesieve/tests/Parser.php + ./../plugins/managesieve/tests/Tokenizer.php + -- cgit v1.2.3