From 5aaffc8095eeb69407855b33d1939dd5ebd619ca Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Tue, 1 Dec 2020 15:18:54 +0000 Subject: Backport IMAP test modernization to PHP-8.0 branch Closes GH-6476 --- azure/setup.yml | 4 +- ext/imap/tests/CONFLICTS | 1 - ext/imap/tests/README.md | 6 +- ext/imap/tests/bug31142_2.phpt | 4 +- ext/imap/tests/bug32589.phpt | 4 +- ext/imap/tests/bug35669.phpt | 56 +++--- ext/imap/tests/bug44098.phpt | 13 +- ext/imap/tests/bug45705_1.phpt | 4 +- ext/imap/tests/bug45705_2.phpt | 4 +- ext/imap/tests/bug53377.phpt | 4 +- ext/imap/tests/bug63126.phpt | 13 +- ext/imap/tests/bug64076.phpt | 11 +- ext/imap/tests/bug77020.phpt | 6 +- ext/imap/tests/bug77153.phpt | 10 +- ext/imap/tests/bug80213.phpt | 7 +- ext/imap/tests/bug80226.phpt | 21 ++- ext/imap/tests/bug80438.phpt | 4 +- ext/imap/tests/clean.inc | 25 --- ext/imap/tests/dovecot.conf | 33 ---- ext/imap/tests/dovecotpass | 1 - ext/imap/tests/imap_append_basic.phpt | 18 +- ext/imap/tests/imap_body.phpt | 23 ++- ext/imap/tests/imap_body_basic.phpt | 18 +- ext/imap/tests/imap_bodystruct_basic.phpt | 69 +++----- ext/imap/tests/imap_clearflag_full_basic.phpt | 16 +- ext/imap/tests/imap_close_basic.phpt | 15 +- ext/imap/tests/imap_close_variation4.phpt | 17 +- ext/imap/tests/imap_createmailbox_basic.phpt | 16 +- ext/imap/tests/imap_errors_basic.phpt | 6 +- ext/imap/tests/imap_fetch_overview_basic.phpt | 11 +- ext/imap/tests/imap_fetch_overview_variation3.phpt | 26 +-- ext/imap/tests/imap_fetch_overview_variation5.phpt | 31 ++-- ext/imap/tests/imap_fetch_overview_variation6.phpt | 13 +- ext/imap/tests/imap_fetchbody_basic.phpt | 11 +- ext/imap/tests/imap_fetchbody_variation4.phpt | 13 +- ext/imap/tests/imap_fetchbody_variation6.phpt | 15 +- ext/imap/tests/imap_fetchheader_basic.phpt | 11 +- ext/imap/tests/imap_fetchheader_variation3.phpt | 13 +- ext/imap/tests/imap_fetchheader_variation5.phpt | 11 +- ext/imap/tests/imap_fetchstructure_basic.phpt | 11 +- ext/imap/tests/imap_gc_error.phpt | 16 +- ext/imap/tests/imap_getsubscribed_basic.phpt | 19 +- ext/imap/tests/imap_headerinfo_basic.phpt | 11 +- ext/imap/tests/imap_include.inc | 196 --------------------- ext/imap/tests/imap_list_basic.phpt | 14 +- ext/imap/tests/imap_lsub_basic.phpt | 21 ++- ext/imap/tests/imap_mail_copy_basic.phpt | 19 +- ext/imap/tests/imap_mail_move_basic.phpt | 19 +- ext/imap/tests/imap_mutf7_to_utf8.phpt | 1 - ext/imap/tests/imap_open_error.phpt | 6 +- ext/imap/tests/imap_renamemailbox_basic.phpt | 24 +-- .../tests/imap_rfc822_parse_headers_basic.phpt | 11 +- ext/imap/tests/imap_savebody_basic.phpt | 11 +- ext/imap/tests/imap_timeout_basic.phpt | 2 +- ext/imap/tests/imap_undelete_basic.phpt | 13 +- ext/imap/tests/imap_utf8.phpt | 4 +- ext/imap/tests/imap_utf8_to_mutf7_basic.phpt | 1 - ext/imap/tests/setup.sh | 6 - ext/imap/tests/setup/clean.inc | 32 ++++ ext/imap/tests/setup/dovecot.conf | 33 ++++ ext/imap/tests/setup/dovecotpass | 1 + ext/imap/tests/setup/imap_include.inc | 190 ++++++++++++++++++++ ext/imap/tests/setup/setup.sh | 6 + ext/imap/tests/setup/skipif.inc | 13 ++ ext/imap/tests/skipif.inc | 16 -- 65 files changed, 648 insertions(+), 632 deletions(-) delete mode 100644 ext/imap/tests/CONFLICTS delete mode 100644 ext/imap/tests/clean.inc delete mode 100644 ext/imap/tests/dovecot.conf delete mode 100644 ext/imap/tests/dovecotpass delete mode 100644 ext/imap/tests/imap_include.inc delete mode 100644 ext/imap/tests/setup.sh create mode 100644 ext/imap/tests/setup/clean.inc create mode 100644 ext/imap/tests/setup/dovecot.conf create mode 100644 ext/imap/tests/setup/dovecotpass create mode 100644 ext/imap/tests/setup/imap_include.inc create mode 100644 ext/imap/tests/setup/setup.sh create mode 100644 ext/imap/tests/setup/skipif.inc delete mode 100644 ext/imap/tests/skipif.inc diff --git a/azure/setup.yml b/azure/setup.yml index e0b4dc79da..489df88159 100644 --- a/azure/setup.yml +++ b/azure/setup.yml @@ -20,8 +20,8 @@ steps: set -e sudo groupadd -g 5000 vmail sudo useradd -m -d /var/vmail -s /bin/false -u 5000 -g vmail vmail - sudo cp ext/imap/tests/dovecot.conf /etc/dovecot/dovecot.conf - sudo cp ext/imap/tests/dovecotpass /etc/dovecot/dovecotpass + sudo cp ext/imap/tests/setup/dovecot.conf /etc/dovecot/dovecot.conf + sudo cp ext/imap/tests/setup/dovecotpass /etc/dovecot/dovecotpass sudo service dovecot restart displayName: 'Configure IMAP' diff --git a/ext/imap/tests/CONFLICTS b/ext/imap/tests/CONFLICTS deleted file mode 100644 index c301c0ffac..0000000000 --- a/ext/imap/tests/CONFLICTS +++ /dev/null @@ -1 +0,0 @@ -imap diff --git a/ext/imap/tests/README.md b/ext/imap/tests/README.md index 6324ab7f9e..1dee1d2663 100644 --- a/ext/imap/tests/README.md +++ b/ext/imap/tests/README.md @@ -11,14 +11,14 @@ hMailServer on Windows. The tests are intended to be mailserver agnostic. ## Set-up tests on Ubuntu (checked on Ubuntu 18.04 (Bionic)) The necessary packages can be installed using the following command; -`apt-get install libc-client-dev libkrb5-dev dovecot-core dovecot-pop3d dovecot-imapd` +`apt-get install libc-client-dev libkrb5-dev dovecot-core dovecot-pop3d dovecot-imapd sendmail` The build of PHP will need to be compiled with the following flags: ``` --with-imap --with-kerberos --with-imap-ssl ``` -Then run the set-up script `ext/imap/tests/setup.sh` which will add the `vmail` +Then run the set-up script `ext/imap/tests/setup/setup.sh` which will add the `vmail` group and user which is used by Dovecot for the mailbox. It will also copy the -`ext/imap/tests/dovecot.conf` and `ext/imap/tests/dovecotpass` to the correct +`ext/imap/tests/setup/dovecot.conf` and `ext/imap/tests/setup/dovecotpass` to the correct location for Dovecot and restarts it for the new configuration to be enabled. diff --git a/ext/imap/tests/bug31142_2.phpt b/ext/imap/tests/bug31142_2.phpt index 004c054963..dbb4c9a6ad 100644 --- a/ext/imap/tests/bug31142_2.phpt +++ b/ext/imap/tests/bug31142_2.phpt @@ -2,9 +2,7 @@ Bug #31142 test #2 (imap_mail_compose() generates incorrect output) --SKIPIF-- --FILE-- --FILE-- --FILE-- '; - $envelope["to"] = 'The bad smurf '; - $envelope['date'] = 'Wed, 04 Jan 2006 19:24:43 -0500'; +$envelope["from"] = 'Santa '; +$envelope["to"] = 'The bad smurf '; +$envelope['date'] = 'Wed, 04 Jan 2006 19:24:43 -0500'; - $multipart["type"] = TYPEMULTIPART; - $multipart["subtype"] = "MIXED"; - $body[] = $multipart; //add multipart stuff +$multipart["type"] = TYPEMULTIPART; +$multipart["subtype"] = "MIXED"; +$body[] = $multipart; //add multipart stuff - $textpart["type"] = TYPEMULTIPART; - $textpart["subtype"] = "ALTERNATIVE"; - $body[] = $textpart; //add body part +$textpart["type"] = TYPEMULTIPART; +$textpart["subtype"] = "ALTERNATIVE"; +$body[] = $textpart; //add body part - $plain["type"] = TYPETEXT; - $plain["subtype"] = "PLAIN"; - $plain["charset"] = "iso-8859-1"; - $plain["encoding"] = ENCQUOTEDPRINTABLE; - $plain["description"] = "Plaintype part of message"; - $plain['disposition'] = "inline"; - $plain["contents.data"] = 'See mom, it will crash'; +$plain["type"] = TYPETEXT; +$plain["subtype"] = "PLAIN"; +$plain["charset"] = "iso-8859-1"; +$plain["encoding"] = ENCQUOTEDPRINTABLE; +$plain["description"] = "Plaintype part of message"; +$plain['disposition'] = "inline"; +$plain["contents.data"] = 'See mom, it will crash'; - $body[] = $plain; //next add plain text part +$body[] = $plain; //next add plain text part - $html["type"] = TYPETEXT; - $html["subtype"] = "HTML"; - $html["charset"] = "iso-8859-1"; - $html["encoding"] = ENCQUOTEDPRINTABLE; - $html["description"] = "HTML part of message"; - $html['disposition'] = "inline"; - $html["contents.data"] = 'See mom, it will crash'; +$html["type"] = TYPETEXT; +$html["subtype"] = "HTML"; +$html["charset"] = "iso-8859-1"; +$html["encoding"] = ENCQUOTEDPRINTABLE; +$html["description"] = "HTML part of message"; +$html['disposition'] = "inline"; +$html["contents.data"] = 'See mom, it will crash'; - $body[] = $html; +$body[] = $html; - echo imap_mail_compose($envelope, $body); +echo imap_mail_compose($envelope, $body); ?> --EXPECTF-- Date: Wed, 04 Jan 2006 19:24:43 -0500 diff --git a/ext/imap/tests/bug44098.phpt b/ext/imap/tests/bug44098.phpt index 2a0f5cef44..2e0f025d6a 100644 --- a/ext/imap/tests/bug44098.phpt +++ b/ext/imap/tests/bug44098.phpt @@ -2,19 +2,14 @@ Bug #44098 (imap_utf8() returns only capital letters) --SKIPIF-- --FILE-- , expected \n"; -} else { - echo "ok"; -} +var_dump($res); + ?> --EXPECT-- -ok +string(17) "LuzonĀ®14 dot CoM" diff --git a/ext/imap/tests/bug45705_1.phpt b/ext/imap/tests/bug45705_1.phpt index 05d3a0a2f6..b8d33e6758 100644 --- a/ext/imap/tests/bug45705_1.phpt +++ b/ext/imap/tests/bug45705_1.phpt @@ -2,9 +2,7 @@ Bug #45705 test #1 (imap rfc822_parse_adrlist() modifies passed address parameter) --SKIPIF-- --FILE-- --FILE-- --FILE-- +--CONFLICTS-- +defaultmailbox --FILE-- array('DISABLE_AUTHENTICATOR' => array('GSSAPI','NTLM')), 'String' => array('DISABLE_AUTHENTICATOR' => 'GSSAPI'), ); -require_once(__DIR__.'/imap_include.inc'); +require_once(__DIR__. '/setup/imap_include.inc'); foreach ($tests as $name => $testparams) { echo "Test for $name\n"; - $in = imap_open($default_mailbox, $username, $password, OP_HALFOPEN, 1, $testparams); + $in = imap_open(IMAP_SERVER_DEBUG, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD, OP_HALFOPEN, 1, $testparams); if ($in) { if (is_array($errors = imap_errors())) { foreach ($errors as $err) { diff --git a/ext/imap/tests/bug64076.phpt b/ext/imap/tests/bug64076.phpt index ccafcfe251..7e9ee6fd04 100644 --- a/ext/imap/tests/bug64076.phpt +++ b/ext/imap/tests/bug64076.phpt @@ -2,22 +2,23 @@ Bug #64076 (imap_sort() does not return FALSE on failure) --SKIPIF-- --FILE-- --CLEAN-- --EXPECT-- Create a temporary mailbox and add 2 msgs -.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created +New mailbox created bool(false) bool(true) diff --git a/ext/imap/tests/bug77020.phpt b/ext/imap/tests/bug77020.phpt index 43c8133700..d828654983 100644 --- a/ext/imap/tests/bug77020.phpt +++ b/ext/imap/tests/bug77020.phpt @@ -6,8 +6,8 @@ if (!extension_loaded('imap')) die('skip imap extension not available'); ?> --FILE-- --EXPECTF-- -Warning: imap_mail(): No message string in mail command in %s on line %d -%S +%Adone diff --git a/ext/imap/tests/bug77153.phpt b/ext/imap/tests/bug77153.phpt index 7b759621fe..d767ce5472 100644 --- a/ext/imap/tests/bug77153.phpt +++ b/ext/imap/tests/bug77153.phpt @@ -1,11 +1,11 @@ ---TEST-- +--TEST-- Bug #77153 (imap_open allows to run arbitrary shell commands via mailbox parameter) --SKIPIF-- +--CONFLICTS-- +defaultmailbox --FILE-- " . __DIR__ . '/__bug'; @@ -21,4 +21,4 @@ bool(false) --CLEAN-- \ No newline at end of file +?> diff --git a/ext/imap/tests/bug80213.phpt b/ext/imap/tests/bug80213.phpt index 9a7961df77..5bad48f306 100644 --- a/ext/imap/tests/bug80213.phpt +++ b/ext/imap/tests/bug80213.phpt @@ -14,8 +14,13 @@ $body = [[ 'type.parameters' => ['param'], 'disposition' => ['disp'], ]]; -imap_mail_compose($envelope, $body); +var_dump(imap_mail_compose($envelope, $body)); echo "done\n"; ?> --EXPECT-- +string(67) "MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; CHARSET=US-ASCII + + +" done diff --git a/ext/imap/tests/bug80226.phpt b/ext/imap/tests/bug80226.phpt index 95ec235178..6cf4cc8a58 100644 --- a/ext/imap/tests/bug80226.phpt +++ b/ext/imap/tests/bug80226.phpt @@ -2,12 +2,25 @@ Bug #80226 (imap_sort() leaks sortpgm memory) --SKIPIF-- --FILE-- +--CLEAN-- + --EXPECT-- +Create a new mailbox for test +Create a temporary mailbox and add 0 msgs +New mailbox created +array(0) { +} diff --git a/ext/imap/tests/bug80438.phpt b/ext/imap/tests/bug80438.phpt index 12a1416a7e..4514e932ef 100644 --- a/ext/imap/tests/bug80438.phpt +++ b/ext/imap/tests/bug80438.phpt @@ -2,11 +2,10 @@ Bug #80438: imap_msgno() incorrectly warns and return false on valid UIDs in PHP 8.0.0 --SKIPIF-- --FILE-- --EXPECT-- -*** Testing imap_fetch_overview() : basic functionality *** Create a temporary mailbox and add 10 msgs New mailbox created array(6) { diff --git a/ext/imap/tests/clean.inc b/ext/imap/tests/clean.inc deleted file mode 100644 index 8bc566ba32..0000000000 --- a/ext/imap/tests/clean.inc +++ /dev/null @@ -1,25 +0,0 @@ -Nmsgs; $i++) { - imap_delete($imap_stream, $i); -} - -$mailboxes = imap_getmailboxes($imap_stream, $server, '*'); - -foreach($mailboxes as $value) { - // Only delete mailboxes with our prefix - if (preg_match('/\{.*?\}INBOX\.(.+)/', $value->name, $match) == 1) { - if (strlen($match[1]) >= strlen($mailbox_prefix) - && substr_compare($match[1], $mailbox_prefix, 0, strlen($mailbox_prefix)) == 0) { - imap_deletemailbox($imap_stream, $value->name); - } - } -} - -imap_close($imap_stream, CL_EXPUNGE); -?> diff --git a/ext/imap/tests/dovecot.conf b/ext/imap/tests/dovecot.conf deleted file mode 100644 index c465ba3ce9..0000000000 --- a/ext/imap/tests/dovecot.conf +++ /dev/null @@ -1,33 +0,0 @@ -# 2.2.33.2 (d6601f4ec): /etc/dovecot/dovecot.conf -# Pigeonhole version 0.4.21 (92477967) -listen = *, :: - -# To make authentication work -ssl = no -disable_plaintext_auth = no - -auth_mechanisms = plain cram-md5 -auth_username_format = %u -auth_debug = yes -auth_verbose = yes -#log -log_path = /var/log/dovecot.log -# If not set, use the value from log_path -info_log_path = /var/log/dovecot-info.log -# If not set, use the value from info_log_path -debug_log_path = /var/log/dovecot-debug.log -## Mailbox locations and namespaces -mail_location = maildir:/var/vmail/dovecot/mail/%d/%n/Maildir -passdb { - args = scheme=cram-md5 /etc/dovecot/dovecotpass - driver = passwd-file -} -protocols = imap -service auth { - user = root -} -userdb { - args = /etc/dovecot/dovecotpass - driver = passwd-file - override_fields = home=/var/vmail/dovecot/mail/%d/%n -} diff --git a/ext/imap/tests/dovecotpass b/ext/imap/tests/dovecotpass deleted file mode 100644 index 86a069fc4f..0000000000 --- a/ext/imap/tests/dovecotpass +++ /dev/null @@ -1 +0,0 @@ -webmaster@something.com:{CRAM-MD5}be5f3177e9c7c06403272f25d983ba630df4ef40476b353bb3087a8401713451:vmail:vmail diff --git a/ext/imap/tests/imap_append_basic.phpt b/ext/imap/tests/imap_append_basic.phpt index e75b452596..ab2e46886e 100644 --- a/ext/imap/tests/imap_append_basic.phpt +++ b/ext/imap/tests/imap_append_basic.phpt @@ -2,22 +2,19 @@ Test imap_append() function : basic functionality --SKIPIF-- --FILE-- Mailbox . "\n"; +echo "Add a couple of msgs to the new mailbox\n"; var_dump(imap_append($imap_stream, $mb_details->Mailbox , "From: webmaster@something.com\r\n" . "To: info@something.com\r\n" @@ -44,14 +41,15 @@ imap_close($imap_stream); ?> --CLEAN-- --EXPECTF-- *** Testing imap_append() : basic functionality *** Create a new mailbox for test Create a temporary mailbox and add 0 msgs -.. mailbox '%s' created -Add a couple of msgs to new mailbox {%s}INBOX.%s +New mailbox created +Add a couple of msgs to the new mailbox bool(true) bool(true) Msg Count after append : 2 diff --git a/ext/imap/tests/imap_body.phpt b/ext/imap/tests/imap_body.phpt index 6c2f629398..59678ad539 100644 --- a/ext/imap/tests/imap_body.phpt +++ b/ext/imap/tests/imap_body.phpt @@ -5,33 +5,40 @@ Paul Sohier #phptestfest utrecht --SKIPIF-- --FILE-- getMessage() . \PHP_EOL; } try { - imap_body($stream_id,1,-1); + imap_body($imap_stream,1,-1); } catch (\ValueError $e) { echo $e->getMessage() . \PHP_EOL; } //Access not existing -var_dump(imap_body($stream_id, 255, FT_UID)); +var_dump(imap_body($imap_stream, 255, FT_UID)); -imap_close($stream_id); +imap_close($imap_stream); +?> +--CLEAN-- + --EXPECTF-- +Create a temporary mailbox and add 0 msgs +New mailbox created imap_body(): Argument #2 ($message_num) must be greater than 0 imap_body(): Argument #3 ($flags) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL diff --git a/ext/imap/tests/imap_body_basic.phpt b/ext/imap/tests/imap_body_basic.phpt index 3034785a90..b5cb0fcd33 100644 --- a/ext/imap/tests/imap_body_basic.phpt +++ b/ext/imap/tests/imap_body_basic.phpt @@ -2,19 +2,16 @@ Test imap_body() function : basic functionality --SKIPIF-- --FILE-- Nmsgs . "\n"; @@ -29,15 +26,16 @@ imap_close($imap_stream); ?> --CLEAN-- --EXPECTF-- *** Testing imap_body() : basic functionality *** Create a new mailbox for test Create a temporary mailbox and add 1 msgs -.. mailbox '%s' created +New mailbox created Msg Count in new mailbox: 1 string(%d) "1: this is a test message, please ignore -" +newline%r\R?%r" string(%d) "1: this is a test message, please ignore -" +newline%r\R?%r" diff --git a/ext/imap/tests/imap_bodystruct_basic.phpt b/ext/imap/tests/imap_bodystruct_basic.phpt index 56c88399c3..f969e86764 100644 --- a/ext/imap/tests/imap_bodystruct_basic.phpt +++ b/ext/imap/tests/imap_bodystruct_basic.phpt @@ -2,47 +2,43 @@ Test imap_bodystruct() function : basic functionality --SKIPIF-- --FILE-- $mf)) - { - echo "$mf is 0 or 1\n"; - } - else - { - echo "$mf FAIL\n"; - } +foreach($mandatoryFields as $mf) { + if (isValid($m->$mf)) { + echo "$mf is 0 or 1\n"; + } else { + echo "$mf FAIL\n"; + } } -if(is_array($m->parameters)) -{ - echo "parameters is an array\n"; +if(is_array($m->parameters)) { + echo "parameters is an array\n"; } echo "\nTry to get part 4!\n"; @@ -50,28 +46,17 @@ var_dump(imap_bodystruct($imap_stream, 1, "4")); imap_close($imap_stream); -function isValid($param) -{ - if(($param == 0) || ($param == 1)) - { - $result=true; - } - else - { - $result=false; - } -return $result; -} ?> --CLEAN-- ---EXPECTF-- +--EXPECT-- *** Testing string imap_bodystruct : basic functionality *** Create a new mailbox for test and add a multipart msgs Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created +New mailbox created Get and validate structure of body part 1 ifsubtype is 0 or 1 diff --git a/ext/imap/tests/imap_clearflag_full_basic.phpt b/ext/imap/tests/imap_clearflag_full_basic.phpt index cc949385fc..ee65d202ce 100644 --- a/ext/imap/tests/imap_clearflag_full_basic.phpt +++ b/ext/imap/tests/imap_clearflag_full_basic.phpt @@ -2,19 +2,16 @@ Test imap_clearflag_full() function : basic functionality --SKIPIF-- --FILE-- Nmsgs . "\n"; @@ -44,13 +41,14 @@ imap_close($imap_stream); ?> --CLEAN-- ---EXPECTF-- +--EXPECT-- *** Testing imap_clearflag_full() : basic functionality *** Create a new mailbox for test Create a temporary mailbox and add 10 msgs -.. mailbox '{%s}%s' created +New mailbox created Initial msg count in new_mailbox : 10 Set some flags bool(true) diff --git a/ext/imap/tests/imap_close_basic.phpt b/ext/imap/tests/imap_close_basic.phpt index 57b2e7eab1..c962b62f7f 100644 --- a/ext/imap/tests/imap_close_basic.phpt +++ b/ext/imap/tests/imap_close_basic.phpt @@ -2,17 +2,17 @@ Test imap_close() function : basic functionality --SKIPIF-- --FILE-- --CLEAN-- --EXPECTF-- *** Testing imap_close() : basic functionality *** Create a temporary mailbox and add 3 msgs -.. mailbox '%sINBOX.phpttest' created +New mailbox created -- Call to imap_close() with all possible arguments -- bool(true) -There are now 0 msgs in mailbox '%sINBOX.phpttest' +There are now 0 msgs in mailbox '%sINBOX.phpttestimapclosebasic' -- Call to imap_close() with mandatory arguments -- bool(true) diff --git a/ext/imap/tests/imap_close_variation4.phpt b/ext/imap/tests/imap_close_variation4.phpt index b57f607f88..ff78ac985c 100644 --- a/ext/imap/tests/imap_close_variation4.phpt +++ b/ext/imap/tests/imap_close_variation4.phpt @@ -2,7 +2,7 @@ Test imap_close() function : usage variations - different ints as $flags arg --SKIPIF-- --FILE-- --CLEAN-- ---EXPECTF-- +--EXPECT-- *** Testing imap_close() : usage variations *** Create a temporary mailbox and add 3 msgs -.. mailbox '{%s}%s' created +New mailbox created -- Iteration 1 -- bool(true) diff --git a/ext/imap/tests/imap_createmailbox_basic.phpt b/ext/imap/tests/imap_createmailbox_basic.phpt index 84db5cbd31..83dc3d0f6e 100644 --- a/ext/imap/tests/imap_createmailbox_basic.phpt +++ b/ext/imap/tests/imap_createmailbox_basic.phpt @@ -2,22 +2,21 @@ Test imap_createmailbox() function : basic functionality --SKIPIF-- --FILE-- +--CLEAN-- + --EXPECTF-- *** Testing imap_createmailbox() : basic functionality *** +Create a temporary mailbox and add 0 msgs +New mailbox created Newname will be 'phpnewbox' Add a couple of msgs to 'phpnewbox' mailbox Your new mailbox 'phpnewbox' has the following status: diff --git a/ext/imap/tests/imap_errors_basic.phpt b/ext/imap/tests/imap_errors_basic.phpt index c897193766..f691a5c705 100644 --- a/ext/imap/tests/imap_errors_basic.phpt +++ b/ext/imap/tests/imap_errors_basic.phpt @@ -2,16 +2,16 @@ Test imap_errors() function : invalid password --SKIPIF-- --FILE-- --FILE-- --CLEAN-- --EXPECTF-- *** Testing imap_fetch_overview() : basic functionality *** Create a temporary mailbox and add 2 msgs -.. mailbox '{%s}%s' created +New mailbox created -- All possible arguments -- diff --git a/ext/imap/tests/imap_fetch_overview_variation3.phpt b/ext/imap/tests/imap_fetch_overview_variation3.phpt index f416887388..1ed528a173 100644 --- a/ext/imap/tests/imap_fetch_overview_variation3.phpt +++ b/ext/imap/tests/imap_fetch_overview_variation3.phpt @@ -2,7 +2,7 @@ Test imap_fetch_overview() function : usage variations - FT_UID option --SKIPIF-- --FILE-- --CLEAN-- ---EXPECTF-- +--EXPECT-- *** Testing imap_fetch_overview() : usage variations *** Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created +New mailbox created Testing with option value:string(1) "1" imap_fetch_overview() returns an object diff --git a/ext/imap/tests/imap_fetch_overview_variation5.phpt b/ext/imap/tests/imap_fetch_overview_variation5.phpt index 9774e682c1..6a8b6abd51 100644 --- a/ext/imap/tests/imap_fetch_overview_variation5.phpt +++ b/ext/imap/tests/imap_fetch_overview_variation5.phpt @@ -2,7 +2,7 @@ Test imap_fetch_overview() function : usage variations - $msg_no argument --SKIPIF-- --FILE-- --CLEAN-- --EXPECTF-- *** Testing imap_fetch_overview() : usage variations *** Create a temporary mailbox and add 3 msgs -.. mailbox '{%s}%s' created +New mailbox created -- $msg_no is 0 -- Sequence out of range diff --git a/ext/imap/tests/imap_fetch_overview_variation6.phpt b/ext/imap/tests/imap_fetch_overview_variation6.phpt index 256f631082..0535b3d5ac 100644 --- a/ext/imap/tests/imap_fetch_overview_variation6.phpt +++ b/ext/imap/tests/imap_fetch_overview_variation6.phpt @@ -2,7 +2,7 @@ Test imap_fetch_overview() function : usage variations - multipart message --SKIPIF-- --FILE-- --CLEAN-- --EXPECTF-- *** Testing imap_fetch_overview() : usage variations *** Create a temporary mailbox and add 0 msgs -.. mailbox '{%s}%s' created +New mailbox created --> Object #1 size is %d diff --git a/ext/imap/tests/imap_fetchbody_basic.phpt b/ext/imap/tests/imap_fetchbody_basic.phpt index 3c16f939c8..d0324383ea 100644 --- a/ext/imap/tests/imap_fetchbody_basic.phpt +++ b/ext/imap/tests/imap_fetchbody_basic.phpt @@ -2,7 +2,7 @@ Test imap_fetchbody() function : basic functionality --SKIPIF-- --FILE-- seen ); ?> --CLEAN-- --EXPECTF-- *** Testing imap_fetchbody() : basic functionality *** Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created +New mailbox created -- All possible arguments -- -- Option is FT_UID -- diff --git a/ext/imap/tests/imap_fetchbody_variation4.phpt b/ext/imap/tests/imap_fetchbody_variation4.phpt index df5d895670..5e25dd1126 100644 --- a/ext/imap/tests/imap_fetchbody_variation4.phpt +++ b/ext/imap/tests/imap_fetchbody_variation4.phpt @@ -2,7 +2,7 @@ Test imap_fetchbody() function : usage variations - FT_UID option --SKIPIF-- --FILE-- --CLEAN-- ---EXPECTF-- +--EXPECT-- *** Testing imap_fetchbody() : usage variations *** Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created +New mailbox created -- Iteration 1 -- FT_UID valid diff --git a/ext/imap/tests/imap_fetchbody_variation6.phpt b/ext/imap/tests/imap_fetchbody_variation6.phpt index 8b3d73540a..7889c40193 100644 --- a/ext/imap/tests/imap_fetchbody_variation6.phpt +++ b/ext/imap/tests/imap_fetchbody_variation6.phpt @@ -2,7 +2,7 @@ Test imap_fetchbody() function : usage variations - $message_num arg --SKIPIF-- --FILE-- --CLEAN-- --EXPECTF-- *** Testing imap_fetchbody() : usage variations *** Create a temporary mailbox and add 3 msgs -.. mailbox '{%s}%s' created +New mailbox created -- $message_num is 0 -- imap_fetchbody(): Argument #2 ($message_num) must be greater than 0 @@ -48,5 +49,5 @@ Warning: imap_fetchbody(): Bad message number in %s on line %d bool(false) -- $message_num is 1 -- -string(%s) "1: this is a test message, please ignore -%A" +string(%d) "1: this is a test message, please ignore +newline%r\R?%r" diff --git a/ext/imap/tests/imap_fetchheader_basic.phpt b/ext/imap/tests/imap_fetchheader_basic.phpt index 44f7de5a39..dc934e00cf 100644 --- a/ext/imap/tests/imap_fetchheader_basic.phpt +++ b/ext/imap/tests/imap_fetchheader_basic.phpt @@ -2,15 +2,15 @@ Test imap_fetchheader() function : basic function --SKIPIF-- --FILE-- FT_UID, 'FT_INTERNAL' => FT_INTERNAL, 'FT_PREFETCHTEXT' => FT_PREFETCHTEXT); @@ -33,12 +33,13 @@ var_dump( imap_fetchheader($stream_id, $msg_no) ); ?> --CLEAN-- --EXPECTF-- *** Testing imap_fetchheader() : basic functionality *** Create a temporary mailbox and add 1 msgs -.. mailbox '%s.phpttest' created +New mailbox created -- All possible arguments -- -- Option is FT_UID -- diff --git a/ext/imap/tests/imap_fetchheader_variation3.phpt b/ext/imap/tests/imap_fetchheader_variation3.phpt index a457db0491..1289087b7d 100644 --- a/ext/imap/tests/imap_fetchheader_variation3.phpt +++ b/ext/imap/tests/imap_fetchheader_variation3.phpt @@ -2,7 +2,7 @@ Test imap_fetchheader() function : usage variations - FT_UID option --SKIPIF-- --FILE-- --CLEAN-- ---EXPECTF-- +--EXPECT-- *** Testing imap_fetchheader() : usage variations *** Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created +New mailbox created -- Iteration 1 -- FT_UID valid diff --git a/ext/imap/tests/imap_fetchheader_variation5.phpt b/ext/imap/tests/imap_fetchheader_variation5.phpt index cb00986a06..eb6493017b 100644 --- a/ext/imap/tests/imap_fetchheader_variation5.phpt +++ b/ext/imap/tests/imap_fetchheader_variation5.phpt @@ -2,7 +2,7 @@ Test imap_fetchheader() function : usage variations - $message_num argument --SKIPIF-- --FILE-- --CLEAN-- --EXPECTF-- *** Testing imap_fetchheader() : usage variations *** Create a temporary mailbox and add 3 msgs -.. mailbox '{%s}%s' created +New mailbox created -- $message_num is 0 -- imap_fetchheader(): Argument #2 ($message_num) must be greater than 0 diff --git a/ext/imap/tests/imap_fetchstructure_basic.phpt b/ext/imap/tests/imap_fetchstructure_basic.phpt index 24cd2307dd..2eb730c890 100644 --- a/ext/imap/tests/imap_fetchstructure_basic.phpt +++ b/ext/imap/tests/imap_fetchstructure_basic.phpt @@ -4,13 +4,13 @@ imap_fetchstructure() function : basic functionality Olivier Doucet --SKIPIF-- --FILE-- --CLEAN-- --EXPECTF-- Create a temporary mailbox and add 1 msgs -.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created +New mailbox created imap_fetchstructure(): Argument #2 ($message_num) must be greater than 0 bool(true) bool(true) diff --git a/ext/imap/tests/imap_gc_error.phpt b/ext/imap/tests/imap_gc_error.phpt index 5b5b65d271..7c6fa3da84 100644 --- a/ext/imap/tests/imap_gc_error.phpt +++ b/ext/imap/tests/imap_gc_error.phpt @@ -1,18 +1,17 @@ --TEST-- -imap_gc() incorrect parameter count +imap_gc() ValueError --CREDITS-- Paul Sohier #phptestfest utrecht --SKIPIF-- --FILE-- getMessage() . \PHP_EOL; } +?> +--CLEAN-- + --EXPECT-- +Create a temporary mailbox and add 1 msgs +New mailbox created imap_gc(): Argument #2 ($flags) must be a bitmask of IMAP_GC_TEXTS, IMAP_GC_ELT, and IMAP_GC_ENV diff --git a/ext/imap/tests/imap_getsubscribed_basic.phpt b/ext/imap/tests/imap_getsubscribed_basic.phpt index 8e5d85383d..a1519042f1 100644 --- a/ext/imap/tests/imap_getsubscribed_basic.phpt +++ b/ext/imap/tests/imap_getsubscribed_basic.phpt @@ -4,27 +4,29 @@ imap_getsubscribed() function : basic functionality Olivier Doucet --SKIPIF-- +--CONFLICTS-- +defaultmailbox --FILE-- --CLEAN-- --EXPECTF-- bool(false) diff --git a/ext/imap/tests/imap_headerinfo_basic.phpt b/ext/imap/tests/imap_headerinfo_basic.phpt index 056a46523c..0d84aee44b 100644 --- a/ext/imap/tests/imap_headerinfo_basic.phpt +++ b/ext/imap/tests/imap_headerinfo_basic.phpt @@ -4,13 +4,13 @@ imap_headerinfo() function : basic functionality Olivier Doucet --SKIPIF-- --FILE-- --CLEAN-- --EXPECTF-- Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created +New mailbox created Check general fields bool(true) bool(true) diff --git a/ext/imap/tests/imap_include.inc b/ext/imap/tests/imap_include.inc deleted file mode 100644 index e57d651697..0000000000 --- a/ext/imap/tests/imap_include.inc +++ /dev/null @@ -1,196 +0,0 @@ -$mf; - if ($mf == 'udate') { - if (($z >= $start_time) && ($z <= time())) { - echo "$mf is OK\n"; - } else { - echo "$mf is BAD ($z)\n"; - } - } else { - echo "$mf is $z\n"; - } - } -} - - -/** - * Create a test mailbox and populate with msgs - * - * @param string mailbox_suffix Suffix used to uniquely identify mailboxes - * @param int message_count number of test msgs to be written to new mailbox - * - * @return IMAP stream to new mailbox on success; FALSE on failure - */ -function setup_test_mailbox($mailbox_suffix, $message_count, &$new_mailbox = null, $msg_type = "simple"){ - global $server, $default_mailbox, $username, $password; - - // open a stream to default mailbox - $imap_stream = imap_open($default_mailbox, $username, $password); - - if ($imap_stream === false) { - echo "Cannot connect to IMAP server $server: " . imap_last_error() . "\n"; - return false; - } - - echo "Create a temporary mailbox and add " . $message_count . " msgs\n"; - $new_mailbox = create_mailbox($imap_stream, $mailbox_suffix, $message_count, $msg_type); - if ($new_mailbox === false) { - echo "Can't create a temporary mailbox: " . imap_last_error(). "\n"; - return false; - } - - echo ".. mailbox '$new_mailbox' created\n"; - - // reopen stream to new mailbox - if (imap_reopen($imap_stream, $new_mailbox) === false) { - echo "can't re-open '$new_mailbox' mailbox: " . imap_last_error() . "\n"; - return false; - } - - return $imap_stream; -} - -/** - * Create mailbox and fill with generic emails - * - * @param resource $imap_stream - * @param string $mailbox - */ -function create_mailbox($imap_stream, $mailbox_suffix, $message_count, $msg_type= "simple"){ - global $default_mailbox, $mailbox_prefix; - $mailbox = $default_mailbox . "." . $mailbox_prefix . $mailbox_suffix; - - $mailboxes = imap_getmailboxes($imap_stream, $mailbox, '*'); - - // check mailbox does not already exist - if ($mailboxes) { - foreach($mailboxes as $value) { - if ($value->name == $mailbox) { - exit ("TEST FAILED : Mailbox '$mailbox' already exists\n"); - } - } - } - - if (imap_createmailbox($imap_stream, $mailbox) === false) { - return false; - } - - // Add number of test msgs requested - if ($message_count > 0) { - populate_mailbox($imap_stream, $mailbox, $message_count, $msg_type); - } - - return $mailbox; -} - -/** - * Populate a mailbox with generic emails - * - * @param resource $imap_stream - * @param string $mailbox - */ -function populate_mailbox($imap_stream, $mailbox, $message_count, $msg_type = "simple"){ - - global $users, $domain; - - for($i = 1; $i <= $message_count; $i++) { - if ($msg_type == "simple") { - $msg = "From: foo@anywhere.com\r\n" - . "To: $users[0]@$domain\r\n" - . "Subject: test$i\r\n" - . "\r\n" - . "$i: this is a test message, please ignore\r\n"; - } else { - $envelope["from"]= "foo@anywhere.com"; - $envelope["to"] = "$users[0]@$domain"; - $envelope["subject"] = "Test msg $i"; - - $part1["type"] = TYPEMULTIPART; - $part1["subtype"] = "mixed"; - - $part2["type"] = TYPETEXT; - $part2["subtype"] = "plain"; - $part2["description"] = "imap_mail_compose() function"; - $part2["contents.data"] = "message 1:xxxxxxxxxxxxxxxxxxxxxxxxxx"; - - $part3["type"] = TYPETEXT; - $part3["subtype"] = "plain"; - $part3["description"] = "Example"; - $part3["contents.data"] = "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy"; - - $part4["type"] = TYPETEXT; - $part4["subtype"] = "plain"; - $part4["description"] = "Return Values"; - $part4["contents.data"] = "message 3:zzzzzzzzzzzzzzzzzzzzzzzzzz"; - - $body[1] = $part1; - $body[2] = $part2; - $body[3] = $part3; - $body[4] = $part4; - - $msg = imap_mail_compose($envelope, $body); - } - - imap_append($imap_stream, $mailbox, $msg); - } -} - -/** - * Get the mailbox name from a mailbox description, i.e strip off server details. - * - * @param string mailbox complete mailbox name - * @return mailbox name - */ -function get_mailbox_name($mailbox){ - - if (preg_match('/\{.*?\}(.*)/', $mailbox, $match) != 1) { - echo "Unrecpognized mailbox name\n"; - return false; - } - - return $match[1]; -} - -?> diff --git a/ext/imap/tests/imap_list_basic.phpt b/ext/imap/tests/imap_list_basic.phpt index addcf70e77..e11c6c1bd0 100644 --- a/ext/imap/tests/imap_list_basic.phpt +++ b/ext/imap/tests/imap_list_basic.phpt @@ -4,20 +4,22 @@ imap_list() function : basic functionality Olivier Doucet --SKIPIF-- --FILE-- +--CONFLICTS-- +defaultmailbox --FILE-- --CLEAN-- --EXPECTF-- bool(false) diff --git a/ext/imap/tests/imap_mail_copy_basic.phpt b/ext/imap/tests/imap_mail_copy_basic.phpt index 25725478a6..312c8198a6 100644 --- a/ext/imap/tests/imap_mail_copy_basic.phpt +++ b/ext/imap/tests/imap_mail_copy_basic.phpt @@ -4,36 +4,33 @@ Test imap_mail_copy() function : basic functionality Olivier Doucet --SKIPIF-- --FILE-- Nmsgs . "\n"; -var_dump(imap_mail_copy($imap_stream, '1', 'INBOX.'.$mailbox_prefix)); +var_dump(imap_mail_copy($imap_stream, '1', 'INBOX.' . IMAP_MAILBOX_PHPT_PREFIX . 'copybasic')); imap_close($imap_stream); ?> --CLEAN-- ---EXPECTF-- +--EXPECT-- *** Testing imap_mail_copy() : basic functionality *** Create a new mailbox for test Create a temporary mailbox and add 1 msgs -.. mailbox '%s' created +New mailbox created Msg Count in new mailbox: 1 bool(true) diff --git a/ext/imap/tests/imap_mail_move_basic.phpt b/ext/imap/tests/imap_mail_move_basic.phpt index 3988951f12..3cd347b627 100644 --- a/ext/imap/tests/imap_mail_move_basic.phpt +++ b/ext/imap/tests/imap_mail_move_basic.phpt @@ -4,36 +4,33 @@ Test imap_mail_move() function : basic functionality Olivier Doucet --SKIPIF-- --FILE-- Nmsgs . "\n"; -var_dump(imap_mail_move($imap_stream, '1', 'INBOX.'.$mailbox_prefix)); +var_dump(imap_mail_move($imap_stream, '1', 'INBOX.' . IMAP_MAILBOX_PHPT_PREFIX . 'movebasic')); imap_close($imap_stream); ?> --CLEAN-- ---EXPECTF-- +--EXPECT-- *** Testing imap_mail_move() : basic functionality *** Create a new mailbox for test Create a temporary mailbox and add 1 msgs -.. mailbox '%s' created +New mailbox created Msg Count in new mailbox: 1 bool(true) diff --git a/ext/imap/tests/imap_mutf7_to_utf8.phpt b/ext/imap/tests/imap_mutf7_to_utf8.phpt index f45361f4a9..835a25428f 100644 --- a/ext/imap/tests/imap_mutf7_to_utf8.phpt +++ b/ext/imap/tests/imap_mutf7_to_utf8.phpt @@ -2,7 +2,6 @@ imap_mutf7_to_utf8 --SKIPIF-- - --FILE-- --FILE-- @@ -20,10 +20,8 @@ try { echo $e->getMessage() . \PHP_EOL; } -require_once(__DIR__.'/imap_include.inc'); - try { - imap_open($default_mailbox, $username, $password, NIL, -1); + imap_open('', '', '', NIL, -1); } catch (\ValueError $e) { echo $e->getMessage() . \PHP_EOL; } diff --git a/ext/imap/tests/imap_renamemailbox_basic.phpt b/ext/imap/tests/imap_renamemailbox_basic.phpt index c6b1812d16..05f1e4a309 100644 --- a/ext/imap/tests/imap_renamemailbox_basic.phpt +++ b/ext/imap/tests/imap_renamemailbox_basic.phpt @@ -4,20 +4,16 @@ imap_renamemailbox() function : basic functionality Olivier Doucet --SKIPIF-- --FILE-- --CLEAN-- ---EXPECTF-- +--EXPECT-- Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created +New mailbox created Checking OK bool(true) -bool(true) diff --git a/ext/imap/tests/imap_rfc822_parse_headers_basic.phpt b/ext/imap/tests/imap_rfc822_parse_headers_basic.phpt index 87dc4aaf05..fd2dfb939d 100644 --- a/ext/imap/tests/imap_rfc822_parse_headers_basic.phpt +++ b/ext/imap/tests/imap_rfc822_parse_headers_basic.phpt @@ -4,13 +4,13 @@ imap_rfc822_parse_headers() function : basic functionality Olivier Doucet --SKIPIF-- --FILE-- --CLEAN-- --EXPECTF-- Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created +New mailbox created Check general fields bool(true) bool(true) diff --git a/ext/imap/tests/imap_savebody_basic.phpt b/ext/imap/tests/imap_savebody_basic.phpt index ccbaa1ba66..38be6ab4a0 100644 --- a/ext/imap/tests/imap_savebody_basic.phpt +++ b/ext/imap/tests/imap_savebody_basic.phpt @@ -4,13 +4,13 @@ imap_savebody() function : basic functionality Olivier Doucet --SKIPIF-- --FILE-- --EXPECTF-- Create a temporary mailbox and add 1 msgs -.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created +New mailbox created bool(true) Size: %d bool(true) diff --git a/ext/imap/tests/imap_timeout_basic.phpt b/ext/imap/tests/imap_timeout_basic.phpt index f9618c3e3a..e449c3fdec 100644 --- a/ext/imap/tests/imap_timeout_basic.phpt +++ b/ext/imap/tests/imap_timeout_basic.phpt @@ -4,7 +4,7 @@ imap_timeout() function : basic functionality Olivier Doucet --SKIPIF-- --FILE-- --FILE-- --CLEAN-- ---EXPECTF-- +--EXPECT-- Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created +New mailbox created bool(true) diff --git a/ext/imap/tests/imap_utf8.phpt b/ext/imap/tests/imap_utf8.phpt index a82c3721c3..522d4d6f56 100644 --- a/ext/imap/tests/imap_utf8.phpt +++ b/ext/imap/tests/imap_utf8.phpt @@ -11,8 +11,8 @@ var_dump(imap_utf8("test")); echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- string(0) "" string(1) "1" -string(4) "%s" +string(4) "test" Done diff --git a/ext/imap/tests/imap_utf8_to_mutf7_basic.phpt b/ext/imap/tests/imap_utf8_to_mutf7_basic.phpt index 8037ae9491..c0f3b06dc9 100644 --- a/ext/imap/tests/imap_utf8_to_mutf7_basic.phpt +++ b/ext/imap/tests/imap_utf8_to_mutf7_basic.phpt @@ -2,7 +2,6 @@ imap_utf8_to_mutf7 --SKIPIF-- - --FILE-- Nmsgs; $i++) { + imap_delete($imap_stream, $i); +} + + +$mailboxes = imap_getmailboxes($imap_stream, IMAP_SERVER, '*'); + +if (!is_array($mailbox_suffix)) { + $mailbox_suffixes = [$mailbox_suffix]; +} else { + $mailbox_suffixes = $mailbox_suffix; +} + +foreach ($mailbox_suffixes as $mailbox_suffix) { + foreach($mailboxes as $value) { + // Only delete mailbox with our prefix (+ optional test suffix) + if (preg_match('/\{.*?\}INBOX\.' . IMAP_MAILBOX_PHPT_PREFIX . $mailbox_suffix .'$/', $value->name, $match) == 1) { + imap_deletemailbox($imap_stream, $value->name); + } + } +} + +imap_close($imap_stream, CL_EXPUNGE); diff --git a/ext/imap/tests/setup/dovecot.conf b/ext/imap/tests/setup/dovecot.conf new file mode 100644 index 0000000000..c465ba3ce9 --- /dev/null +++ b/ext/imap/tests/setup/dovecot.conf @@ -0,0 +1,33 @@ +# 2.2.33.2 (d6601f4ec): /etc/dovecot/dovecot.conf +# Pigeonhole version 0.4.21 (92477967) +listen = *, :: + +# To make authentication work +ssl = no +disable_plaintext_auth = no + +auth_mechanisms = plain cram-md5 +auth_username_format = %u +auth_debug = yes +auth_verbose = yes +#log +log_path = /var/log/dovecot.log +# If not set, use the value from log_path +info_log_path = /var/log/dovecot-info.log +# If not set, use the value from info_log_path +debug_log_path = /var/log/dovecot-debug.log +## Mailbox locations and namespaces +mail_location = maildir:/var/vmail/dovecot/mail/%d/%n/Maildir +passdb { + args = scheme=cram-md5 /etc/dovecot/dovecotpass + driver = passwd-file +} +protocols = imap +service auth { + user = root +} +userdb { + args = /etc/dovecot/dovecotpass + driver = passwd-file + override_fields = home=/var/vmail/dovecot/mail/%d/%n +} diff --git a/ext/imap/tests/setup/dovecotpass b/ext/imap/tests/setup/dovecotpass new file mode 100644 index 0000000000..86a069fc4f --- /dev/null +++ b/ext/imap/tests/setup/dovecotpass @@ -0,0 +1 @@ +webmaster@something.com:{CRAM-MD5}be5f3177e9c7c06403272f25d983ba630df4ef40476b353bb3087a8401713451:vmail:vmail diff --git a/ext/imap/tests/setup/imap_include.inc b/ext/imap/tests/setup/imap_include.inc new file mode 100644 index 0000000000..33e4e5ca16 --- /dev/null +++ b/ext/imap/tests/setup/imap_include.inc @@ -0,0 +1,190 @@ +$mf; + if ($mf == 'udate') { + if (($z >= $start_time) && ($z <= time())) { + echo "$mf is OK\n"; + } else { + echo "$mf is BAD ($z)\n"; + } + } else { + echo "$mf is $z\n"; + } + } +} + + +/** + * Create a test mailbox and populate with msgs + * + * @param string mailbox_suffix Suffix used to uniquely identify mailboxes + * @param int message_count number of test msgs to be written to new mailbox + * @param null $new_mailbox + * @param bool $simpleMessages + * @return resource IMAP stream to new mailbox + * @throws Exception + */ +function setup_test_mailbox(string $mailbox_suffix, int $message_count, &$new_mailbox = null, bool $simpleMessages = true){ + // open a stream to default mailbox + $imap_stream = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD); + + if ($imap_stream === false) { + throw new Exception("Cannot connect to IMAP server " . IMAP_SERVER . ": " . imap_last_error()); + } + + echo "Create a temporary mailbox and add " . $message_count . " msgs\n"; + $new_mailbox = create_mailbox($imap_stream, $mailbox_suffix, $message_count, $simpleMessages); + + echo "New mailbox created\n"; + + // reopen stream to new mailbox + if (imap_reopen($imap_stream, $new_mailbox) === false) { + throw new Exception("Can't re-open '$new_mailbox' mailbox: " . imap_last_error()); + } + + return $imap_stream; +} + +/** + * Create mailbox and fill with generic emails + * + * @param resource $imap_stream + * @param string $mailbox_suffix + * @param int $message_count + * @param bool $simpleMessages + * @return string + * @throws Exception + */ +function create_mailbox($imap_stream, string $mailbox_suffix, int $message_count, bool $simpleMessages = true): string { + $mailbox = IMAP_DEFAULT_MAILBOX . '.' . IMAP_MAILBOX_PHPT_PREFIX . $mailbox_suffix; + + $mailboxes = imap_getmailboxes($imap_stream, $mailbox, '*'); + + // check mailbox does not already exist + if ($mailboxes) { + foreach($mailboxes as $value) { + if ($value->name == $mailbox) { + throw new Exception("Mailbox '$mailbox' already exists"); + } + } + } + + if (imap_createmailbox($imap_stream, $mailbox) === false) { + throw new Exception("Can't create a temporary mailbox: " . imap_last_error()); + } + + // Add number of test msgs requested + if ($message_count > 0) { + populate_mailbox($imap_stream, $mailbox, $message_count, $simpleMessages); + } + + return $mailbox; +} + +/** + * Populate a mailbox with generic emails + * + * @param resource $imap_stream + * @param string $mailbox + * @param int $message_count + * @param bool $simpleMessages + */ +function populate_mailbox($imap_stream, string $mailbox, int $message_count, bool $simpleMessages = true): void { + for ($i = 1; $i <= $message_count; $i++) { + if ($simpleMessages) { + $msg = "From: foo@anywhere.com\r\n" + . "To: ". IMAP_USERS[0] . "@" . IMAP_MAIL_DOMAIN . "\r\n" + . "Subject: test$i\r\n" + . "\r\n" + . "$i: this is a test message, please ignore\r\nnewline"; + } else { + $envelope["from"]= "foo@anywhere.com"; + $envelope["to"] = IMAP_USERS[0] . "@" . IMAP_MAIL_DOMAIN; + $envelope["subject"] = "Test msg $i"; + + $part1["type"] = TYPEMULTIPART; + $part1["subtype"] = "mixed"; + + $part2["type"] = TYPETEXT; + $part2["subtype"] = "plain"; + $part2["description"] = "imap_mail_compose() function"; + $part2["contents.data"] = "message 1:xxxxxxxxxxxxxxxxxxxxxxxxxx"; + + $part3["type"] = TYPETEXT; + $part3["subtype"] = "plain"; + $part3["description"] = "Example"; + $part3["contents.data"] = "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy"; + + $part4["type"] = TYPETEXT; + $part4["subtype"] = "plain"; + $part4["description"] = "Return Values"; + $part4["contents.data"] = "message 3:zzzzzzzzzzzzzzzzzzzzzzzzzz"; + + $body[1] = $part1; + $body[2] = $part2; + $body[3] = $part3; + $body[4] = $part4; + + $msg = imap_mail_compose($envelope, $body); + } + + imap_append($imap_stream, $mailbox, $msg); + } +} + +/** + * Get the mailbox name from a mailbox description, i.e strip off server details. + * + * @param string mailbox complete mailbox name + * @return string mailbox name + */ +function get_mailbox_name(string $mailboxName): string { + + if (preg_match('/\{.*?\}(.*)/', $mailboxName, $match) != 1) { + throw new Exception("Unrecognized mailbox name '$mailboxName'"); + } + + return $match[1]; +} diff --git a/ext/imap/tests/setup/setup.sh b/ext/imap/tests/setup/setup.sh new file mode 100644 index 0000000000..efa7c30310 --- /dev/null +++ b/ext/imap/tests/setup/setup.sh @@ -0,0 +1,6 @@ +sudo service dovecot stop +sudo groupadd -g 5000 vmail +sudo useradd -m -d /var/vmail -s /bin/false -u 5000 -g vmail vmail +sudo cp ext/imap/tests/setup/dovecot.conf /etc/dovecot/dovecot.conf +sudo cp ext/imap/tests/setup/dovecotpass /etc/dovecot/dovecotpass +sudo service dovecot start diff --git a/ext/imap/tests/setup/skipif.inc b/ext/imap/tests/setup/skipif.inc new file mode 100644 index 0000000000..c7dc24efd7 --- /dev/null +++ b/ext/imap/tests/setup/skipif.inc @@ -0,0 +1,13 @@ + -- cgit v1.2.1