summaryrefslogtreecommitdiff
path: root/ext/imap/tests
diff options
context:
space:
mode:
Diffstat (limited to 'ext/imap/tests')
-rw-r--r--ext/imap/tests/README45
-rw-r--r--ext/imap/tests/bug45705_1.phpt20
-rw-r--r--ext/imap/tests/bug45705_2.phpt53
-rw-r--r--ext/imap/tests/bug46918.phpt69
-rw-r--r--ext/imap/tests/clean.inc25
-rw-r--r--ext/imap/tests/imap_8bit_basic.phpt33
-rw-r--r--ext/imap/tests/imap_alerts_error.phpt31
-rw-r--r--ext/imap/tests/imap_append_basic.phpt72
-rw-r--r--ext/imap/tests/imap_base64_basic.phpt47
-rw-r--r--ext/imap/tests/imap_binary_basic.phpt48
-rw-r--r--ext/imap/tests/imap_body_basic.phpt44
-rw-r--r--ext/imap/tests/imap_bodystruct_basic.phpt93
-rw-r--r--ext/imap/tests/imap_clearflag_full_basic.phpt127
-rw-r--r--ext/imap/tests/imap_close_basic.phpt56
-rw-r--r--ext/imap/tests/imap_close_error.phpt45
-rw-r--r--ext/imap/tests/imap_close_variation1.phpt214
-rw-r--r--ext/imap/tests/imap_close_variation2.phpt221
-rw-r--r--ext/imap/tests/imap_close_variation3.phpt47
-rw-r--r--ext/imap/tests/imap_close_variation4.phpt93
-rw-r--r--ext/imap/tests/imap_createmailbox_basic.phpt69
-rw-r--r--ext/imap/tests/imap_errors_basic.phpt55
-rw-r--r--ext/imap/tests/imap_fetch_overview_basic.phpt118
-rw-r--r--ext/imap/tests/imap_fetch_overview_error.phpt54
-rw-r--r--ext/imap/tests/imap_fetch_overview_variation1.phpt221
-rw-r--r--ext/imap/tests/imap_fetch_overview_variation2.phpt243
-rw-r--r--ext/imap/tests/imap_fetch_overview_variation3.phpt79
-rw-r--r--ext/imap/tests/imap_fetch_overview_variation4.phpt46
-rw-r--r--ext/imap/tests/imap_fetch_overview_variation5.phpt149
-rw-r--r--ext/imap/tests/imap_fetch_overview_variation6.phpt125
-rw-r--r--ext/imap/tests/imap_fetchbody_basic.phpt70
-rw-r--r--ext/imap/tests/imap_fetchbody_error.phpt57
-rw-r--r--ext/imap/tests/imap_fetchbody_variation1.phpt219
-rw-r--r--ext/imap/tests/imap_fetchbody_variation2.phpt221
-rw-r--r--ext/imap/tests/imap_fetchbody_variation3.phpt217
-rw-r--r--ext/imap/tests/imap_fetchbody_variation4.phpt79
-rw-r--r--ext/imap/tests/imap_fetchbody_variation5.phpt46
-rw-r--r--ext/imap/tests/imap_fetchbody_variation6.phpt66
-rw-r--r--ext/imap/tests/imap_fetchheader_basic.phpt83
-rw-r--r--ext/imap/tests/imap_fetchheader_error.phpt49
-rw-r--r--ext/imap/tests/imap_fetchheader_variation1.phpt245
-rw-r--r--ext/imap/tests/imap_fetchheader_variation2.phpt292
-rw-r--r--ext/imap/tests/imap_fetchheader_variation3.phpt77
-rw-r--r--ext/imap/tests/imap_fetchheader_variation4.phpt45
-rw-r--r--ext/imap/tests/imap_fetchheader_variation5.phpt79
-rw-r--r--ext/imap/tests/imap_include.inc150
-rw-r--r--ext/imap/tests/skipif.inc16
46 files changed, 4553 insertions, 0 deletions
diff --git a/ext/imap/tests/README b/ext/imap/tests/README
new file mode 100644
index 000000000..0d222ad0b
--- /dev/null
+++ b/ext/imap/tests/README
@@ -0,0 +1,45 @@
+
+Many of the tests in this directory require a mail server to be running, if there is no mail server the test will skip and warn, see skipif.inc for details.
+
+To make the tests run parameters in the skipif.inc and imap_include.inc file will need to be changed to match the local mailserver configuration.
+
+
+The tests have been checked using dovecot (on Linux 32 and 64 bit systems) and hMailServer on Windows. The tests are intended to be mailserver agnostic.
+
+The tests can be run without modification with a fairly minimal dovecot installation. For information, the dovecot.conf file used in running the tests is given below (after -----). The dovecot password file (dovecotpass) requires a password for one user, webmaster@something.com. It's also necessary to set up one additional user ID (vmail) to own the mail directory.
+
+--------------------------------------------------
+protocols = imap imaps
+
+listen = *
+
+ssl_disable = yes
+
+disable_plaintext_auth=yes
+
+## Mailbox locations and namespaces
+
+mail_location = maildir:/home/vmail/mail/%d/%n/Maildir
+
+auth_verbose = yes
+
+auth_debug = yes
+
+auth default {
+
+ mechanisms = login
+
+ passdb passwd-file {
+ args = /etc/dovecot/dovecotpass
+ }
+
+ userdb static {
+ args = uid=11459 gid=1002 home=/home/vmail/dovecot/mail/%d/%n
+ }
+
+ user = root
+}
+
+
+
+
diff --git a/ext/imap/tests/bug45705_1.phpt b/ext/imap/tests/bug45705_1.phpt
new file mode 100644
index 000000000..eedaed081
--- /dev/null
+++ b/ext/imap/tests/bug45705_1.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Bug #45705 test #1 (imap rfc822_parse_adrlist() modifies passed address parameter)
+--SKIPIF--
+<?php
+ if (!extension_loaded("imap")) {
+ die("skip imap extension not available");
+ }
+?>
+--FILE--
+<?php
+
+$address = 'John Doe <john@example.com>';
+var_dump($address);
+imap_rfc822_parse_adrlist($address, null);
+var_dump($address);
+
+?>
+--EXPECT--
+string(27) "John Doe <john@example.com>"
+string(27) "John Doe <john@example.com>"
diff --git a/ext/imap/tests/bug45705_2.phpt b/ext/imap/tests/bug45705_2.phpt
new file mode 100644
index 000000000..797d47317
--- /dev/null
+++ b/ext/imap/tests/bug45705_2.phpt
@@ -0,0 +1,53 @@
+--TEST--
+Bug #45705 test #2 (imap rfc822_parse_adrlist() modifies passed address parameter)
+--SKIPIF--
+<?php
+ if (!extension_loaded("imap")) {
+ die("skip imap extension not available");
+ }
+?>
+--FILE--
+<?php
+
+$envelope = array('return_path' => 'John Doe <john@example.com>',
+ 'from' => 'John Doe <john@example.com>',
+ 'reply_to' => 'John Doe <john@example.com>',
+ 'to' => 'John Doe <john@example.com>',
+ 'cc' => 'John Doe <john@example.com>',
+ 'bcc' => 'John Doe <john@example.com>',
+);
+
+var_dump($envelope);
+imap_mail_compose($envelope, array(1 => array()));
+var_dump($envelope);
+
+?>
+--EXPECT--
+array(6) {
+ ["return_path"]=>
+ string(27) "John Doe <john@example.com>"
+ ["from"]=>
+ string(27) "John Doe <john@example.com>"
+ ["reply_to"]=>
+ string(27) "John Doe <john@example.com>"
+ ["to"]=>
+ string(27) "John Doe <john@example.com>"
+ ["cc"]=>
+ string(27) "John Doe <john@example.com>"
+ ["bcc"]=>
+ string(27) "John Doe <john@example.com>"
+}
+array(6) {
+ ["return_path"]=>
+ string(27) "John Doe <john@example.com>"
+ ["from"]=>
+ string(27) "John Doe <john@example.com>"
+ ["reply_to"]=>
+ string(27) "John Doe <john@example.com>"
+ ["to"]=>
+ string(27) "John Doe <john@example.com>"
+ ["cc"]=>
+ string(27) "John Doe <john@example.com>"
+ ["bcc"]=>
+ string(27) "John Doe <john@example.com>"
+}
diff --git a/ext/imap/tests/bug46918.phpt b/ext/imap/tests/bug46918.phpt
new file mode 100644
index 000000000..6456f2570
--- /dev/null
+++ b/ext/imap/tests/bug46918.phpt
@@ -0,0 +1,69 @@
+--TEST--
+Bug #46918 (imap_rfc822_parse_adrlist host part not filled in correctly)
+--FILE--
+<?php
+
+$adds = 'ian eiloart <iane@example.ac.uk>,
+ shuf6@example.ac.uk,
+ blobby,
+ "ian,eiloart"<ian@example.ac.uk>,
+ <@example.com:foo@example.ac.uk>,
+ foo@#,
+ ian@-example.com,
+ ian@one@two';
+$add_arr = imap_rfc822_parse_adrlist($adds, 'example.com');
+var_export($add_arr);
+
+?>
+--EXPECT--
+array (
+ 0 =>
+ stdClass::__set_state(array(
+ 'mailbox' => 'iane',
+ 'host' => 'example.ac.uk',
+ 'personal' => 'ian eiloart',
+ )),
+ 1 =>
+ stdClass::__set_state(array(
+ 'mailbox' => 'shuf6',
+ 'host' => 'example.ac.uk',
+ )),
+ 2 =>
+ stdClass::__set_state(array(
+ 'mailbox' => 'blobby',
+ 'host' => 'example.com',
+ )),
+ 3 =>
+ stdClass::__set_state(array(
+ 'mailbox' => 'ian',
+ 'host' => 'example.ac.uk',
+ 'personal' => 'ian,eiloart',
+ )),
+ 4 =>
+ stdClass::__set_state(array(
+ 'mailbox' => 'foo',
+ 'host' => 'example.ac.uk',
+ 'adl' => '@example.com',
+ )),
+ 5 =>
+ stdClass::__set_state(array(
+ 'mailbox' => 'foo',
+ 'host' => '#',
+ )),
+ 6 =>
+ stdClass::__set_state(array(
+ 'mailbox' => 'ian',
+ 'host' => '-example.com',
+ )),
+ 7 =>
+ stdClass::__set_state(array(
+ 'mailbox' => 'ian',
+ 'host' => 'one',
+ )),
+ 8 =>
+ stdClass::__set_state(array(
+ 'mailbox' => 'UNEXPECTED_DATA_AFTER_ADDRESS',
+ 'host' => '.SYNTAX-ERROR.',
+ )),
+)
+Notice: Unknown: Unexpected characters at end of address: @two (errflg=3) in Unknown on line 0
diff --git a/ext/imap/tests/clean.inc b/ext/imap/tests/clean.inc
new file mode 100644
index 000000000..648f3c364
--- /dev/null
+++ b/ext/imap/tests/clean.inc
@@ -0,0 +1,25 @@
+<?php
+include_once(dirname(__FILE__) . '/imap_include.inc');
+
+$imap_stream = imap_open($default_mailbox, $username, $password);
+
+// delete all msgs in default mailbox, i.e INBOX
+$check = imap_check($imap_stream);
+for ($i = 1; $i <= $check->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);
+?> \ No newline at end of file
diff --git a/ext/imap/tests/imap_8bit_basic.phpt b/ext/imap/tests/imap_8bit_basic.phpt
new file mode 100644
index 000000000..48b136d74
--- /dev/null
+++ b/ext/imap/tests/imap_8bit_basic.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test imap_8bit() function : basic functionality
+--SKIPIF--
+<?php
+extension_loaded('imap') or die('skip imap extension not available in this build');
+?>
+--FILE--
+<?php
+/* Prototype : string imap_8bit ( string $string )
+ * Description: Convert an 8bit string to a quoted-printable string.
+ * Source code: ext/imap/php_imap.c
+ */
+
+echo "*** Testing imap_8bit() : basic functionality ***\n";
+
+var_dump(imap_8bit("String with CRLF at end \r\n"));
+//NB this appears to be a bug in cclient; a space at end of string should be encoded as =20
+var_dump(imap_8bit("String with space at end "));
+var_dump(imap_8bit("String with tabs \t\t in middle"));
+var_dump(imap_8bit("String with tab at end \t"));
+var_dump(imap_8bit("\x00\x01\x02\x03\x04\xfe\xff\x0a\x0d"));
+
+?>
+===Done===
+--EXPECT--
+*** Testing imap_8bit() : basic functionality ***
+string(28) "String with CRLF at end=20
+"
+string(25) "String with space at end "
+string(33) "String with tabs =09=09 in middle"
+string(26) "String with tab at end =09"
+string(27) "=00=01=02=03=04=FE=FF=0A=0D"
+===Done===
diff --git a/ext/imap/tests/imap_alerts_error.phpt b/ext/imap/tests/imap_alerts_error.phpt
new file mode 100644
index 000000000..b1b9ccdf6
--- /dev/null
+++ b/ext/imap/tests/imap_alerts_error.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Test imap_alerts() function : error conditions
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : array imap_alerts(void)
+ * Description: Returns an array of all IMAP alerts that have been generated since the last page load or since the last imap_alerts() call, whichever came last. The alert stack is cleared after imap_alerts() is called.
+ * Source code: ext/imap/php_imap.c
+ * Alias to functions:
+ */
+
+echo "*** Testing imap_alerts() : error conditions ***\n";
+
+// One argument
+echo "\n-- Testing imap_alerts() function with one argument --\n";
+$extra_arg = 10;;
+var_dump( imap_alerts($extra_arg) );
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing imap_alerts() : error conditions ***
+
+-- Testing imap_alerts() function with one argument --
+
+Warning: Wrong parameter count for imap_alerts() in %s on line %d
+NULL
+===DONE===
diff --git a/ext/imap/tests/imap_append_basic.phpt b/ext/imap/tests/imap_append_basic.phpt
new file mode 100644
index 000000000..cd0021688
--- /dev/null
+++ b/ext/imap/tests/imap_append_basic.phpt
@@ -0,0 +1,72 @@
+--TEST--
+Test imap_append() function : basic functionality
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : bool imap_append ( resource $imap_stream , string $mailbox , string $message [, string $options ] )
+ * Description: Append a string message to a specified mailbox.
+ * Source code: ext/imap/php_imap.c
+ */
+
+echo "*** Testing imap_append() : basic functionality ***\n";
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+echo "Create a new mailbox for test\n";
+$imap_stream = setup_test_mailbox("", 0);
+if (!is_resource($imap_stream)) {
+ exit("TEST FAILED: Unable to create test mailbox\n");
+}
+
+$mb_details = imap_mailboxmsginfo($imap_stream);
+echo "Add a couple of msgs to new mailbox " . $mb_details->Mailbox . "\n";
+var_dump(imap_append($imap_stream, $mb_details->Mailbox
+ , "From: webmaster@something.com\r\n"
+ . "To: info@something.com\r\n"
+ . "Subject: Test message\r\n"
+ . "\r\n"
+ . "this is a test message, please ignore\r\n"
+ ));
+
+var_dump(imap_append($imap_stream, $mb_details->Mailbox
+ , "From: webmaster@something.com\r\n"
+ . "To: info@something.com\r\n"
+ . "Subject: Another test\r\n"
+ . "\r\n"
+ . "this is another test message, please ignore it too!!\r\n"
+ ));
+
+$check = imap_check($imap_stream);
+echo "Msg Count after append : ". $check->Nmsgs . "\n";
+
+echo "List the msg headers\n";
+var_dump(imap_headers($imap_stream));
+
+imap_close($imap_stream);
+?>
+===Done===
+--CLEAN--
+<?php
+require_once('clean.inc');
+?>
+--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
+bool(true)
+bool(true)
+Msg Count after append : 2
+List the msg headers
+array(2) {
+ [0]=>
+ string(%d) "%w%s 1)%s webmaster@something. Test message (%d chars)"
+ [1]=>
+ string(%d) "%w%s 2)%s webmaster@something. Another test (%d chars)"
+}
+===Done===
+
diff --git a/ext/imap/tests/imap_base64_basic.phpt b/ext/imap/tests/imap_base64_basic.phpt
new file mode 100644
index 000000000..3d1b6c283
--- /dev/null
+++ b/ext/imap/tests/imap_base64_basic.phpt
@@ -0,0 +1,47 @@
+--TEST--
+Test imap_base64() function : basic functionality
+--SKIPIF--
+<?php
+extension_loaded('imap') or die('skip imap extension not available in this build');
+?>
+--FILE--
+<?php
+/* Prototype : string imap_base64 ( string $text )
+ * Description: Decode BASE64 encoded text.
+ * Source code: ext/imap/php_imap.c
+ */
+
+echo "*** Testing imap_base64() : basic functionality ***\n";
+
+$str = b'This is an example string to be base 64 encoded';
+$base64 = base64_encode($str);
+if (imap_base64($base64) == $str) {
+ echo "TEST PASSED\n";
+} else {
+ echo "TEST FAILED";
+}
+
+$str = b'!£$%^&*()_+-={][];;@~#?/>.<,';
+$base64 = base64_encode($str);
+if (imap_base64($base64) == $str) {
+ echo "TEST PASSED\n";
+} else {
+ echo "TEST FAILED";
+}
+
+$hex = b'x00\x01\x02\x03\x04\x05\x06\xFA\xFB\xFC\xFD\xFE\xFF';
+$base64 = base64_encode($hex);
+if (imap_base64($base64) == $hex) {
+ echo "TEST PASSED\n";
+} else {
+ echo "TEST FAILED";
+}
+
+?>
+===Done===
+--EXPECT--
+*** Testing imap_base64() : basic functionality ***
+TEST PASSED
+TEST PASSED
+TEST PASSED
+===Done===
diff --git a/ext/imap/tests/imap_binary_basic.phpt b/ext/imap/tests/imap_binary_basic.phpt
new file mode 100644
index 000000000..bd4eabba5
--- /dev/null
+++ b/ext/imap/tests/imap_binary_basic.phpt
@@ -0,0 +1,48 @@
+--TEST--
+Test imap_binary() function : basic functionality
+--SKIPIF--
+<?php
+extension_loaded('imap') or die('skip imap extension not available in this build');
+?>
+--FILE--
+<?php
+/* Prototype : string imap_binary ( string $string )
+ * Description: Convert an 8bit string to a base64 string.
+ * Source code: ext/imap/php_imap.c
+ */
+
+echo "*** Testing imap_binary() : basic functionality ***\n";
+
+echo "Encode as short string\n";
+$str = b'This is an example string to be base 64 encoded';
+$base64 = imap_binary($str);
+var_dump(bin2hex($base64));
+
+echo "Encode a string which results in more than 60 charters of output\n";
+$str = b'This is a long string with results in more than 60 characters of output';
+$base64 = imap_binary($str);
+var_dump(bin2hex($base64));
+
+echo "Encode a string with special characters\n";
+$str = b'_+-={][];;@~#?/>.<,';
+$base64 = imap_binary($str);
+var_dump(bin2hex($base64));
+
+echo "Encode some hexadecimal data\n";
+$hex = b'x00\x01\x02\x03\x04\x05\x06\xFA\xFB\xFC\xFD\xFE\xFF';
+$base64 = imap_binary($hex);
+var_dump(bin2hex($base64));
+
+?>
+===Done===
+--EXPECTF--
+*** Testing imap_binary() : basic functionality ***
+Encode as short string
+%string|unicode%(136) "5647687063794270637942686269426c654746746347786c49484e30636d6c755a794230627942695a53426959584e6c49445930494756755932396b0d0a5a57513d0d0a"
+Encode a string which results in more than 60 charters of output
+%string|unicode%(200) "56476870637942706379426849477876626d6367633352796157356e4948647064476767636d567a64577830637942706269427462334a6c4948526f0d0a595734674e6a416759326868636d466a64475679637942765a694276645852776458513d0d0a"
+Encode a string with special characters
+%string|unicode%(60) "5879737450587464573130374f30422b497a3876506934384c413d3d0d0a"
+Encode some hexadecimal data
+%string|unicode%(144) "65444177584867774d5678344d444a636544417a584867774e4678344d445663654441325848684751567834526b4a6365455a4458486847524678340d0a526b566365455a470d0a"
+===Done===
diff --git a/ext/imap/tests/imap_body_basic.phpt b/ext/imap/tests/imap_body_basic.phpt
new file mode 100644
index 000000000..deda63a35
--- /dev/null
+++ b/ext/imap/tests/imap_body_basic.phpt
@@ -0,0 +1,44 @@
+--TEST--
+Test imap_body() function : basic functionality
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : string imap_body ( resource $imap_stream , int $msg_number [, int $options ] )
+ * Description: Read the message body.
+ * Source code: ext/imap/php_imap.c
+ */
+
+echo "*** Testing imap_body() : basic functionality ***\n";
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+echo "Create a new mailbox for test\n";
+$imap_stream = setup_test_mailbox("", 1);
+if (!is_resource($imap_stream)) {
+ exit("TEST FAILED: Unable to create test mailbox\n");
+}
+
+$check = imap_check($imap_stream);
+echo "Msg Count in new mailbox: ". $check->Nmsgs . "\n";
+
+// show body for msg 1
+var_dump(imap_body($imap_stream, 1));
+
+imap_close($imap_stream);
+?>
+===Done===
+--CLEAN--
+<?php
+require_once('clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_body() : basic functionality ***
+Create a new mailbox for test
+Create a temporary mailbox and add 1 msgs
+.. mailbox '%s' created
+Msg Count in new mailbox: 1
+string(%d) "1: this is a test message, please ignore%a"
+===Done=== \ No newline at end of file
diff --git a/ext/imap/tests/imap_bodystruct_basic.phpt b/ext/imap/tests/imap_bodystruct_basic.phpt
new file mode 100644
index 000000000..4edc753b6
--- /dev/null
+++ b/ext/imap/tests/imap_bodystruct_basic.phpt
@@ -0,0 +1,93 @@
+--TEST--
+Test imap_bodystruct() function : basic functionality
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : object imap_bodystruct ( resource $imap_stream , int $msg_number , string $section )
+ * Description: Read the structure of a specified body section of a specific message.
+ * Source code: ext/imap/php_imap.c
+ */
+
+echo "*** Testing string imap_bodystruct : basic functionality ***\n";
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+echo "Create a new mailbox for test and add a multipart msgs\n";
+$imap_stream = setup_test_mailbox("", 1, $mailbox, "multipart");
+if (!is_resource($imap_stream)) {
+ exit("TEST FAILED: Unable to create test mailbox\n");
+}
+
+echo "\nGet and validate structure of body part 1\n";
+
+$m = imap_bodystruct($imap_stream, 1, "1");
+
+$mandatoryFields = array(
+ 'ifsubtype',
+ 'ifdescription',
+ 'ifid',
+ 'ifdisposition',
+ 'ifdparameters',
+ 'ifparameters',
+ );
+
+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";
+}
+
+echo "\nTry to get part 4!\n";
+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;
+}
+?>
+===Done===
+--CLEAN--
+<?php
+require_once('clean.inc');
+?>
+--EXPECTF--
+*** 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 '{localhost/norsh}INBOX.phpttest' created
+
+Get and validate structure of body part 1
+ifsubtype is 0 or 1
+ifdescription is 0 or 1
+ifid is 0 or 1
+ifdisposition is 0 or 1
+ifdparameters is 0 or 1
+ifparameters is 0 or 1
+parameters is an array
+
+Try to get part 4!
+bool(false)
+===Done===
diff --git a/ext/imap/tests/imap_clearflag_full_basic.phpt b/ext/imap/tests/imap_clearflag_full_basic.phpt
new file mode 100644
index 000000000..3e52b5dcb
--- /dev/null
+++ b/ext/imap/tests/imap_clearflag_full_basic.phpt
@@ -0,0 +1,127 @@
+--TEST--
+Test imap_clearflag_full() function : basic functionality
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : bool imap_clearflag_full ( resource $imap_stream , string $sequence , string $flag [, string $options ] )
+ * Description: Clears flags on messages.
+ * Source code: ext/imap/php_imap.c
+ */
+
+echo "*** Testing imap_clearflag_full() : basic functionality ***\n";
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+echo "Create a new mailbox for test\n";
+$imap_stream = setup_test_mailbox("", 10);
+if (!is_resource($imap_stream)) {
+ exit("TEST FAILED: Unable to create test mailbox\n");
+}
+
+$check = imap_check($imap_stream);
+echo "Initial msg count in new_mailbox : ". $check->Nmsgs . "\n";
+
+echo "Set some flags\n";
+var_dump(imap_setflag_full($imap_stream, "1,3", "\\Seen \\Answered"));
+var_dump(imap_setflag_full($imap_stream, "2,4", "\\Answered"));
+var_dump(imap_setflag_full($imap_stream, "5,7", "\\Flagged \\Deleted"));
+var_dump(imap_setflag_full($imap_stream, "6,8", "\\Deleted"));
+var_dump(imap_setflag_full($imap_stream, "9,10", "\\Draft \\Flagged"));
+
+var_dump(imap_search($imap_stream, "SEEN"));
+var_dump(imap_search($imap_stream, "ANSWERED"));
+var_dump(imap_search($imap_stream, "FLAGGED"));
+var_dump(imap_search($imap_stream, "DELETED"));
+
+var_dump(imap_clearflag_full($imap_stream, "1,4", "\\Answered"));
+var_dump(imap_clearflag_full($imap_stream, "5,6,7,8", "\\Deleted"));
+var_dump(imap_clearflag_full($imap_stream, "9", "\\Flagged"));
+
+var_dump(imap_search($imap_stream, "SEEN"));
+var_dump(imap_search($imap_stream, "ANSWERED"));
+var_dump(imap_search($imap_stream, "FLAGGED"));
+var_dump(imap_search($imap_stream, "DELETED"));
+
+imap_close($imap_stream);
+?>
+===Done===
+--CLEAN--
+<?php
+require_once('clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_clearflag_full() : basic functionality ***
+Create a new mailbox for test
+Create a temporary mailbox and add 10 msgs
+.. mailbox '{localhost/norsh}INBOX.%s' created
+Initial msg count in new_mailbox : 10
+Set some flags
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+array(2) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(3)
+}
+array(4) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(2)
+ [2]=>
+ int(3)
+ [3]=>
+ int(4)
+}
+array(4) {
+ [0]=>
+ int(5)
+ [1]=>
+ int(7)
+ [2]=>
+ int(9)
+ [3]=>
+ int(10)
+}
+array(4) {
+ [0]=>
+ int(5)
+ [1]=>
+ int(6)
+ [2]=>
+ int(7)
+ [3]=>
+ int(8)
+}
+bool(true)
+bool(true)
+bool(true)
+array(2) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(3)
+}
+array(2) {
+ [0]=>
+ int(2)
+ [1]=>
+ int(3)
+}
+array(3) {
+ [0]=>
+ int(5)
+ [1]=>
+ int(7)
+ [2]=>
+ int(10)
+}
+bool(false)
+===Done===
diff --git a/ext/imap/tests/imap_close_basic.phpt b/ext/imap/tests/imap_close_basic.phpt
new file mode 100644
index 000000000..5ec6a33a1
--- /dev/null
+++ b/ext/imap/tests/imap_close_basic.phpt
@@ -0,0 +1,56 @@
+--TEST--
+Test imap_close() function : basic functionality
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : bool imap_close(resource $stream_id [, int $options])
+ * Description: Close an IMAP stream
+ * Source code: ext/imap/php_imap.c
+ */
+
+echo "*** Testing imap_close() : basic functionality ***\n";
+
+// include file for required variables in imap_open()
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+// Initialize required variables
+$stream_id = setup_test_mailbox('', 3, $mailbox); // set up temp mailbox with 3 messages
+$options = CL_EXPUNGE;
+
+// mark messages in inbox for deletion
+for ($i = 1; $i < 4; $i++) {
+ imap_delete($stream_id, $i);
+}
+
+// Calling imap_close() with all possible arguments
+echo "\n-- Call to imap_close() with all possible arguments --\n";
+var_dump( imap_close($stream_id, $options) );
+
+// check that CL_EXPUNGE worked
+$stream_id = imap_open($mailbox, $username, $password);
+echo "There are now " . imap_num_msg($stream_id) . " msgs in mailbox '$mailbox'\n";
+
+// Calling imap_close() with mandatory arguments
+echo "\n-- Call to imap_close() with mandatory arguments --\n";
+var_dump( imap_close($stream_id) );
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_close() : basic functionality ***
+Create a temporary mailbox and add 3 msgs
+.. mailbox '%sINBOX.phpttest' created
+
+-- Call to imap_close() with all possible arguments --
+bool(true)
+There are now 0 msgs in mailbox '%sINBOX.phpttest'
+
+-- Call to imap_close() with mandatory arguments --
+bool(true)
+===DONE===
diff --git a/ext/imap/tests/imap_close_error.phpt b/ext/imap/tests/imap_close_error.phpt
new file mode 100644
index 000000000..2fbe0ec82
--- /dev/null
+++ b/ext/imap/tests/imap_close_error.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Test imap_close() function : error conditions - incorrect number of args
+--SKIPIF--
+<?php
+require_once (dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : bool imap_close(resource $stream_id [, int $options])
+ * Description: Close an IMAP stream
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass an incorrect number of arguments to imap_close() to test behaviour
+ */
+
+echo "*** Testing imap_close() : error conditions ***\n";
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+// Zero arguments
+echo "\n-- Testing imap_close() function with Zero arguments --\n";
+var_dump( imap_close() );
+
+//Test imap_close with one more than the expected number of arguments
+echo "\n-- Testing imap_close() function with more than expected no. of arguments --\n";
+$stream_id = imap_open($server, $username, $password);
+$options = CL_EXPUNGE;
+$extra_arg = 10;
+var_dump( imap_close($stream_id, $options, $extra_arg) );
+?>
+===DONE===
+--EXPECTF--
+*** Testing imap_close() : error conditions ***
+
+-- Testing imap_close() function with Zero arguments --
+
+Warning: Wrong parameter count for imap_close() in %s on line %d
+NULL
+
+-- Testing imap_close() function with more than expected no. of arguments --
+
+Warning: Wrong parameter count for imap_close() in %s on line %d
+NULL
+===DONE===
diff --git a/ext/imap/tests/imap_close_variation1.phpt b/ext/imap/tests/imap_close_variation1.phpt
new file mode 100644
index 000000000..e5ffa2ecb
--- /dev/null
+++ b/ext/imap/tests/imap_close_variation1.phpt
@@ -0,0 +1,214 @@
+--TEST--
+Test imap_close() function : usage variations - different data types as $stream_id arg
+--SKIPIF--
+<?php
+extension_loaded('imap') or die('skip imap extension not available in this build');
+?>
+--FILE--
+<?php
+/* Prototype : bool imap_close(resource $stream_id [, int $options])
+ * Description: Close an IMAP stream
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different data types as $stream_id argument to test behaviour of imap_close()
+ */
+
+echo "*** Testing imap_close() : usage variations ***\n";
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a class
+class classA
+{
+ public function __toString() {
+ return "Class A object";
+ }
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// unexpected values to be passed to $stream_id argument
+$inputs = array(
+
+ // int data
+/*1*/ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+/*5*/ 10.5,
+ -10.5,
+ 12.3456789000e10,
+ 12.3456789000E-10,
+ .5,
+
+ // null data
+/*10*/ NULL,
+ null,
+
+ // boolean data
+/*12*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+/*16*/ "",
+ '',
+ array(),
+
+ // string data
+/*19*/ "string",
+ 'string',
+ $heredoc,
+
+ // object data
+/*22*/ new classA(),
+
+ // undefined data
+/*23*/ @$undefined_var,
+
+ // unset data
+/*24*/ @$unset_var,
+);
+
+// loop through each element of $inputs to check the behavior of imap_close()
+$iterator = 1;
+foreach($inputs as $input) {
+ echo "\n-- Iteration $iterator --\n";
+ var_dump( imap_close($input) );
+ $iterator++;
+};
+?>
+===DONE===
+--EXPECTF--
+*** Testing imap_close() : usage variations ***
+
+-- Iteration 1 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 2 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 3 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 4 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 5 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 6 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 7 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 8 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 9 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 10 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 11 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 12 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 13 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 14 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 15 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 16 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 17 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 18 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 19 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 20 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 21 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 22 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 23 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 24 --
+
+Warning: imap_close(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/imap/tests/imap_close_variation2.phpt b/ext/imap/tests/imap_close_variation2.phpt
new file mode 100644
index 000000000..3aa9f2a7e
--- /dev/null
+++ b/ext/imap/tests/imap_close_variation2.phpt
@@ -0,0 +1,221 @@
+--TEST--
+Test imap_close() function : usage variations - different data types as $options arg
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : bool imap_close(resource $stream_id [, int $options])
+ * Description: Close an IMAP stream
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different data types as $options argument to test behaviour of imap_close()
+ */
+
+echo "*** Testing imap_close() : usage variations ***\n";
+
+// include file for imap_stream
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+// create mailbox to test whether options has been set to CL_EXPUNGE
+$stream_id = setup_test_mailbox('', 3, $mailbox);
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// heredoc string
+$heredoc = <<<EOT
+32768
+EOT;
+
+// unexpected values to be passed to $options argument
+$inputs = array(
+
+ // int data
+/*1*/ 0,
+ 1,
+ 32768,
+ -2345,
+
+ // float data
+/*5*/ 10.5,
+ -10.5,
+ 12.3456789000e10,
+ 12.3456789000E-10,
+ .5,
+
+ // null data
+/*10*/ NULL,
+ null,
+
+ // boolean data
+/*12*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+/*16*/ "",
+ '',
+ array(),
+
+ // string data
+/*19*/ "32768",
+ '32768',
+ $heredoc,
+
+ // undefined data
+/*22*/ @$undefined_var,
+
+ // unset data
+/*23*/ @$unset_var,
+);
+
+// loop through each element of $inputs to check the behavior of imap_close()
+$iterator = 1;
+foreach($inputs as $input) {
+
+ // mark added messages for deletion
+ for ($i = 1; $i < 4; $i++) {
+ imap_delete($stream_id, $i);
+ }
+ echo "\n-- Iteration $iterator --\n";
+ var_dump( $check = imap_close($stream_id, $input) );
+
+ // check that imap_close was successful, if not call imap_close and explicitly set CL_EXPUNGE
+ if(false === $check) {
+ imap_close($stream_id, CL_EXPUNGE);
+ } else {
+ // if imap_close was successful test whether CL_EXPUNGE was set by doing a message count
+ $imap_stream = imap_open($mailbox, $username, $password);
+ $num_msg = imap_num_msg($imap_stream);
+ if ($num_msg != 0) {
+ echo "CL_EXPUNGE was not set, $num_msg msgs in mailbox\n";
+ } else {
+ echo "CL_EXPUNGE was set\n";
+ }
+ // call imap_close with CL_EXPUNGE explicitly set in case mailbox not empty
+ imap_close($imap_stream, CL_EXPUNGE);
+ }
+ $iterator++;
+
+ // get $stream_id for next iteration
+ $stream_id = imap_open($mailbox, $username, $password);
+ populate_mailbox($stream_id, $mailbox, 3);
+
+};
+
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_close() : usage variations ***
+Create a temporary mailbox and add 3 msgs
+.. mailbox '{localhost/norsh}INBOX.phpttest' created
+
+-- Iteration 1 --
+bool(true)
+CL_EXPUNGE was not set, 3 msgs in mailbox
+
+-- Iteration 2 --
+
+Warning: imap_close(): invalid value for the flags parameter in %s on line %d
+bool(false)
+
+-- Iteration 3 --
+bool(true)
+CL_EXPUNGE was set
+
+-- Iteration 4 --
+
+Warning: imap_close(): invalid value for the flags parameter in %s on line %d
+bool(false)
+
+-- Iteration 5 --
+
+Warning: imap_close(): invalid value for the flags parameter in %s on line %d
+bool(false)
+
+-- Iteration 6 --
+
+Warning: imap_close(): invalid value for the flags parameter in %s on line %d
+bool(false)
+
+-- Iteration 7 --
+
+Warning: imap_close(): invalid value for the flags parameter in %s on line %d
+bool(false)
+
+-- Iteration 8 --
+bool(true)
+CL_EXPUNGE was not set, 3 msgs in mailbox
+
+-- Iteration 9 --
+bool(true)
+CL_EXPUNGE was not set, 3 msgs in mailbox
+
+-- Iteration 10 --
+bool(true)
+CL_EXPUNGE was not set, 3 msgs in mailbox
+
+-- Iteration 11 --
+bool(true)
+CL_EXPUNGE was not set, 3 msgs in mailbox
+
+-- Iteration 12 --
+
+Warning: imap_close(): invalid value for the flags parameter in %s on line %d
+bool(false)
+
+-- Iteration 13 --
+bool(true)
+CL_EXPUNGE was not set, 3 msgs in mailbox
+
+-- Iteration 14 --
+
+Warning: imap_close(): invalid value for the flags parameter in %s on line %d
+bool(false)
+
+-- Iteration 15 --
+bool(true)
+CL_EXPUNGE was not set, 3 msgs in mailbox
+
+-- Iteration 16 --
+bool(true)
+CL_EXPUNGE was not set, 3 msgs in mailbox
+
+-- Iteration 17 --
+bool(true)
+CL_EXPUNGE was not set, 3 msgs in mailbox
+
+-- Iteration 18 --
+bool(true)
+CL_EXPUNGE was not set, 3 msgs in mailbox
+
+-- Iteration 19 --
+bool(true)
+CL_EXPUNGE was set
+
+-- Iteration 20 --
+bool(true)
+CL_EXPUNGE was set
+
+-- Iteration 21 --
+bool(true)
+CL_EXPUNGE was set
+
+-- Iteration 22 --
+bool(true)
+CL_EXPUNGE was not set, 3 msgs in mailbox
+
+-- Iteration 23 --
+bool(true)
+CL_EXPUNGE was not set, 3 msgs in mailbox
+===DONE===
diff --git a/ext/imap/tests/imap_close_variation3.phpt b/ext/imap/tests/imap_close_variation3.phpt
new file mode 100644
index 000000000..5f2790b31
--- /dev/null
+++ b/ext/imap/tests/imap_close_variation3.phpt
@@ -0,0 +1,47 @@
+--TEST--
+Test imap_close() function : usage variations - different streams
+--SKIPIF--
+<?php
+extension_loaded('imap') or die('skip imap extension not available in this build');
+?>
+--FILE--
+<?php
+/* Prototype : bool imap_close(resource $stream_id [, int $options])
+ * Description: Close an IMAP stream
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different stream types to imap_close() to test whether it can close them
+ */
+
+echo "*** Testing imap_close() : usage variations ***\n";
+
+echo "\n-- File Resource opened with fopen() --\n";
+var_dump($file_handle = fopen(__FILE__, 'r'));
+var_dump(imap_close($file_handle));
+var_dump($file_handle);
+
+echo "\n-- Directory Resource opened with opendir() --\n";
+var_dump($dir_handle = opendir(dirname(__FILE__)));
+var_dump(imap_close($dir_handle));
+var_dump($dir_handle);
+?>
+===DONE===
+--EXPECTF--
+*** Testing imap_close() : usage variations ***
+
+-- File Resource opened with fopen() --
+resource(%d) of type (stream)
+
+Warning: imap_close(): supplied resource is not a valid imap resource in %s on line %d
+bool(false)
+resource(%d) of type (stream)
+
+-- Directory Resource opened with opendir() --
+resource(%d) of type (stream)
+
+Warning: imap_close(): supplied resource is not a valid imap resource in %s on line %d
+bool(false)
+resource(%d) of type (stream)
+===DONE===
diff --git a/ext/imap/tests/imap_close_variation4.phpt b/ext/imap/tests/imap_close_variation4.phpt
new file mode 100644
index 000000000..65b05786f
--- /dev/null
+++ b/ext/imap/tests/imap_close_variation4.phpt
@@ -0,0 +1,93 @@
+--TEST--
+Test imap_close() function : usage variations - different ints as $options arg
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : bool imap_close(resource $stream_id [, int $options])
+ * Description: Close an IMAP stream
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different integers as $options arg to imap_close() to test which are
+ * recognised as CL_EXPUNGE option
+ */
+
+echo "*** Testing imap_close() : usage variations ***\n";
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+$inputs = array (0, 3.2768e4, -32768, PHP_INT_MAX, -PHP_INT_MAX);
+
+$stream_id = setup_test_mailbox('', 3, $mailbox); // set up temp mailbox with 3 messages
+
+// loop through each element of $inputs to check the behavior of imap_close()
+$iterator = 1;
+foreach($inputs as $input) {
+
+ // mark added messages for deletion
+ for ($i = 1; $i < 4; $i++) {
+ imap_delete($stream_id, $i);
+ }
+ echo "\n-- Iteration $iterator --\n";
+ var_dump( $check = imap_close($stream_id, $input) );
+
+ // check that imap_close was successful, if not call imap_close and explicitly set CL_EXPUNGE
+ if(false === $check) {
+ imap_close($stream_id, CL_EXPUNGE);
+ } else {
+ // if imap_close was successful test whether CL_EXPUNGE was set by doing a message count
+ $imap_stream = imap_open($mailbox, $username, $password);
+ $num_msg = imap_num_msg($imap_stream);
+ if ($num_msg != 0) {
+ echo "CL_EXPUNGE was not set, $num_msg msgs in mailbox\n";
+ } else {
+ echo "CL_EXPUNGE was set\n";
+ }
+ // call imap_close with CL_EXPUNGE explicitly set in case mailbox not empty
+ imap_close($imap_stream, CL_EXPUNGE);
+ }
+ $iterator++;
+
+ // get $stream_id for next iteration
+ $stream_id = imap_open($mailbox, $username, $password);
+ populate_mailbox($stream_id, $mailbox, 3);
+
+};
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_close() : usage variations ***
+Create a temporary mailbox and add 3 msgs
+.. mailbox '{localhost/norsh}INBOX.phpttest' created
+
+-- Iteration 1 --
+bool(true)
+CL_EXPUNGE was not set, 3 msgs in mailbox
+
+-- Iteration 2 --
+bool(true)
+CL_EXPUNGE was set
+
+-- Iteration 3 --
+
+Warning: imap_close(): invalid value for the flags parameter in %s on line %d
+bool(false)
+
+-- Iteration 4 --
+
+Warning: imap_close(): invalid value for the flags parameter in %s on line %d
+bool(false)
+
+-- Iteration 5 --
+
+Warning: imap_close(): invalid value for the flags parameter in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/imap/tests/imap_createmailbox_basic.phpt b/ext/imap/tests/imap_createmailbox_basic.phpt
new file mode 100644
index 000000000..e80c87dc8
--- /dev/null
+++ b/ext/imap/tests/imap_createmailbox_basic.phpt
@@ -0,0 +1,69 @@
+--TEST--
+Test imap_createmailbox() function : basic functionality
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : bool imap_createmailbox ( resource $imap_stream , string $mailbox )
+ * Description: Creates a new mailbox specified by mailbox .
+ * Source code: ext/imap/php_imap.c
+ */
+
+echo "*** Testing imap_createmailbox() : basic functionality ***\n";
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+$imap_stream = imap_open($default_mailbox, $username, $password) or
+ die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
+
+$newname = "phpnewbox";
+
+echo "Newname will be '$newname'\n";
+
+$newbox = imap_utf7_encode($server.$newname);
+if (imap_createmailbox($imap_stream, $newbox)) {
+
+ echo "Add a couple of msgs to '$newname' mailbox\n";
+ populate_mailbox($imap_stream, $newbox, 2);
+
+ $status = imap_status($imap_stream, $newbox, SA_ALL);
+ if ($status) {
+ echo "Your new mailbox '$newname' has the following status:\n";
+ echo "Messages: " . $status->messages . "\n";
+ echo "Recent: " . $status->recent . "\n";
+ echo "Unseen: " . $status->unseen . "\n";
+ echo "UIDnext: " . $status->uidnext . "\n";
+ echo "UIDvalidity: " . $status->uidvalidity . "\n";
+
+ } else {
+ echo "imap_status on new mailbox failed: " . imap_last_error() . "\n";
+ }
+
+ if (imap_deletemailbox($imap_stream, $newbox)) {
+ echo "Mailbox '$newname' removed to restore initial state\n";
+ } else {
+ echo "imap_deletemailbox on new mailbox failed: " . implode("\n", imap_errors()) . "\n";
+ }
+
+} else {
+ echo "could not create new mailbox: " . implode("\n", imap_errors()) . "\n";
+}
+
+imap_close($imap_stream);
+
+?>
+===Done===
+--EXPECTF--
+*** Testing imap_createmailbox() : basic functionality ***
+Newname will be 'phpnewbox'
+Add a couple of msgs to 'phpnewbox' mailbox
+Your new mailbox 'phpnewbox' has the following status:
+Messages: 2
+Recent: 2
+Unseen: 2
+UIDnext: %d
+UIDvalidity: %d
+Mailbox 'phpnewbox' removed to restore initial state
+===Done===
diff --git a/ext/imap/tests/imap_errors_basic.phpt b/ext/imap/tests/imap_errors_basic.phpt
new file mode 100644
index 000000000..f839fe152
--- /dev/null
+++ b/ext/imap/tests/imap_errors_basic.phpt
@@ -0,0 +1,55 @@
+--TEST--
+Test imap_errors() function : basic functionality
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : array imap_errors ( void )
+ * Description: Returns all of the IMAP errors that have occured.
+ * Source code: ext/imap/php_imap.c
+ */
+
+echo "*** Testing imap_errors() : basic functionality ***\n";
+require_once(dirname(__FILE__).'/imap_include.inc');
+$password = "bogus"; // invalid password to use in this test
+
+echo "Issue open with invalid password with normal default number of retries, i.e 3\n";
+$mbox = imap_open($default_mailbox, $username, $password, OP_READONLY, 3);
+
+echo "List any errors\n";
+var_dump(imap_errors());
+
+echo "\n\nIssue open with invalid password with retries == 1\n";
+$mbox = imap_open($default_mailbox, $username, $password, OP_READONLY, 1);
+
+echo "List any errors\n";
+var_dump(imap_errors());
+?>
+===Done===
+--EXPECTF--
+*** Testing imap_errors() : basic functionality ***
+Issue open with invalid password with normal default number of retries, i.e 3
+
+Warning: imap_open(): Couldn't open stream %s in %s on line %d
+List any errors
+array(%d) {
+ [0]=>
+ string(%d) "%s"
+ [1]=>
+ string(%d) "%s"
+ [2]=>
+ string(%d) "%a
+}
+
+
+Issue open with invalid password with retries == 1
+
+Warning: imap_open(): Couldn't open stream %s in %s on line %d
+List any errors
+array(%d) {
+ [0]=>
+ string(%d) "%a
+}
+===Done===
diff --git a/ext/imap/tests/imap_fetch_overview_basic.phpt b/ext/imap/tests/imap_fetch_overview_basic.phpt
new file mode 100644
index 000000000..80d5c69f1
--- /dev/null
+++ b/ext/imap/tests/imap_fetch_overview_basic.phpt
@@ -0,0 +1,118 @@
+--TEST--
+Test imap_fetch_overview() function : basic functionality
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : array imap_fetch_overview(resource $stream_id, int $msg_no [, int $options])
+ * Description: Read an overview of the information in the headers
+ * of the given message sequence
+ * Source code: ext/imap/php_imap.c
+ */
+
+echo "*** Testing imap_fetch_overview() : basic functionality ***\n";
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+// create a new mailbox and add two new messages to it
+$stream_id = setup_test_mailbox('', 2, $mailbox, 'notSimple');
+
+// get UID for new message
+$msg_no = imap_uid($stream_id, 1);
+$options = FT_UID;
+
+//Set mandatory response fields
+$mandatoryFields = array(
+ 'size',
+ 'uid',
+ 'msgno',
+ 'recent',
+ 'flagged',
+ 'answered',
+ 'deleted',
+ 'seen',
+ 'draft',
+ );
+
+// Calling imap_fetch_overview() with all possible arguments
+echo "\n-- All possible arguments --\n";
+$a = imap_fetch_overview($stream_id, "$msg_no", $options) ;
+echo "\n--> Object #1\n";
+foreach ($mandatoryFields as $mf)
+{
+ $z = $a[0]->$mf;
+ echo "$mf is $z\n";
+}
+
+// Calling imap_fetch_overview() with mandatory arguments
+echo "\n-- Mandatory arguments --\n";
+$a = imap_fetch_overview($stream_id, '1:2') ;
+
+//first object in array
+echo "\n--> Object #1\n";
+foreach ($mandatoryFields as $mf)
+{
+ $z = $a[0]->$mf;
+ echo "$mf is $z\n";
+}
+
+//Second object in array
+echo "\n--> Object #2\n";
+foreach ($mandatoryFields as $mf)
+{
+ $z = $a[1]->$mf;
+ echo "$mf is $z\n";
+}
+
+imap_close($stream_id);
+
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_fetch_overview() : basic functionality ***
+Create a temporary mailbox and add 2 msgs
+.. mailbox '{localhost/norsh}INBOX.phpttest' created
+
+-- All possible arguments --
+
+--> Object #1
+size is %d
+uid is %d
+msgno is 1
+recent is %d
+flagged is 0
+answered is 0
+deleted is 0
+seen is 0
+draft is 0
+
+-- Mandatory arguments --
+
+--> Object #1
+size is %d
+uid is %d
+msgno is 1
+recent is %d
+flagged is 0
+answered is 0
+deleted is 0
+seen is 0
+draft is 0
+
+--> Object #2
+size is %d
+uid is %d
+msgno is 2
+recent is %d
+flagged is 0
+answered is 0
+deleted is 0
+seen is 0
+draft is 0
+===DONE===
diff --git a/ext/imap/tests/imap_fetch_overview_error.phpt b/ext/imap/tests/imap_fetch_overview_error.phpt
new file mode 100644
index 000000000..fa8c18232
--- /dev/null
+++ b/ext/imap/tests/imap_fetch_overview_error.phpt
@@ -0,0 +1,54 @@
+--TEST--
+Test imap_fetch_overview() function : error conditions - incorrect number of args
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : array imap_fetch_overview(resource $stream_id, int $msg_no [, int $options])
+ * Description: Read an overview of the information in the headers
+ * of the given message sequence
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass an incorrect number of arguments to imap_fetch_overview() to test behaviour
+ */
+
+echo "*** Testing imap_fetch_overview() : error conditions ***\n";
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+//Test imap_fetch_overview with one more than the expected number of arguments
+echo "\n-- Testing imap_fetch_overview() function with more than expected no. of arguments --\n";
+$stream_id = setup_test_mailbox('', 2, $mailbox, 'notSimple'); // set up temp mailbox with 2 msgs
+$msg_no = 1;
+$options = FT_UID;
+$extra_arg = 10;
+var_dump( imap_fetch_overview($stream_id, $msg_no, $options, $extra_arg) );
+
+// Testing imap_fetch_overview with one less than the expected number of arguments
+echo "\n-- Testing imap_fetch_overview() function with less than expected no. of arguments --\n";
+var_dump( imap_fetch_overview($stream_id) );
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_fetch_overview() : error conditions ***
+
+-- Testing imap_fetch_overview() function with more than expected no. of arguments --
+Create a temporary mailbox and add 2 msgs
+.. mailbox '%s.phpttest' created
+
+Warning: Wrong parameter count for imap_fetch_overview() in %s on line %d
+NULL
+
+-- Testing imap_fetch_overview() function with less than expected no. of arguments --
+
+Warning: Wrong parameter count for imap_fetch_overview() in %s on line %d
+NULL
+===DONE===
diff --git a/ext/imap/tests/imap_fetch_overview_variation1.phpt b/ext/imap/tests/imap_fetch_overview_variation1.phpt
new file mode 100644
index 000000000..a7d86b434
--- /dev/null
+++ b/ext/imap/tests/imap_fetch_overview_variation1.phpt
@@ -0,0 +1,221 @@
+--TEST--
+Test imap_fetch_overview() function : usage variations - diff data types as $stream_id arg
+--SKIPIF--
+<?php
+extension_loaded('imap') or die('skip imap extension not available in this build');
+?>
+--FILE--
+<?php
+/* Prototype : array imap_fetch_overview(resource $stream_id, int $msg_no [, int $options])
+ * Description: Read an overview of the information in the headers
+ * of the given message sequence
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different data types as $stream_id argument to imap_fetch_overview() to test behaviour
+ */
+
+echo "*** Testing imap_fetch_overview() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$msg_no = 1;
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a class
+class classA
+{
+ public function __toString() {
+ return "Class A object";
+ }
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// unexpected values to be passed to $stream_id argument
+$inputs = array(
+
+ // int data
+/*1*/ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+/*5*/ 10.5,
+ -10.5,
+ 12.3456789000e10,
+ 12.3456789000E-10,
+ .5,
+
+ // null data
+/*10*/ NULL,
+ null,
+
+ // boolean data
+/*12*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+/*16*/ "",
+ '',
+ array(),
+
+ // string data
+/*19*/ "string",
+ 'string',
+ $heredoc,
+
+ // object data
+/*22*/ new classA(),
+
+ // undefined data
+/*23*/ @$undefined_var,
+
+ // unset data
+/*24*/ @$unset_var,
+);
+
+// loop through each element of $inputs to check the behavior of imap_fetch_overview()
+$iterator = 1;
+foreach($inputs as $input) {
+ echo "\n-- Testing with first argument value: ";
+ var_dump($input);
+ var_dump( imap_fetch_overview($input, $msg_no) );
+ $iterator++;
+};
+?>
+===DONE===
+--EXPECTF--
+*** Testing imap_fetch_overview() : usage variations ***
+
+-- Testing with first argument value: int(0)
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: int(1)
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: int(12345)
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: int(-2345)
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: float(10.5)
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: float(-10.5)
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: float(123456789000)
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: float(1.23456789E-9)
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: float(0.5)
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: NULL
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: NULL
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: bool(true)
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: bool(false)
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: bool(true)
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: bool(false)
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: string(0) ""
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: string(0) ""
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: array(0) {
+}
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: string(6) "string"
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: string(6) "string"
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: string(11) "hello world"
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: object(classA)#1 (0) {
+}
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: NULL
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Testing with first argument value: NULL
+
+Warning: imap_fetch_overview(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/imap/tests/imap_fetch_overview_variation2.phpt b/ext/imap/tests/imap_fetch_overview_variation2.phpt
new file mode 100644
index 000000000..18f2af3be
--- /dev/null
+++ b/ext/imap/tests/imap_fetch_overview_variation2.phpt
@@ -0,0 +1,243 @@
+--TEST--
+Test imap_fetch_overview() function : usage variations - diff data types as $msg_no arg
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : array imap_fetch_overview(resource $stream_id, int $msg_no [, int $options])
+ * Description: Read an overview of the information in the headers
+ * of the given message sequence
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different data types as $msg_no argument to imap_fetch_overview() to test behaviour
+ */
+
+echo "*** Testing imap_fetch_overview() : usage variations ***\n";
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+// Initialise function arguments not being substituted
+$stream_id = setup_test_mailbox('', 1, $mailbox, 'notSimple'); // set up temp mailbox with 1 msg
+
+//Set mandatory response fields
+$mandatoryFields = array(
+ 'size',
+ 'uid',
+ 'msgno',
+ 'recent',
+ 'flagged',
+ 'answered',
+ 'deleted',
+ 'seen',
+ 'draft',
+ );
+
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a class
+class classA
+{
+ public function __toString() {
+ return "Class A object";
+ }
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// get a resource variable
+$fp = fopen(__FILE__, "r");
+
+// unexpected values to be passed to <<<ARGUMENT HERE>>> argument
+$inputs = array(
+
+ // int data
+/*1*/ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+/*5*/ 10.5,
+ -10.5,
+ 12.3456789000e10,
+ 12.3456789000E-10,
+ .5,
+
+ // null data
+/*10*/ NULL,
+ null,
+
+ // boolean data
+/*12*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+/*16*/ "",
+ '',
+ array(),
+
+ // string data
+/*19*/ "string",
+ 'string',
+ $heredoc,
+
+ // object data
+/*22*/ new classA(),
+
+ // undefined data
+/*23*/ @$undefined_var,
+
+ // unset data
+/*24*/ @$unset_var,
+
+ // resource variable
+/*25*/ $fp
+);
+
+// loop through each element of $inputs to check the behavior of imap_fetch_overview()
+$iterator = 1;
+foreach($inputs as $input) {
+ echo "\n-- Testing with second argument value: ";
+ var_dump($input);
+ $overview = imap_fetch_overview($stream_id, $input);
+ if (!$overview) {
+ echo imap_last_error() . "\n";
+ } else {
+ foreach ($mandatoryFields as $mf)
+ {
+ $z = $overview[0]->$mf;
+ echo "$mf is $z\n";
+ }
+ }
+ $iterator++;
+};
+
+fclose($fp);
+
+// clear the error stack
+imap_errors();
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_fetch_overview() : usage variations ***
+Create a temporary mailbox and add 1 msgs
+.. mailbox '{localhost/norsh}INBOX.phpttest' created
+
+-- Testing with second argument value: int(0)
+Sequence out of range
+
+-- Testing with second argument value: int(1)
+size is %d
+uid is %d
+msgno is 1
+recent is %d
+flagged is 0
+answered is 0
+deleted is 0
+seen is 0
+draft is 0
+
+-- Testing with second argument value: int(12345)
+Sequence out of range
+
+-- Testing with second argument value: int(-2345)
+Syntax error in sequence
+
+-- Testing with second argument value: float(10.5)
+Sequence out of range
+
+-- Testing with second argument value: float(-10.5)
+Syntax error in sequence
+
+-- Testing with second argument value: float(123456789000)
+Sequence out of range
+
+-- Testing with second argument value: float(1.23456789E-9)
+Sequence syntax error
+
+-- Testing with second argument value: float(0.5)
+Sequence out of range
+
+-- Testing with second argument value: NULL
+Sequence out of range
+
+-- Testing with second argument value: NULL
+Sequence out of range
+
+-- Testing with second argument value: bool(true)
+size is %d
+uid is %d
+msgno is 1
+recent is %d
+flagged is 0
+answered is 0
+deleted is 0
+seen is 0
+draft is 0
+
+-- Testing with second argument value: bool(false)
+Sequence out of range
+
+-- Testing with second argument value: bool(true)
+size is %d
+uid is %d
+msgno is 1
+recent is %d
+flagged is 0
+answered is 0
+deleted is 0
+seen is 0
+draft is 0
+
+-- Testing with second argument value: bool(false)
+Sequence out of range
+
+-- Testing with second argument value: string(0) ""
+Sequence out of range
+
+-- Testing with second argument value: string(0) ""
+Sequence out of range
+
+-- Testing with second argument value: array(0) {
+}
+
+Notice: Array to string conversion in %s on line %d
+Syntax error in sequence
+
+-- Testing with second argument value: string(6) "string"
+Syntax error in sequence
+
+-- Testing with second argument value: string(6) "string"
+Syntax error in sequence
+
+-- Testing with second argument value: string(11) "hello world"
+Syntax error in sequence
+
+-- Testing with second argument value: object(classA)#1 (0) {
+}
+Syntax error in sequence
+
+-- Testing with second argument value: NULL
+Syntax error in sequence
+
+-- Testing with second argument value: NULL
+Syntax error in sequence
+
+-- Testing with second argument value: resource(%d) of type (stream)
+Syntax error in sequence
+===DONE===
diff --git a/ext/imap/tests/imap_fetch_overview_variation3.phpt b/ext/imap/tests/imap_fetch_overview_variation3.phpt
new file mode 100644
index 000000000..4ec4fae6e
--- /dev/null
+++ b/ext/imap/tests/imap_fetch_overview_variation3.phpt
@@ -0,0 +1,79 @@
+--TEST--
+Test imap_fetch_overview() function : usage variations - FT_UID option
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : array imap_fetch_overview(resource $stream_id, int $msg_no [, int $options])
+ * Description: Read an overview of the information in the headers of the given message sequence
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Test passing a range of values into the $options argument to imap_fetch_overview():
+ * 1. values that equate to 1
+ * 2. Minimum and maximum PHP values
+ */
+
+echo "*** Testing imap_fetch_overview() : usage variations ***\n";
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+// Initialise required variables
+$stream_id = setup_test_mailbox('', 1); // set up temporary mailbox with one simple message
+$msg_no = 1;
+$msg_uid=imap_uid($stream_id, $msg_no);
+$options = array ('1',
+ true,
+ 1.000000000000001,
+ 0.00001e5,
+ PHP_INT_MAX,
+ -PHP_INT_MAX
+ );
+
+// iterate over each element of $options array
+$iterator = 1;
+imap_check($stream_id);
+foreach($options as $option) {
+ echo "\nTesting with option value:";
+ var_dump($option);
+ $overview = imap_fetch_overview($stream_id, $msg_uid, $option);
+ if ($overview) {
+ echo "imap_fetch_overview() returns an object\n";
+ }
+ $iterator++;
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_fetch_overview() : usage variations ***
+Create a temporary mailbox and add 1 msgs
+.. mailbox '{localhost/norsh}INBOX.phpttest' created
+
+Testing with option value:string(1) "1"
+imap_fetch_overview() returns an object
+
+Testing with option value:bool(true)
+imap_fetch_overview() returns an object
+
+Testing with option value:float(1)
+imap_fetch_overview() returns an object
+
+Testing with option value:float(1)
+imap_fetch_overview() returns an object
+
+Testing with option value:int(%d)
+
+Warning: imap_fetch_overview(): invalid value for the options parameter in %s on line %d
+
+Testing with option value:int(-%d)
+
+Warning: imap_fetch_overview(): invalid value for the options parameter in %s on line %d
+===DONE===
diff --git a/ext/imap/tests/imap_fetch_overview_variation4.phpt b/ext/imap/tests/imap_fetch_overview_variation4.phpt
new file mode 100644
index 000000000..a5c266631
--- /dev/null
+++ b/ext/imap/tests/imap_fetch_overview_variation4.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Test imap_fetch_overview() function : usage variations - different resources as $stream_id
+--SKIPIF--
+<?php
+extension_loaded('imap') or die('skip imap extension not available in this build');
+?>
+--FILE--
+<?php
+/* Prototype : array imap_fetch_overview(resource $stream_id, int $msg_no [, int $options])
+ * Description: Read an overview of the information in the headers
+ * of the given message sequence
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different resource types to imap_fetch_overview() to test behaviour
+ */
+
+echo "*** Testing imap_fetch_overview() : usage variations ***\n";
+
+echo "\n-- File Resource opened with fopen() --\n";
+var_dump($file_pointer = fopen(__FILE__, 'r+'));
+var_dump(imap_fetch_overview($file_pointer, 1));
+fclose($file_pointer);
+
+echo "\n-- Directory Resource opened with opendir() --\n";
+var_dump($dir_handle = opendir(dirname(__FILE__)));
+var_dump(imap_fetch_overview($dir_handle, 1));
+closedir($dir_handle);
+?>
+===DONE===
+--EXPECTF--
+*** Testing imap_fetch_overview() : usage variations ***
+
+-- File Resource opened with fopen() --
+resource(%d) of type (stream)
+
+Warning: imap_fetch_overview(): supplied resource is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Directory Resource opened with opendir() --
+resource(%d) of type (stream)
+
+Warning: imap_fetch_overview(): supplied resource is not a valid imap resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/imap/tests/imap_fetch_overview_variation5.phpt b/ext/imap/tests/imap_fetch_overview_variation5.phpt
new file mode 100644
index 000000000..79861be7a
--- /dev/null
+++ b/ext/imap/tests/imap_fetch_overview_variation5.phpt
@@ -0,0 +1,149 @@
+--TEST--
+Test imap_fetch_overview() function : usage variations - $msg_no argument
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : array imap_fetch_overview(resource $stream_id, int $msg_no [, int $options])
+ * Description: Read an overview of the information in the headers
+ * of the given message sequence
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different sequences/msg numbers as $msg_no argument to test behaviour
+ * of imap_fetch_overview()
+ */
+
+echo "*** Testing imap_fetch_overview() : usage variations ***\n";
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+$stream_id = setup_test_mailbox('', 3, $mailbox, 'notSimple'); // set up temp mailbox with 3 msgs
+
+//Set mandatory response fields
+$mandatoryFields = array(
+ 'size',
+ 'uid',
+ 'msgno',
+ 'recent',
+ 'flagged',
+ 'answered',
+ 'deleted',
+ 'seen',
+ 'draft',
+ );
+
+$sequences = array (0, 4, '4', // out of range
+ '2', '1,3', '1, 2',
+ '1:3'); // pass uid without setting FT_UID option
+
+foreach($sequences as $msg_no) {
+ echo "\n-- \$msg_no is $msg_no --\n";
+ $overview = imap_fetch_overview($stream_id, $msg_no);
+ if (!$overview) {
+ echo imap_last_error() . "\n";
+ } else {
+ foreach($overview as $ov) {
+ echo "\n";
+ foreach ($mandatoryFields as $mf)
+ {
+ $z = $ov->$mf;
+ echo "$mf is $z\n";
+ }
+ }
+ }
+}
+
+// clear error stack
+imap_errors();
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_fetch_overview() : usage variations ***
+Create a temporary mailbox and add 3 msgs
+.. mailbox '{localhost/norsh}INBOX.phpttest' created
+
+-- $msg_no is 0 --
+Sequence out of range
+
+-- $msg_no is 4 --
+Sequence out of range
+
+-- $msg_no is 4 --
+Sequence out of range
+
+-- $msg_no is 2 --
+
+size is %d
+uid is %d
+msgno is 2
+recent is %d
+flagged is 0
+answered is 0
+deleted is 0
+seen is 0
+draft is 0
+
+-- $msg_no is 1,3 --
+
+size is %d
+uid is %d
+msgno is 1
+recent is %d
+flagged is 0
+answered is 0
+deleted is 0
+seen is 0
+draft is 0
+
+size is %d
+uid is %d
+msgno is 3
+recent is %d
+flagged is 0
+answered is 0
+deleted is 0
+seen is 0
+draft is 0
+
+-- $msg_no is 1, 2 --
+Syntax error in sequence
+
+-- $msg_no is 1:3 --
+
+size is %d
+uid is %d
+msgno is 1
+recent is %d
+flagged is 0
+answered is 0
+deleted is 0
+seen is 0
+draft is 0
+
+size is %d
+uid is %d
+msgno is 2
+recent is %d
+flagged is 0
+answered is 0
+deleted is 0
+seen is 0
+draft is 0
+
+size is %d
+uid is %d
+msgno is 3
+recent is %d
+flagged is 0
+answered is 0
+deleted is 0
+seen is 0
+draft is 0
+===DONE===
diff --git a/ext/imap/tests/imap_fetch_overview_variation6.phpt b/ext/imap/tests/imap_fetch_overview_variation6.phpt
new file mode 100644
index 000000000..fda937e24
--- /dev/null
+++ b/ext/imap/tests/imap_fetch_overview_variation6.phpt
@@ -0,0 +1,125 @@
+--TEST--
+Test imap_fetch_overview() function : usage variations - multipart message
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : array imap_fetch_overview(resource $stream_id, int $msg_no [, int $options])
+ * Description: Read an overview of the information in the headers of the given message sequence
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass a multipart message to imap_fetch_overview() to test the contents of returned array
+ */
+
+echo "*** Testing imap_fetch_overview() : usage variations ***\n";
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+$stream_id = setup_test_mailbox('', 0, $mailbox); // setup temp mailbox
+create_multipart_message($stream_id, $mailbox);
+
+//Set mandatory response fields
+$mandatoryFields = array(
+ 'size',
+ 'uid',
+ 'msgno',
+ 'recent',
+ 'flagged',
+ 'answered',
+ 'deleted',
+ 'seen',
+ 'draft',
+ );
+
+// refresh msg numbers
+imap_check($stream_id);
+$msg_no = 1;
+
+$a = imap_fetch_overview($stream_id, $msg_no);
+echo "\n--> Object #1\n";
+foreach ($mandatoryFields as $mf)
+{
+ $z = $a[0]->$mf;
+ echo "$mf is $z\n";
+}
+
+
+
+
+/**
+ * Create a multipart message with subparts
+ *
+ * @param resource $imap_stream
+ * @param string $mailbox
+ */
+function create_multipart_message($imap_stream, $mailbox) {
+ global $users, $domain;
+ $envelope["from"]= "foo@anywhere.com";
+ $envelope["to"] = "$users[0]@$domain";
+ $envelope["subject"] = "Test msg 1";
+
+ $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";
+
+ $file_handle = fopen(__FILE__, 'r+');
+ $file_size = 1;
+
+ $part4["type"] = TYPEAPPLICATION;
+ $part4["encoding"] = ENCBASE64;
+ $part4["subtype"] = "octet-stream";
+ $part4["description"] = 'Test';
+ $part4['disposition.type'] = 'attachment';
+ $part4['disposition'] = array ('filename' => 'Test');
+ $part4['type.parameters'] = array('name' => 'Test');
+ $part4["contents.data"] = base64_encode(fread($file_handle, 1));
+
+ $body[1] = $part1;
+ $body[2] = $part2;
+ $body[3] = $part3;
+ $body[4] = $part4;
+
+ $msg = imap_mail_compose($envelope, $body);
+
+ if (imap_append($imap_stream, $mailbox, $msg) === false) {
+ echo imap_last_error() . "\n";
+ echo "TEST FAILED : could not append new message to mailbox '$mailbox'\n";
+ exit;
+ }
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_fetch_overview() : usage variations ***
+Create a temporary mailbox and add 0 msgs
+.. mailbox '{localhost/norsh}INBOX.phpttest' created
+
+--> Object #1
+size is %d
+uid is %d
+msgno is 1
+recent is %d
+flagged is 0
+answered is 0
+deleted is 0
+seen is 0
+draft is 0
+===DONE===
diff --git a/ext/imap/tests/imap_fetchbody_basic.phpt b/ext/imap/tests/imap_fetchbody_basic.phpt
new file mode 100644
index 000000000..7783ee131
--- /dev/null
+++ b/ext/imap/tests/imap_fetchbody_basic.phpt
@@ -0,0 +1,70 @@
+--TEST--
+Test imap_fetchbody() function : basic functionality
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : string imap_fetchbody(resource $stream_id, int $msg_no, string $section
+ * [, int $options])
+ * Description: Get a specific body section
+ * Source code: ext/imap/php_imap.c
+ */
+
+echo "*** Testing imap_fetchbody() : basic functionality ***\n";
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+// Initialise all required variables
+
+// set up mailbox with one message
+$stream_id = setup_test_mailbox('', 3, $mailbox, 'notSimple');
+$section = '2';
+
+// Calling imap_fetchbody() with all possible arguments
+echo "\n-- All possible arguments --\n";
+
+echo "Option == FD_UID\n";
+$msg_uid = imap_uid($stream_id, 1);
+var_dump( imap_fetchbody($stream_id, $msg_uid, $section, FT_UID) );
+
+echo "Option == FD_PEEK\n";
+var_dump( imap_fetchbody($stream_id, 2, $section, FT_PEEK) );
+$overview = imap_fetch_overview($stream_id, 2);
+echo "Seen Flag: ";
+var_dump( $overview[0]->seen );
+
+echo "option == FD_INTERNAL\n";
+var_dump( imap_fetchbody($stream_id, 3, $section, FT_INTERNAL) );
+
+// Calling imap_fetchbody() with mandatory arguments
+echo "\n-- Mandatory arguments --\n";
+var_dump( imap_fetchbody($stream_id, 1, $section) );
+$overview = imap_fetch_overview($stream_id, 1);
+echo "Seen Flag: ";
+var_dump( $overview[0]->seen );
+
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_fetchbody() : basic functionality ***
+Create a temporary mailbox and add 3 msgs
+.. mailbox '{localhost/norsh}INBOX.phpttest' created
+
+-- All possible arguments --
+Option == FD_UID
+string(36) "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy"
+Option == FD_PEEK
+string(36) "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy"
+Seen Flag: int(%d)
+option == FD_INTERNAL
+string(36) "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy"
+
+-- Mandatory arguments --
+string(36) "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy"
+Seen Flag: int(%d)
+===DONE=== \ No newline at end of file
diff --git a/ext/imap/tests/imap_fetchbody_error.phpt b/ext/imap/tests/imap_fetchbody_error.phpt
new file mode 100644
index 000000000..b6bf1eb8f
--- /dev/null
+++ b/ext/imap/tests/imap_fetchbody_error.phpt
@@ -0,0 +1,57 @@
+--TEST--
+Test imap_fetchbody() function : error conditions - incorrect number of args
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype :string imap_fetchbody(resource $stream_id, int $msg_no, string $section
+ * [, int $options])
+ * Description: Get a specific body section
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass an incorrect number of arguments to imap_fetchbody() to test behaviour
+ */
+
+echo "*** Testing imap_fetchbody() : error conditions ***\n";
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+//Test imap_fetchbody with one more than the expected number of arguments
+echo "\n-- Testing imap_fetchbody() function with more than expected no. of arguments --\n";
+
+$stream_id = setup_test_mailbox('', 1); // set up temp mailbox with 1 simple msg
+$msg_no = 1;
+$section = '1';
+$options = FT_PEEK;
+$extra_arg = 10;
+
+var_dump( imap_fetchbody($stream_id, $msg_no, $section, $options, $extra_arg) );
+
+// Testing imap_fetchbody with one less than the expected number of arguments
+echo "\n-- Testing imap_fetchbody() function with less than expected no. of arguments --\n";
+
+var_dump( imap_fetchbody($stream_id, $msg_no) );
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_fetchbody() : error conditions ***
+
+-- Testing imap_fetchbody() function with more than expected no. of arguments --
+Create a temporary mailbox and add 1 msgs
+.. mailbox '%s.phpttest' created
+
+Warning: Wrong parameter count for imap_fetchbody() in %s on line %d
+NULL
+
+-- Testing imap_fetchbody() function with less than expected no. of arguments --
+
+Warning: Wrong parameter count for imap_fetchbody() in %s on line %d
+NULL
+===DONE===
diff --git a/ext/imap/tests/imap_fetchbody_variation1.phpt b/ext/imap/tests/imap_fetchbody_variation1.phpt
new file mode 100644
index 000000000..3248ff2f1
--- /dev/null
+++ b/ext/imap/tests/imap_fetchbody_variation1.phpt
@@ -0,0 +1,219 @@
+--TEST--
+Test imap_fetchbody() function : usage variation - diff data types as $stream_id arg
+--SKIPIF--
+<?php
+extension_loaded('imap') or die('skip imap extension not available in this build');
+?>
+--FILE--
+<?php
+/* Prototype : string imap_fetchbody(resource $stream_id, int $msg_no, string $section
+ * [, int $options])
+ * Description: Get a specific body section
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different data types as $stream_id argument to test behaviour of imap_fetchbody()
+ */
+
+echo "*** Testing imap_fetchbody() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$msg_no = 1;
+$section = '2';
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a class
+class classA
+{
+ public function __toString() {
+ return "Class A object";
+ }
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// unexpected values to be passed to $stream_id argument
+$inputs = array(
+
+ // int data
+/*1*/ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+/*5*/ 10.5,
+ -10.5,
+ 12.3456789000e10,
+ 12.3456789000E-10,
+ .5,
+
+ // null data
+/*10*/ NULL,
+ null,
+
+ // boolean data
+/*12*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+/*16*/ "",
+ '',
+ array(),
+
+ // string data
+/*19*/ "string",
+ 'string',
+ $heredoc,
+
+ // object data
+/*22*/ new classA(),
+
+ // undefined data
+/*23*/ @$undefined_var,
+
+ // unset data
+/*24*/ @$unset_var,
+);
+
+// loop through each element of $inputs to check the behavior of imap_fetchbody()
+$iterator = 1;
+foreach($inputs as $input) {
+ echo "\n-- Iteration $iterator --\n";
+ var_dump( imap_fetchbody($input, $msg_no, $section) );
+ $iterator++;
+}
+?>
+===DONE===
+--EXPECTF--
+*** Testing imap_fetchbody() : usage variations ***
+
+-- Iteration 1 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 2 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 3 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 4 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 5 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 6 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 7 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 8 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 9 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 10 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 11 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 12 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 13 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 14 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 15 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 16 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 17 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 18 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 19 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 20 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 21 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 22 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 23 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 24 --
+
+Warning: imap_fetchbody(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/imap/tests/imap_fetchbody_variation2.phpt b/ext/imap/tests/imap_fetchbody_variation2.phpt
new file mode 100644
index 000000000..8c5e60f38
--- /dev/null
+++ b/ext/imap/tests/imap_fetchbody_variation2.phpt
@@ -0,0 +1,221 @@
+--TEST--
+Test imap_fetchbody() function : usage variation - diff data types as $msg_no arg
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : string imap_fetchbody(resource $stream_id, int $msg_no, string $section
+ * [, int $options])
+ * Description: Get a specific body section
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different data types as $msg_no argument to test behaviour of imap_fetchbody()
+ */
+
+echo "*** Testing imap_fetchbody() : usage variations ***\n";
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+// Initialise function arguments not being substituted
+$stream_id = setup_test_mailbox('', 1); // set up temp mailbox with 1 simple msg
+$section = '1';
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a class
+class classA
+{
+ public function __toString() {
+ return "Class A object";
+ }
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// unexpected values to be passed to $msg_no argument
+$inputs = array(
+
+ // int data
+/*1*/ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+/*5*/ 10.5,
+ -10.5,
+ 12.3456789000e10,
+ 12.3456789000E-10,
+ .5,
+
+ // null data
+/*10*/ NULL,
+ null,
+
+ // boolean data
+/*12*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+/*16*/ "",
+ '',
+ array(),
+
+ // string data
+/*19*/ "string",
+ 'string',
+ $heredoc,
+
+ // object data
+/*22*/ new classA(),
+
+ // undefined data
+/*23*/ @$undefined_var,
+
+ // unset data
+/*24*/ @$unset_var,
+);
+
+// loop through each element of $inputs to check the behavior of imap_fetchbody()
+$iterator = 1;
+foreach($inputs as $input) {
+ echo "\n-- Iteration $iterator --\n";
+ var_dump( imap_fetchbody($stream_id, $input, $section) );
+ $iterator++;
+};
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_fetchbody() : usage variations ***
+Create a temporary mailbox and add 1 msgs
+.. mailbox '{localhost/norsh}INBOX.phpttest' created
+
+-- Iteration 1 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 2 --
+string(%d) "1: this is a test message, please ignore%a"
+
+-- Iteration 3 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 4 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 5 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 6 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 7 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 8 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 9 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 10 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 11 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 12 --
+string(%d) "1: this is a test message, please ignore%a"
+
+-- Iteration 13 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 14 --
+string(%d) "1: this is a test message, please ignore%a"
+
+-- Iteration 15 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 16 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 17 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 18 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 19 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 20 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 21 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 22 --
+
+Notice: Object of class classA could not be converted to int in %s on line %d
+string(%d) "1: this is a test message, please ignore%a"
+
+-- Iteration 23 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 24 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/imap/tests/imap_fetchbody_variation3.phpt b/ext/imap/tests/imap_fetchbody_variation3.phpt
new file mode 100644
index 000000000..2a017b533
--- /dev/null
+++ b/ext/imap/tests/imap_fetchbody_variation3.phpt
@@ -0,0 +1,217 @@
+--TEST--
+Test imap_fetchbody() function : usage variation - diff data types as $section arg
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : string imap_fetchbody(resource $stream_id, int $msg_no, string $section
+ * [, int $options])
+ * Description: Get a specific body section
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different data types as $section argument to test behaviour of imap_fetchbody()
+ */
+
+echo "*** Testing imap_fetchbody() : usage variations ***\n";
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+// Initialise function arguments not being substituted
+$stream_id = setup_test_mailbox('', 1); // set up temp mailbox with 1 simple msg
+$msg_no = 1;
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a class
+class classA
+{
+ public function __toString() {
+ return "Class A object";
+ }
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// unexpected values to be passed to $section argument
+$inputs = array(
+
+ // int data
+/*1*/ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+/*5*/ 10.5,
+ -10.5,
+ 12.3456789000e10,
+ 12.3456789000E-10,
+ .5,
+
+ // null data
+/*10*/ NULL,
+ null,
+
+ // boolean data
+/*12*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+/*16*/ "",
+ '',
+ array(),
+
+ // string data
+/*19*/ "string",
+ 'string',
+ $heredoc,
+
+ // object data
+/*22*/ new classA(),
+
+ // undefined data
+/*23*/ @$undefined_var,
+
+ // unset data
+/*24*/ @$unset_var,
+);
+
+// loop through each element of $inputs to check the behavior of imap_fetchbody()
+$iterator = 1;
+foreach($inputs as $input) {
+ echo "\n-- Iteration $iterator --\n";
+ var_dump( imap_fetchbody($stream_id, $msg_no, $input) );
+ $iterator++;
+};
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_fetchbody() : usage variations ***
+Create a temporary mailbox and add 1 msgs
+.. mailbox '%s.phpttest' created
+
+-- Iteration 1 --
+string(71) "From: %s
+To: %s
+Subject: test1
+
+"
+
+-- Iteration 2 --
+string(%d) "1: this is a test message, please ignore%a"
+
+-- Iteration 3 --
+string(0) ""
+
+-- Iteration 4 --
+string(0) ""
+
+-- Iteration 5 --
+string(0) ""
+
+-- Iteration 6 --
+string(0) ""
+
+-- Iteration 7 --
+string(0) ""
+
+-- Iteration 8 --
+string(0) ""
+
+-- Iteration 9 --
+string(0) ""
+
+-- Iteration 10 --
+string(%d) "From: %s
+To: %s
+Subject: test1
+
+1: this is a test message, please ignore%a"
+
+-- Iteration 11 --
+string(%d) "From: %s
+To: %s
+Subject: test1
+
+1: this is a test message, please ignore%a"
+
+-- Iteration 12 --
+string(%d) "1: this is a test message, please ignore%a"
+
+-- Iteration 13 --
+string(%d) "From: %s
+To: %s
+Subject: test1
+
+1: this is a test message, please ignore%a"
+
+-- Iteration 14 --
+string(%d) "1: this is a test message, please ignore%a"
+
+-- Iteration 15 --
+string(%d) "From: %s
+To: %s
+Subject: test1
+
+1: this is a test message, please ignore%a"
+
+-- Iteration 16 --
+string(%d) "From: %s
+To: %s
+Subject: test1
+
+1: this is a test message, please ignore%a"
+
+-- Iteration 17 --
+string(%d) "From: %s
+To: %s
+Subject: test1
+
+1: this is a test message, please ignore%a"
+
+-- Iteration 18 --
+
+Notice: Array to string conversion in %s on line %d
+string(0) ""
+
+-- Iteration 19 --
+string(0) ""
+
+-- Iteration 20 --
+string(0) ""
+
+-- Iteration 21 --
+string(0) ""
+
+-- Iteration 22 --
+string(0) ""
+
+-- Iteration 23 --
+string(%d) "From: %s
+To: %s
+Subject: test1
+
+1: this is a test message, please ignore%a"
+
+-- Iteration 24 --
+string(%d) "From: %s
+To: %s
+Subject: test1
+
+1: this is a test message, please ignore%a"
+===DONE===
diff --git a/ext/imap/tests/imap_fetchbody_variation4.phpt b/ext/imap/tests/imap_fetchbody_variation4.phpt
new file mode 100644
index 000000000..6b9579abd
--- /dev/null
+++ b/ext/imap/tests/imap_fetchbody_variation4.phpt
@@ -0,0 +1,79 @@
+--TEST--
+Test imap_fetchbody() function : usage variations - FT_UID option
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : string imap_fetchbody(resource $stream_id, int $msg_no, string $section [, int $options])
+ * Description: Get a specific body section
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Test if FT_UID is set by passing the following as $options argument to imap_fetchbody():
+ * 1. values that equate to 1
+ * 2. Minimum and maximum PHP values
+ */
+echo "*** Testing imap_fetchbody() : usage variations ***\n";
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+// Initialise required variables
+$stream_id = setup_test_mailbox('', 1); // set up temporary mailbox with one simple message
+$msg_no = 1;
+$msg_uid = imap_uid($stream_id, $msg_no);
+$section = 1;
+
+//Note: the first four values are valid as they will all be cast to 1L.
+$options = array ('1', true,
+ 1.000000000000001, 0.00001e5,
+ PHP_INT_MAX, -PHP_INT_MAX);
+
+// iterate over each element of $options array to test whether FT_UID is set
+$iterator = 1;
+imap_check($stream_id);
+foreach($options as $option) {
+ echo "\n-- Iteration $iterator --\n";
+ if(is_string(imap_fetchbody($stream_id, $msg_uid, $section, $option))) {
+ echo "FT_UID valid\n";
+ } else {
+ echo "FT_UID not valid\n";
+ }
+ $iterator++;
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_fetchbody() : usage variations ***
+Create a temporary mailbox and add 1 msgs
+.. mailbox '{localhost/norsh}INBOX.phpttest' created
+
+-- Iteration 1 --
+FT_UID valid
+
+-- Iteration 2 --
+FT_UID valid
+
+-- Iteration 3 --
+FT_UID valid
+
+-- Iteration 4 --
+FT_UID valid
+
+-- Iteration 5 --
+
+Warning: imap_fetchbody(): invalid value for the options parameter in %s on line %d
+FT_UID not valid
+
+-- Iteration 6 --
+
+Warning: imap_fetchbody(): invalid value for the options parameter in %s on line %d
+FT_UID not valid
+===DONE===
diff --git a/ext/imap/tests/imap_fetchbody_variation5.phpt b/ext/imap/tests/imap_fetchbody_variation5.phpt
new file mode 100644
index 000000000..f01bfb405
--- /dev/null
+++ b/ext/imap/tests/imap_fetchbody_variation5.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Test imap_fetchbody() function : usage variation - different resources as $stream_id arg
+--SKIPIF--
+<?php
+extension_loaded('imap') or die('skip imap extension not available in this build');
+?>
+--FILE--
+<?php
+/* Prototype : string imap_fetchbody(resource $stream_id, int $msg_no, string $section
+ * [, int options])
+ * Description: Get a specific body section
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different resource types to imap_fetchbody() to test behaviour
+ */
+
+echo "*** Testing imap_fetchbody() : usage variations ***\n";
+
+echo "\n-- File Resource opened with fopen() --\n";
+var_dump($file_pointer = fopen(__FILE__, 'r+'));
+var_dump(imap_fetchbody($file_pointer, 1));
+fclose($file_pointer);
+
+echo "\n-- Directory Resource opened with opendir() --\n";
+var_dump($dir_handle = opendir(dirname(__FILE__)));
+var_dump(imap_fetchbody($dir_handle, 1));
+closedir($dir_handle);
+?>
+===DONE===
+--EXPECTF--
+*** Testing imap_fetchbody() : usage variations ***
+
+-- File Resource opened with fopen() --
+resource(%d) of type (stream)
+
+Warning: Wrong parameter count for imap_fetchbody() in %s on line %d
+NULL
+
+-- Directory Resource opened with opendir() --
+resource(%d) of type (stream)
+
+Warning: Wrong parameter count for imap_fetchbody() in %s on line %d
+NULL
+===DONE===
diff --git a/ext/imap/tests/imap_fetchbody_variation6.phpt b/ext/imap/tests/imap_fetchbody_variation6.phpt
new file mode 100644
index 000000000..8f6f78095
--- /dev/null
+++ b/ext/imap/tests/imap_fetchbody_variation6.phpt
@@ -0,0 +1,66 @@
+--TEST--
+Test imap_fetchbody() function : usage variations - $msg_no arg
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : string imap_fetchbody(resource $stream_id, int $msg_no, string $section [, int $options])
+ * Description: Get a specific body section
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different integers, strings, msg sequences and msg UIDs as $msg_no argument
+ * to test behaviour of imap_fetchbody()
+ */
+
+echo "*** Testing imap_fetchbody() : usage variations ***\n";
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+//Initialise required variables
+$stream_id = setup_test_mailbox('', 3); // set up temp mailbox with simple msgs
+$section = 1;
+
+$sequences = array (0, 4, // out of range
+ '1,3', '1:3', // message sequences instead of numbers
+ ); //
+
+foreach($sequences as $msg_no) {
+ echo "\n-- \$msg_no is $msg_no --\n";
+ var_dump($overview = imap_fetchbody($stream_id, $msg_no, $section));
+ if (!$overview) {
+ echo imap_last_error() . "\n";
+ }
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_fetchbody() : usage variations ***
+Create a temporary mailbox and add 3 msgs
+.. mailbox '%s.phpttest' created
+
+-- $msg_no is 0 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+
+-- $msg_no is 4 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+
+-- $msg_no is 1,3 --
+string(%d) "1: this is a test message, please ignore%a"
+
+-- $msg_no is 1:3 --
+string(%d) "1: this is a test message, please ignore%a"
+===DONE===
diff --git a/ext/imap/tests/imap_fetchheader_basic.phpt b/ext/imap/tests/imap_fetchheader_basic.phpt
new file mode 100644
index 000000000..2e47b0ce5
--- /dev/null
+++ b/ext/imap/tests/imap_fetchheader_basic.phpt
@@ -0,0 +1,83 @@
+--TEST--
+Test imap_fetchheader() function : basic functions
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : string imap_fetchheader(resource $stream_id, int $msg_no [, int $options])
+ * Description: Get the full unfiltered header for a message
+ * Source code: ext/imap/php_imap.c
+ */
+
+echo "*** Testing imap_fetchheader() : basic functionality ***\n";
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+// Initialise all required variables
+$stream_id = setup_test_mailbox('', 1, $mailbox, 'multiPart'); // setup temp mailbox with 1 msg
+$msg_no = 1;
+$options = array('FT_UID' => FT_UID, 'FT_INTERNAL' => FT_INTERNAL,
+ 'FT_PREFETCHTEXT' => FT_PREFETCHTEXT);
+
+// Calling imap_fetchheader() with all possible arguments
+echo "\n-- All possible arguments --\n";
+foreach ($options as $key => $option) {
+ echo "-- Option is $key --\n";
+ if ($key == 'FT_UID') {
+ $msg_uid = imap_uid($stream_id, $msg_no);
+ var_dump(imap_fetchheader($stream_id, $msg_uid, $option));
+ } else {
+ var_dump(imap_fetchheader($stream_id, $msg_no, $option));
+ }
+}
+
+// Calling imap_fetchheader() with mandatory arguments
+echo "\n-- Mandatory arguments --\n";
+var_dump( imap_fetchheader($stream_id, $msg_no) );
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_fetchheader() : basic functionality ***
+Create a temporary mailbox and add 1 msgs
+.. mailbox '%s.phpttest' created
+
+-- All possible arguments --
+-- Option is FT_UID --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: %s; %s
+
+"
+-- Option is FT_INTERNAL --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: %s; %s
+
+"
+-- Option is FT_PREFETCHTEXT --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: %s; %s
+
+"
+
+-- Mandatory arguments --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: %s; %s
+
+"
+===DONE===
diff --git a/ext/imap/tests/imap_fetchheader_error.phpt b/ext/imap/tests/imap_fetchheader_error.phpt
new file mode 100644
index 000000000..7d1e84ef1
--- /dev/null
+++ b/ext/imap/tests/imap_fetchheader_error.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Test imap_fetchheader() function : error conditions - incorrect number of args
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : string imap_fetchheader(resource $stream_id, int $msg_no [, int $options])
+ * Description: Get the full unfiltered header for a message
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass an incorrect number of arguments to imap_fetchheader() to test behaviour
+ */
+
+echo "*** Testing imap_fetchheader() : error conditions ***\n";
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+//Test imap_fetchheader with one more than the expected number of arguments
+echo "\n-- Testing imap_fetchheader() function with more than expected no. of arguments --\n";
+
+$stream_id = imap_open($server, $username, $password);
+$msg_no = 10;
+$options = 10;
+$extra_arg = 10;
+var_dump( imap_fetchheader($stream_id, $msg_no, $options, $extra_arg) );
+
+// Testing imap_fetchheader with one less than the expected number of arguments
+echo "\n-- Testing imap_fetchheader() function with less than expected no. of arguments --\n";
+var_dump( imap_fetchheader($stream_id) );
+
+imap_close($stream_id);
+?>
+===DONE===
+--EXPECTF--
+*** Testing imap_fetchheader() : error conditions ***
+
+-- Testing imap_fetchheader() function with more than expected no. of arguments --
+
+Warning: Wrong parameter count for imap_fetchheader() in %s on line %d
+NULL
+
+-- Testing imap_fetchheader() function with less than expected no. of arguments --
+
+Warning: Wrong parameter count for imap_fetchheader() in %s on line %d
+NULL
+===DONE===
diff --git a/ext/imap/tests/imap_fetchheader_variation1.phpt b/ext/imap/tests/imap_fetchheader_variation1.phpt
new file mode 100644
index 000000000..f43e07d80
--- /dev/null
+++ b/ext/imap/tests/imap_fetchheader_variation1.phpt
@@ -0,0 +1,245 @@
+--TEST--
+Test imap_fetchheader() function : usage variations - diff data types as $stream_id arg
+--SKIPIF--
+<?php
+extension_loaded('imap') or die('skip imap extension not available in this build');
+?>
+--FILE--
+<?php
+/* Prototype : string imap_fetchheader(resource $stream_id, int $msg_no [, int $options])
+ * Description: Get the full unfiltered header for a message
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different data types as $stream_id argument to test behaviour of imap_fetchheader()
+ */
+
+echo "*** Testing imap_fetchheader() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$msg_no = 1;
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a class
+class classA
+{
+ public function __toString() {
+ return "Class A object";
+ }
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// get different types of array
+$index_array = array (1, 2, 3);
+$assoc_array = array ('one' => 1, 'two' => 2);
+
+// get a resource variable
+$fp = fopen(__FILE__, "r");
+
+// unexpected values to be passed to $stream_id argument
+$inputs = array(
+
+ // int data
+/*1*/ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+/*5*/ 10.5,
+ -10.5,
+ 12.3456789000e10,
+ 12.3456789000E-10,
+ .5,
+
+ // null data
+/*10*/ NULL,
+ null,
+
+ // boolean data
+/*12*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+/*16*/ "",
+ '',
+
+ // string data
+/*18*/ "string",
+ 'string',
+ $heredoc,
+
+ // array data
+/*21*/ array(),
+ $index_array,
+ $assoc_array,
+ array('foo', $index_array, $assoc_array),
+
+
+ // object data
+/*25*/ new classA(),
+
+ // undefined data
+/*26*/ @$undefined_var,
+
+ // unset data
+/*27*/ @$unset_var,
+);
+
+// loop through each element of $inputs to check the behavior of imap_fetchheader()
+$iterator = 1;
+foreach($inputs as $input) {
+ echo "\n-- Iteration $iterator --\n";
+ var_dump( imap_fetchheader($input, $msg_no) );
+ $iterator++;
+};
+?>
+===DONE===
+--EXPECTF--
+*** Testing imap_fetchheader() : usage variations ***
+
+-- Iteration 1 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 2 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 3 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 4 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 5 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 6 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 7 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 8 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 9 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 10 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 11 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 12 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 13 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 14 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 15 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 16 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 17 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 18 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 19 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 20 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 21 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 22 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 23 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 24 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 25 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 26 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 27 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/imap/tests/imap_fetchheader_variation2.phpt b/ext/imap/tests/imap_fetchheader_variation2.phpt
new file mode 100644
index 000000000..65d5d8557
--- /dev/null
+++ b/ext/imap/tests/imap_fetchheader_variation2.phpt
@@ -0,0 +1,292 @@
+--TEST--
+Test imap_fetchheader() function : usage variations - diff data types for $msg_no arg
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : string imap_fetchheader(resource $stream_id, int $msg_no [, int $options])
+ * Description: Get the full unfiltered header for a message
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different data types as $msg_no argument to test behaviour of imap_fetchheader()
+ */
+
+echo "*** Testing imap_fetchheader() : usage variations ***\n";
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+// Initialise function arguments not being substituted
+$stream_id = setup_test_mailbox('', 1, $mailbox, 'notSimple'); // set up temp mailbox with 1 msg
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a class
+class classA
+{
+ public function __toString() {
+ return "Class A object";
+ }
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+$index_array = array (1, 2, 3);
+$assoc_array = array ('one' => 1, 'two' => 2);
+
+// get a resource variable
+$fp = fopen(__FILE__, "r");
+
+// unexpected values to be passed to $msg_no argument
+$inputs = array(
+
+ // int data
+/*1*/ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+/*5*/ 10.5,
+ -10.5,
+ 12.3456789000e10,
+ 12.3456789000E-10,
+ .5,
+
+ // null data
+/*10*/ NULL,
+ null,
+
+ // boolean data
+/*12*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+/*16*/ "",
+ '',
+
+ // string data
+/*18*/ "string",
+ 'string',
+ $heredoc,
+
+ // array data
+/*21*/ array(),
+ $index_array,
+ $assoc_array,
+ array('foo', $index_array, $assoc_array),
+
+
+ // object data
+/*25*/ new classA(),
+
+ // undefined data
+/*26*/ @$undefined_var,
+
+ // unset data
+/*27*/ @$unset_var,
+
+ // resource variable
+/*28*/ $fp
+);
+
+// loop through each element of $inputs to check the behavior of imap_fetchheader()
+$iterator = 1;
+foreach($inputs as $input) {
+ echo "\n-- Iteration $iterator --\n";
+ var_dump( imap_fetchheader($stream_id, $input) );
+ $iterator++;
+};
+
+fclose($fp);
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+===DONE===
+--EXPECTF--
+*** Testing imap_fetchheader() : usage variations ***
+Create a temporary mailbox and add 1 msgs
+.. mailbox '{localhost/norsh}INBOX.phpttest' created
+
+-- Iteration 1 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 2 --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+"
+
+-- Iteration 3 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 4 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 5 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 6 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 7 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 8 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 9 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 10 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 11 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 12 --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+"
+
+-- Iteration 13 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 14 --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+"
+
+-- Iteration 15 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 16 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 17 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 18 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 19 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 20 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 21 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 22 --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+"
+
+-- Iteration 23 --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+"
+
+-- Iteration 24 --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+"
+
+-- Iteration 25 --
+
+Notice: Object of class classA could not be converted to int in %s on line %d
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+"
+
+-- Iteration 26 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 27 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 28 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/imap/tests/imap_fetchheader_variation3.phpt b/ext/imap/tests/imap_fetchheader_variation3.phpt
new file mode 100644
index 000000000..e21c1a966
--- /dev/null
+++ b/ext/imap/tests/imap_fetchheader_variation3.phpt
@@ -0,0 +1,77 @@
+--TEST--
+Test imap_fetchheader() function : usage variations - FT_UID option
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : string imap_fetchheader(resource $stream_id, int $msg_no [, int $options])
+ * Description: Get the full unfiltered header for a message
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Test if FT_UID is set by passing the following as $options argument to imap_fetchheader():
+ * 1. values that equate to 1
+ * 2. Minimum and maximum PHP values
+ */
+
+echo "*** Testing imap_fetchheader() : usage variations ***\n";
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+// Initialise required variables
+$stream_id = setup_test_mailbox('', 1); // set up temporary mailbox with one simple message
+$msg_no = 1;
+$msg_uid = imap_uid($stream_id, $msg_no);
+
+$options = array ('1', true,
+ 1.000000000000001, 0.00001e5,
+ PHP_INT_MAX, -PHP_INT_MAX);
+
+// iterate over each element of $options array to test whether FT_UID is set
+$iterator = 1;
+imap_check($stream_id);
+foreach($options as $option) {
+ echo "\n-- Iteration $iterator --\n";
+ if(is_string(imap_fetchheader($stream_id, $msg_uid, $option))) {
+ echo "FT_UID valid\n";
+ } else {
+ echo "FT_UID not valid\n";
+ }
+ $iterator++;
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_fetchheader() : usage variations ***
+Create a temporary mailbox and add 1 msgs
+.. mailbox '{localhost/norsh}INBOX.phpttest' created
+
+-- Iteration 1 --
+FT_UID valid
+
+-- Iteration 2 --
+FT_UID valid
+
+-- Iteration 3 --
+FT_UID valid
+
+-- Iteration 4 --
+FT_UID valid
+
+-- Iteration 5 --
+
+Warning: imap_fetchheader(): invalid value for the options parameter in %s on line %d
+FT_UID not valid
+
+-- Iteration 6 --
+
+Warning: imap_fetchheader(): invalid value for the options parameter in %s on line %d
+FT_UID not valid
+===DONE===
diff --git a/ext/imap/tests/imap_fetchheader_variation4.phpt b/ext/imap/tests/imap_fetchheader_variation4.phpt
new file mode 100644
index 000000000..090fa217c
--- /dev/null
+++ b/ext/imap/tests/imap_fetchheader_variation4.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Test imap_fetchheader() function : usage variations - diff resource types as $stream_id
+--SKIPIF--
+<?php
+extension_loaded('imap') or die('skip imap extension not available in this build');
+?>
+--FILE--
+<?php
+/* Prototype : string imap_fetchheader(resource $stream_id, int $msg_no [, int $options])
+ * Description: Get the full unfiltered header for a message
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different types of resources to imap_fetchheader() to test behaviour
+ */
+
+echo "*** Testing imap_fetchheader() : usage variations ***\n";
+
+echo "\n-- File Resource opened with fopen() --\n";
+var_dump($file_pointer = fopen(__FILE__, 'r+'));
+var_dump(imap_fetchheader($file_pointer, 1));
+fclose($file_pointer);
+
+echo "\n-- Directory Resource opened with opendir() --\n";
+var_dump($dir_handle = opendir(dirname(__FILE__)));
+var_dump(imap_fetchheader($dir_handle, 1));
+closedir($dir_handle);
+?>
+===DONE===
+--EXPECTF--
+*** Testing imap_fetchheader() : usage variations ***
+
+-- File Resource opened with fopen() --
+resource(%d) of type (stream)
+
+Warning: imap_fetchheader(): supplied resource is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Directory Resource opened with opendir() --
+resource(%d) of type (stream)
+
+Warning: imap_fetchheader(): supplied resource is not a valid imap resource in %s on line %d
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/imap/tests/imap_fetchheader_variation5.phpt b/ext/imap/tests/imap_fetchheader_variation5.phpt
new file mode 100644
index 000000000..f0f5fd597
--- /dev/null
+++ b/ext/imap/tests/imap_fetchheader_variation5.phpt
@@ -0,0 +1,79 @@
+--TEST--
+Test imap_fetchheader() function : usage variations - $msg_no argument
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : string imap_fetchheader(resource $stream_id, int $msg_no [, int $options])
+ * Description: Get the full unfiltered header for a message
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different integers and strings as $msg_no argument
+ * to test behaviour of imap_fetchheader()
+ */
+
+echo "*** Testing imap_fetchheader() : usage variations ***\n";
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+$stream_id = setup_test_mailbox('', 3, $mailbox, 'notSimple'); // set up temp mailbox with 3 msgs
+
+$sequences = array (0, 4, // out of range
+ '1,3', '1:3', // message sequences instead of numbers
+ );
+
+foreach($sequences as $msg_no) {
+ echo "\n-- \$msg_no is $msg_no --\n";
+ var_dump($overview = imap_fetchheader($stream_id, $msg_no));
+ if (!$overview) {
+ echo imap_last_error() . "\n";
+ }
+}
+
+// clear error stack
+imap_errors();
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_fetchheader() : usage variations ***
+Create a temporary mailbox and add 3 msgs
+.. mailbox '{localhost/norsh}INBOX.phpttest' created
+
+-- $msg_no is 0 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+
+-- $msg_no is 4 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+
+-- $msg_no is 1,3 --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+"
+
+-- $msg_no is 1:3 --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+"
+===DONE===
diff --git a/ext/imap/tests/imap_include.inc b/ext/imap/tests/imap_include.inc
new file mode 100644
index 000000000..3f9845476
--- /dev/null
+++ b/ext/imap/tests/imap_include.inc
@@ -0,0 +1,150 @@
+<?php
+// Change these to make tests run successfully
+$server = '{localhost/norsh}';
+$default_mailbox = $server . "INBOX";
+$domain = "something.com";
+$admin_user = "webmaster"; // a user with admin access
+$username = "$admin_user@$domain";
+$password = 'p4ssw0rd';
+$users = array("webmaster", "info", "admin", "foo"); // tests require 4 valid userids
+$mailbox_prefix = "phpttest"; // name used for test mailbox
+
+/**
+ * Create a test mailbox and populate with msgs
+ *
+ * @para, 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 sucesss; 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 "Cant 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 "cant 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 decription, 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/skipif.inc b/ext/imap/tests/skipif.inc
new file mode 100644
index 000000000..df69c4382
--- /dev/null
+++ b/ext/imap/tests/skipif.inc
@@ -0,0 +1,16 @@
+<?php
+extension_loaded('imap') or die('skip imap extension not available in this build');
+
+// Change these to make tests run successfully
+$mailbox = '{localhost/norsh}';
+$username = 'webmaster@something.com';
+$password = 'p4ssw0rd';
+$options = OP_HALFOPEN; // this should be enough to verify server present
+$retries = 0; // dont retry connect on failure
+
+$mbox = @imap_open($mailbox, $username, $password, $options, $retries);
+if (!$mbox) {
+ die("skip could not connect to mailbox $mailbox");
+}
+imap_close($mbox);
+?>