--- /dev/null
+--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===
--- /dev/null
+--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: imap_alerts() expects exactly 0 parameters, 1 given in %s on line %d
+NULL
+===DONE===
--- /dev/null
+--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===
+
--- /dev/null
+--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===
--- /dev/null
+--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===
--- /dev/null
+--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
--- /dev/null
+--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===
--- /dev/null
+--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===
--- /dev/null
+--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===
--- /dev/null
+--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: imap_close() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+
+-- Testing imap_close() function with more than expected no. of arguments --
+
+Warning: imap_close() expects at most 2 parameters, 3 given in %s on line %d
+NULL
+===DONE===
--- /dev/null
+--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() expects parameter 1 to be resource, integer given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 2 --
+
+Warning: imap_close() expects parameter 1 to be resource, integer given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 3 --
+
+Warning: imap_close() expects parameter 1 to be resource, integer given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 4 --
+
+Warning: imap_close() expects parameter 1 to be resource, integer given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 5 --
+
+Warning: imap_close() expects parameter 1 to be resource, double given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 6 --
+
+Warning: imap_close() expects parameter 1 to be resource, double given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 7 --
+
+Warning: imap_close() expects parameter 1 to be resource, double given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 8 --
+
+Warning: imap_close() expects parameter 1 to be resource, double given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 9 --
+
+Warning: imap_close() expects parameter 1 to be resource, double given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 10 --
+
+Warning: imap_close() expects parameter 1 to be resource, null given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 11 --
+
+Warning: imap_close() expects parameter 1 to be resource, null given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 12 --
+
+Warning: imap_close() expects parameter 1 to be resource, boolean given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 13 --
+
+Warning: imap_close() expects parameter 1 to be resource, boolean given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 14 --
+
+Warning: imap_close() expects parameter 1 to be resource, boolean given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 15 --
+
+Warning: imap_close() expects parameter 1 to be resource, boolean given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 16 --
+
+Warning: imap_close() expects parameter 1 to be resource, %unicode_string_optional% given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 17 --
+
+Warning: imap_close() expects parameter 1 to be resource, %unicode_string_optional% given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 18 --
+
+Warning: imap_close() expects parameter 1 to be resource, array given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 19 --
+
+Warning: imap_close() expects parameter 1 to be resource, %unicode_string_optional% given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 20 --
+
+Warning: imap_close() expects parameter 1 to be resource, %unicode_string_optional% given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 21 --
+
+Warning: imap_close() expects parameter 1 to be resource, %unicode_string_optional% given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 22 --
+
+Warning: imap_close() expects parameter 1 to be resource, object given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 23 --
+
+Warning: imap_close() expects parameter 1 to be resource, null given in %simap_close_variation1.php on line 80
+NULL
+
+-- Iteration 24 --
+
+Warning: imap_close() expects parameter 1 to be resource, null given in %simap_close_variation1.php on line 80
+NULL
+===DONE===
--- /dev/null
+--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 --
+
+Warning: imap_close() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d
+NULL
+CL_EXPUNGE was not set, 3 msgs in mailbox
+
+-- Iteration 17 --
+
+Warning: imap_close() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d
+NULL
+CL_EXPUNGE was not set, 3 msgs in mailbox
+
+-- Iteration 18 --
+
+Warning: imap_close() expects parameter 2 to be long, array given in %s on line %d
+NULL
+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===
--- /dev/null
+--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===
--- /dev/null
+--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===
--- /dev/null
+--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===
--- /dev/null
+--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===
--- /dev/null
+--TEST--
+Test imap_fetchbody() function : basic functionality
+--XFAIL--
+Expected to fail - missing unicode implementation
+--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('', 1, $mailbox, 'notSimple');
+
+$msg_no = 1;
+$section = '2';
+$options = array ('FT_UID' => FT_UID, 'FT_PEEK' => FT_PEEK, 'FT_INTERNAL' => FT_INTERNAL);
+
+// Calling imap_fetchbody() with all possible arguments
+echo "\n-- All possible arguments --\n";
+foreach ($options as $key => $option) {
+ echo "-- Option is $key --\n";
+ switch ($key) {
+
+ case 'FT_UID';
+ $msg_uid = imap_uid($stream_id, $msg_no);
+ var_dump( imap_fetchbody($stream_id, $msg_uid, $section, $option) );
+ break;
+
+ case 'FT_PEEK';
+ var_dump( imap_fetchbody($stream_id, $msg_no, $section, $option) );
+ $overview = imap_fetch_overview($stream_id, 1);
+ echo "Seen Flag: ";
+ var_dump( $overview[0]->seen );
+ break;
+
+ case 'FT_INTERNAL';
+ var_dump( imap_fetchbody($stream_id, $msg_no, $section, $option) );
+ break;
+
+ }
+}
+
+// Calling imap_fetchbody() with mandatory arguments
+echo "\n-- Mandatory arguments --\n";
+var_dump( imap_fetchbody($stream_id, $msg_no, $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 1 msgs
+.. mailbox '{localhost/norsh}INBOX.phpttest' created
+
+-- All possible arguments --
+-- Option is FT_UID --
+%unicode|string%(36) "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy"
+-- Option is FT_PEEK --
+%unicode|string%(36) "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy"
+Seen Flag: int(%d)
+-- Option is FT_INTERNAL --
+%unicode|string%(36) "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy"
+
+-- Mandatory arguments --
+%unicode|string%(36) "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy"
+Seen Flag: int(%d)
+===DONE===
--- /dev/null
+--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 '{localhost/norsh}INBOX.phpttest' created
+
+Warning: imap_fetchbody() expects at most 4 parameters, 5 given in %s on line %d
+NULL
+
+-- Testing imap_fetchbody() function with less than expected no. of arguments --
+
+Warning: imap_fetchbody() expects at least 3 parameters, 2 given in %s on line %d
+NULL
+===DONE===
--- /dev/null
+--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() expects parameter 1 to be resource, integer given in %s on line 85
+NULL
+
+-- Iteration 2 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, integer given in %s on line 85
+NULL
+
+-- Iteration 3 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, integer given in %s on line 85
+NULL
+
+-- Iteration 4 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, integer given in %s on line 85
+NULL
+
+-- Iteration 5 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, double given in %s on line 85
+NULL
+
+-- Iteration 6 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, double given in %s on line 85
+NULL
+
+-- Iteration 7 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, double given in %s on line 85
+NULL
+
+-- Iteration 8 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, double given in %s on line 85
+NULL
+
+-- Iteration 9 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, double given in %s on line 85
+NULL
+
+-- Iteration 10 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, null given in %s on line 85
+NULL
+
+-- Iteration 11 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, null given in %s on line 85
+NULL
+
+-- Iteration 12 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, boolean given in %s on line 85
+NULL
+
+-- Iteration 13 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, boolean given in %s on line 85
+NULL
+
+-- Iteration 14 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, boolean given in %s on line 85
+NULL
+
+-- Iteration 15 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, boolean given in %s on line 85
+NULL
+
+-- Iteration 16 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line 85
+NULL
+
+-- Iteration 17 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line 85
+NULL
+
+-- Iteration 18 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, array given in %s on line 85
+NULL
+
+-- Iteration 19 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line 85
+NULL
+
+-- Iteration 20 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line 85
+NULL
+
+-- Iteration 21 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line 85
+NULL
+
+-- Iteration 22 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, object given in %s on line 85
+NULL
+
+-- Iteration 23 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, null given in %s on line 85
+NULL
+
+-- Iteration 24 --
+
+Warning: imap_fetchbody() expects parameter 1 to be resource, null given in %s on line 85
+NULL
+===DONE===
--- /dev/null
+--TEST--
+Test imap_fetchbody() function : usage variation - diff data types as $msg_no arg
+--XFAIL--
+Missing unicode implementation in ext/imap
+--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(42) "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===
--- /dev/null
+--TEST--
+Test imap_fetchbody() function : usage variation - diff data types as $section arg
+--XFAIL--
+Missing unicode implementaion in ex/imap
+--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 --
+%unicode|string%(%d) "1: this is a test message, please ignore%a"
+
+-- Iteration 3 --
+%unicode|string%(0) ""
+
+-- Iteration 4 --
+%unicode|string%(0) ""
+
+-- Iteration 5 --
+%unicode|string%(0) ""
+
+-- Iteration 6 --
+%unicode|string%(0) ""
+
+-- Iteration 7 --
+%unicode|string%(0) ""
+
+-- Iteration 8 --
+%unicode|string%(0) ""
+
+-- Iteration 9 --
+%unicode|string%(0) ""
+
+-- Iteration 10 --
+%unicode|string%(%d) "From: %s
+To: %s
+Subject: test1
+
+1: this is a test message, please ignore%a"
+
+-- Iteration 11 --
+%unicode|string%(%d) "From: %s
+To: %s
+Subject: test1
+
+1: this is a test message, please ignore%a"
+
+-- Iteration 12 --
+%unicode|string%(%d) "1: this is a test message, please ignore%a"
+
+-- Iteration 13 --
+%unicode|string%(%d) "From: %s
+To: %s
+Subject: test1
+
+1: this is a test message, please ignore%a"
+
+-- Iteration 14 --
+%unicode|string%(%d) "1: this is a test message, please ignore%a"
+
+-- Iteration 15 --
+%unicode|string%(%d) "From: %s
+To: %s
+Subject: test1
+
+1: this is a test message, please ignore%a"
+
+-- Iteration 16 --
+%unicode|string%(%d) "From: %s
+To: %s
+Subject: test1
+
+1: this is a test message, please ignore%a"
+
+-- Iteration 17 --
+%unicode|string%(%d) "From: %s
+To: %s
+Subject: test1
+
+1: this is a test message, please ignore%a"
+
+-- Iteration 18 --
+
+Warning: imap_fetchbody() expects parameter 3 to be %unicode_string_optional%, array given in %s on line 87
+NULL
+
+-- Iteration 19 --
+%unicode|string%(0) ""
+
+-- Iteration 20 --
+%unicode|string%(0) ""
+
+-- Iteration 21 --
+%unicode|string%(0) ""
+
+-- Iteration 22 --
+%unicode|string%(0) ""
+
+-- Iteration 23 --
+%unicode|string%(%d) "From: %s
+To: %s
+Subject: test1
+
+1: this is a test message, please ignore%a"
+
+-- Iteration 24 --
+%unicode|string%(%d) "From: %s
+To: %s
+Subject: test1
+
+1: this is a test message, please ignore%a"
+===DONE===
--- /dev/null
+--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===
--- /dev/null
+--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(5) of type (stream)
+
+Warning: imap_fetchbody() expects at least 3 parameters, 2 given in %s on line %d
+NULL
+
+-- Directory Resource opened with opendir() --
+resource(6) of type (stream)
+
+Warning: imap_fetchbody() expects at least 3 parameters, 2 given in %s on line %d
+NULL
+===DONE===
--- /dev/null
+--TEST--
+Test imap_fetchbody() function : usage variations - $msg_no arg
+--XFAIL--
+Missing unicoe implementation in /ext/imap
+--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 '{localhost/norsh}INBOX.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 --
+
+Notice: A non well formed numeric value encountered in %s on line %d
+%unicode|string%(%d) "1: this is a test message, please ignore%a"
+
+-- $msg_no is 1:3 --
+
+Notice: A non well formed numeric value encountered in %s on line %d
+%unicode|string%(%d) "1: this is a test message, please ignore%a"
+===DONE===