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/bug31142_1.phpt59
-rw-r--r--ext/imap/tests/bug31142_2.phpt30
-rw-r--r--ext/imap/tests/bug32589.phpt34
-rw-r--r--ext/imap/tests/bug35669.phpt68
-rw-r--r--ext/imap/tests/bug40854.phpt57
-rw-r--r--ext/imap/tests/bug44098.phpt20
-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.phpt75
-rw-r--r--ext/imap/tests/bug53377.phpt38
-rw-r--r--ext/imap/tests/bug63126.phpt52
-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.phpt48
-rw-r--r--ext/imap/tests/imap_body_basic.phpt48
-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.phpt227
-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_expunge_error.phpt27
-rw-r--r--ext/imap/tests/imap_fetch_overview_basic.phpt96
-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.phpt230
-rw-r--r--ext/imap/tests/imap_fetch_overview_variation3.phpt80
-rw-r--r--ext/imap/tests/imap_fetch_overview_variation4.phpt46
-rw-r--r--ext/imap/tests/imap_fetch_overview_variation5.phpt138
-rw-r--r--ext/imap/tests/imap_fetch_overview_variation6.phpt109
-rw-r--r--ext/imap/tests/imap_fetchbody_basic.phpt81
-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.phpt70
-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.phpt274
-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.phpt83
-rw-r--r--ext/imap/tests/imap_fetchstructure_basic.phpt70
-rw-r--r--ext/imap/tests/imap_gc_error.phpt35
-rw-r--r--ext/imap/tests/imap_getsubscribed_basic.phpt68
-rw-r--r--ext/imap/tests/imap_headerinfo_basic.phpt129
-rw-r--r--ext/imap/tests/imap_headerinfo_error.phpt36
-rw-r--r--ext/imap/tests/imap_headers.phpt28
-rw-r--r--ext/imap/tests/imap_include.inc196
-rw-r--r--ext/imap/tests/imap_list_basic.phpt47
-rw-r--r--ext/imap/tests/imap_lsub_basic.phpt61
-rw-r--r--ext/imap/tests/imap_mail_copy.phpt54
-rw-r--r--ext/imap/tests/imap_mail_copy_basic.phpt46
-rw-r--r--ext/imap/tests/imap_mail_move.phpt54
-rw-r--r--ext/imap/tests/imap_mail_move_basic.phpt46
-rw-r--r--ext/imap/tests/imap_mutf7_to_utf8.phpt23
-rw-r--r--ext/imap/tests/imap_num_msg_error.phpt28
-rw-r--r--ext/imap/tests/imap_num_recent_error.phpt27
-rw-r--r--ext/imap/tests/imap_open_error.phpt47
-rw-r--r--ext/imap/tests/imap_ping_error.phpt27
-rw-r--r--ext/imap/tests/imap_renamemailbox_basic.phpt66
-rw-r--r--ext/imap/tests/imap_rfc822_parse_headers_basic.phpt122
-rw-r--r--ext/imap/tests/imap_savebody_basic.phpt61
-rw-r--r--ext/imap/tests/imap_timeout_basic.phpt60
-rw-r--r--ext/imap/tests/imap_undelete_basic.phpt29
-rw-r--r--ext/imap/tests/imap_undelete_error.phpt36
-rw-r--r--ext/imap/tests/imap_utf8.phpt22
-rw-r--r--ext/imap/tests/imap_utf8_to_mutf7_basic.phpt23
-rw-r--r--ext/imap/tests/skipif.inc16
81 files changed, 6233 insertions, 0 deletions
diff --git a/ext/imap/tests/README b/ext/imap/tests/README
new file mode 100644
index 0000000..0d222ad
--- /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/bug31142_1.phpt b/ext/imap/tests/bug31142_1.phpt
new file mode 100644
index 0000000..efb92b7
--- /dev/null
+++ b/ext/imap/tests/bug31142_1.phpt
@@ -0,0 +1,59 @@
+--TEST--
+Bug #31142 test #1 (imap_mail_compose() generates incorrect output)
+--SKIPIF--
+<?php
+ if (!extension_loaded("imap")) {
+ die("skip imap extension not available");
+ }
+?>
+--FILE--
+<?php
+
+$envelope["from"]= "joe@example.com";
+$envelope["to"] = "foo@example.com";
+$envelope["cc"] = "bar@example.com";
+
+$part1["type"] = TYPEMULTIPART;
+$part1["subtype"] = "mixed";
+
+$part2["type"] = TYPEAPPLICATION;
+$part2["encoding"] = ENCBINARY;
+$part2["subtype"] = "octet-stream";
+$part2["description"] = "some file";
+$part2["contents.data"] = "ABC";
+
+$part3["type"] = TYPETEXT;
+$part3["subtype"] = "plain";
+$part3["description"] = "description3";
+$part3["contents.data"] = "contents.data3\n\n\n\t";
+
+$body[1] = $part1;
+$body[2] = $part2;
+$body[3] = $part3;
+
+echo imap_mail_compose($envelope, $body);
+
+?>
+--EXPECTF--
+From: joe@example.com
+To: foo@example.com
+cc: bar@example.com
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+--%s
+Content-Type: APPLICATION/octet-stream
+Content-Transfer-Encoding: BASE64
+Content-Description: some file
+
+QUJD
+
+--%s
+Content-Type: TEXT/plain; CHARSET=US-ASCII
+Content-Description: description3
+
+contents.data3
+
+
+
+--%s--
diff --git a/ext/imap/tests/bug31142_2.phpt b/ext/imap/tests/bug31142_2.phpt
new file mode 100644
index 0000000..2a81760
--- /dev/null
+++ b/ext/imap/tests/bug31142_2.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Bug #31142 test #2 (imap_mail_compose() generates incorrect output)
+--SKIPIF--
+<?php
+ if (!extension_loaded("imap")) {
+ die("skip imap extension not available");
+ }
+?>
+--FILE--
+<?php
+$envelope["from"]= 'host@domain.com';
+$envelope["return_path"]= 'host@domain.com';
+
+$part1["type"]=TYPETEXT;
+$part1["subtype"]="plain";
+$part1["encoding"]=ENCQUOTEDPRINTABLE ;
+$part1["charset"]='iso-8859-2';
+$part1["contents.data"]=imap_8bit('asn řkl');
+
+$body = array($part1);
+
+echo imap_mail_compose($envelope, $body);
+?>
+--EXPECT--
+From: host@domain.com
+MIME-Version: 1.0
+Content-Type: TEXT/plain; CHARSET=iso-8859-2
+Content-Transfer-Encoding: QUOTED-PRINTABLE
+
+asn =C5=99kl \ No newline at end of file
diff --git a/ext/imap/tests/bug32589.phpt b/ext/imap/tests/bug32589.phpt
new file mode 100644
index 0000000..c5030e8
--- /dev/null
+++ b/ext/imap/tests/bug32589.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Bug #32589 (crash inside imap_mail_compose() function)
+--SKIPIF--
+<?php
+ if (!extension_loaded("imap")) {
+ die("skip imap extension not available");
+ }
+?>
+--FILE--
+<?php
+$m_envelope["To"] = "mail@example.com";
+$m_part1["type"] = TYPEMULTIPART;
+$m_part1["subtype"] = "mixed";
+$m_part2["type"] = TYPETEXT;
+$m_part2["subtype"] = "plain";
+$m_part2["description"] = "text_message";
+
+$m_part2["charset"] = "ISO-8859-2";
+
+$m_part2["contents.data"] = "hello";
+$m_body[1] = $m_part1;
+$m_body[2] = $m_part2;
+echo imap_mail_compose($m_envelope, $m_body);
+?>
+--EXPECTF--
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+%s
+Content-Type: TEXT/plain; CHARSET=ISO-8859-2
+Content-Description: text_message
+
+hello
+%s
diff --git a/ext/imap/tests/bug35669.phpt b/ext/imap/tests/bug35669.phpt
new file mode 100644
index 0000000..1cc4e70
--- /dev/null
+++ b/ext/imap/tests/bug35669.phpt
@@ -0,0 +1,68 @@
+--TEST--
+Bug #35669 (imap_mail_compose() crashes with multipart-multiboundary-email)
+--SKIPIF--
+<?php
+ if (!extension_loaded("imap")) {
+ die("skip imap extension not available");
+ }
+?>
+--FILE--
+<?php
+ $envelope["from"] = 'Santa <somewhere@northpole.gov>';
+ $envelope["to"] = 'The bad smurf <bad@smurf.com>';
+ $envelope['date'] = 'Wed, 04 Jan 2006 19:24:43 -0500';
+
+ $multipart["type"] = TYPEMULTIPART;
+ $multipart["subtype"] = "MIXED";
+ $body[] = $multipart; //add multipart stuff
+
+ $textpart["type"] = TYPEMULTIPART;
+ $textpart["subtype"] = "ALTERNATIVE";
+ $body[] = $textpart; //add body part
+
+ $plain["type"] = TYPETEXT;
+ $plain["subtype"] = "PLAIN";
+ $plain["charset"] = "iso-8859-1";
+ $plain["encoding"] = ENCQUOTEDPRINTABLE;
+ $plain["description"] = "Plaintype part of message";
+ $plain['disposition'] = "inline";
+ $plain["contents.data"] = 'See mom, it will crash';
+
+ $body[] = $plain; //next add plain text part
+
+ $html["type"] = TYPETEXT;
+ $html["subtype"] = "HTML";
+ $html["charset"] = "iso-8859-1";
+ $html["encoding"] = ENCQUOTEDPRINTABLE;
+ $html["description"] = "HTML part of message";
+ $html['disposition'] = "inline";
+ $html["contents.data"] = 'See mom, it will <b>crash</b>';
+
+ $body[] = $html;
+
+ echo imap_mail_compose($envelope, $body);
+?>
+--EXPECTF--
+Date: Wed, 04 Jan 2006 19:24:43 -0500
+From: Santa <somewhere@northpole.gov>
+To: The bad smurf <bad@smurf.com>
+MIME-Version: 1.0
+Content-Type: MULTIPART/MIXED; BOUNDARY="%s"
+
+--%s
+Content-Type: TEXT/ALTERNATIVE; CHARSET=US-ASCII
+
+
+--%s
+Content-Type: TEXT/PLAIN; CHARSET=iso-8859-1
+Content-Transfer-Encoding: QUOTED-PRINTABLE
+Content-Description: Plaintype part of message
+
+See mom, it will crash
+--%s
+Content-Type: TEXT/HTML; CHARSET=iso-8859-1
+Content-Transfer-Encoding: QUOTED-PRINTABLE
+Content-Description: HTML part of message
+
+See mom, it will <b>crash</b>
+--%s--
diff --git a/ext/imap/tests/bug40854.phpt b/ext/imap/tests/bug40854.phpt
new file mode 100644
index 0000000..3df81ea
--- /dev/null
+++ b/ext/imap/tests/bug40854.phpt
@@ -0,0 +1,57 @@
+--TEST--
+Bug #40854 (imap_mail_compose() creates an invalid terminator for multipart e-mails)
+--SKIPIF--
+<?php
+ if (!extension_loaded("imap")) {
+ die("skip imap extension not available");
+ }
+?>
+--FILE--
+<?php
+$envelope["from"]= "joe@example.com";
+$envelope["to"] = "foo@example.com";
+$envelope["cc"] = "bar@example.com";
+
+$part1["type"] = TYPEMULTIPART;
+$part1["subtype"] = "mixed";
+
+$part2["type"] = TYPEAPPLICATION;
+$part2["encoding"] = ENCBINARY;
+$part2["subtype"] = "octet-stream";
+$part2["description"] = 'a.txt';
+$part2["contents.data"] = '';
+
+$part3["type"] = TYPETEXT;
+$part3["subtype"] = "plain";
+$part3["description"] = "description3";
+$part3["contents.data"] = "contents.data3\n\n\n\t";
+
+$body[1] = $part1;
+$body[2] = $part2;
+$body[3] = $part3;
+
+echo imap_mail_compose($envelope, $body);
+?>
+--EXPECTF--
+From: joe@example.com
+To: foo@example.com
+cc: bar@example.com
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+--%s
+Content-Type: APPLICATION/octet-stream
+Content-Transfer-Encoding: BASE64
+Content-Description: a.txt
+
+
+
+--%s
+Content-Type: TEXT/plain; CHARSET=US-ASCII
+Content-Description: description3
+
+contents.data3
+
+
+
+--%s-- \ No newline at end of file
diff --git a/ext/imap/tests/bug44098.phpt b/ext/imap/tests/bug44098.phpt
new file mode 100644
index 0000000..f758c11
--- /dev/null
+++ b/ext/imap/tests/bug44098.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Bug #44098 (imap_utf8() returns only capital letters)
+--SKIPIF--
+<?php
+ if (!extension_loaded("imap")) {
+ die("skip imap extension not available");
+ }
+?>
+--FILE--
+<?php
+$exp = 'Luzon®14 dot CoM';
+$res = imap_utf8('=?iso-8859-1?b?THV6b26uMTQ=?= dot CoM');
+if ($res != $exp) {
+ echo "failed: got <$res>, expected <exp>\n";
+} else {
+ echo "ok";
+}
+?>
+--EXPECT--
+ok
diff --git a/ext/imap/tests/bug45705_1.phpt b/ext/imap/tests/bug45705_1.phpt
new file mode 100644
index 0000000..eedaed0
--- /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 0000000..797d473
--- /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 0000000..351beca
--- /dev/null
+++ b/ext/imap/tests/bug46918.phpt
@@ -0,0 +1,75 @@
+--TEST--
+Bug #46918 (imap_rfc822_parse_adrlist host part not filled in correctly)
+--SKIPIF--
+<?php
+ if (!extension_loaded("imap")) {
+ die("skip imap extension not available");
+ }
+?>
+--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/bug53377.phpt b/ext/imap/tests/bug53377.phpt
new file mode 100644
index 0000000..1a2173a
--- /dev/null
+++ b/ext/imap/tests/bug53377.phpt
@@ -0,0 +1,38 @@
+--TEST--
+Bug #53377 (imap_mime_header_decode() doesn't ignore \t during long MIME header unfolding)
+--SKIPIF--
+<?php
+ if (!extension_loaded("imap")) {
+ die("skip imap extension not available");
+ }
+?>
+--FILE--
+<?php
+$s = "=?UTF-8?Q?=E2=82=AC?=";
+$header = "$s\n $s\n\t$s";
+
+var_dump(imap_mime_header_decode($header));
+--EXPECT--
+array(3) {
+ [0]=>
+ object(stdClass)#1 (2) {
+ ["charset"]=>
+ string(5) "UTF-8"
+ ["text"]=>
+ string(3) "€"
+ }
+ [1]=>
+ object(stdClass)#2 (2) {
+ ["charset"]=>
+ string(5) "UTF-8"
+ ["text"]=>
+ string(3) "€"
+ }
+ [2]=>
+ object(stdClass)#3 (2) {
+ ["charset"]=>
+ string(5) "UTF-8"
+ ["text"]=>
+ string(3) "€"
+ }
+}
diff --git a/ext/imap/tests/bug63126.phpt b/ext/imap/tests/bug63126.phpt
new file mode 100644
index 0000000..70fba38
--- /dev/null
+++ b/ext/imap/tests/bug63126.phpt
@@ -0,0 +1,52 @@
+--TEST--
+imap_open() DISABLE_AUTHENTICATOR ignores array param
+--SKIPIF--
+<?php
+extension_loaded('imap') or die('skip imap extension not available in this build');
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+$in = imap_open($default_mailbox, $username, $password, OP_HALFOPEN, 1);
+if (!$in) {
+ die("skip could not connect to mailbox $default_mailbox");
+}
+$kerberos = false;
+if (is_array($errors = imap_errors())) {
+ foreach ($errors as $err) {
+ if (strstr($err, 'GSSAPI') || strstr($err, 'Kerberos')) {
+ $kerberos = true;
+ }
+ }
+}
+if (!$kerberos) {
+ die("skip need a GSSAPI/Kerberos aware server");
+}
+?>
+--FILE--
+<?php
+$tests = array(
+ 'Array' => array('DISABLE_AUTHENTICATOR' => array('GSSAPI','NTLM')),
+ 'String' => array('DISABLE_AUTHENTICATOR' => 'GSSAPI'),
+);
+require_once(dirname(__FILE__).'/imap_include.inc');
+foreach ($tests as $name => $testparams) {
+ echo "Test for $name\n";
+ $in = imap_open($default_mailbox, $username, $password, OP_HALFOPEN, 1, $testparams);
+ if ($in) {
+ if (is_array($errors = imap_errors())) {
+ foreach ($errors as $err) {
+ if (strstr($err, 'GSSAPI') || strstr($err, 'Kerberos')) {
+ echo "$err\n";
+ }
+ }
+ }
+ } else {
+ echo "Can't connect\n";
+ }
+}
+echo "Done\n";
+?>
+--EXPECTF--
+Test for Array
+Test for String
+Done
diff --git a/ext/imap/tests/clean.inc b/ext/imap/tests/clean.inc
new file mode 100644
index 0000000..f5e869f
--- /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 0000000..aaa0591
--- /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 0000000..ab13ec4
--- /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: imap_alerts() expects exactly 0 parameters, 1 given 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 0000000..60847ce
--- /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 0000000..a64be27
--- /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 0000000..bd4eabb
--- /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.phpt b/ext/imap/tests/imap_body.phpt
new file mode 100644
index 0000000..40f35f0
--- /dev/null
+++ b/ext/imap/tests/imap_body.phpt
@@ -0,0 +1,48 @@
+--TEST--
+imap_body() incorrect parameter count
+--CREDITS--
+Paul Sohier
+#phptestfest utrecht
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+echo "Checking with no parameters\n";
+imap_body();
+
+echo "Checking with incorrect parameter type\n";
+imap_body('');
+imap_body(false);
+require_once(dirname(__FILE__).'/imap_include.inc');
+$stream_id = imap_open($default_mailbox, $username, $password) or
+ die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
+imap_body($stream_id);
+imap_body($stream_id,-1);
+imap_body($stream_id,1,-1);
+
+//Access not existing
+var_dump(imap_body($stream_id, 999, FT_UID));
+
+imap_close($stream_id);
+
+?>
+--EXPECTF--
+Checking with no parameters
+
+Warning: imap_body() expects at least 2 parameters, 0 given in %s on line %d
+Checking with incorrect parameter type
+
+Warning: imap_body() expects at least 2 parameters, 1 given in %s on line %d
+
+Warning: imap_body() expects at least 2 parameters, 1 given in %s on line %d
+
+Warning: imap_body() expects at least 2 parameters, 1 given in %s on line %d
+
+Warning: imap_body(): Bad message number in %s on line %d
+
+Warning: imap_body(): invalid value for the options parameter in %s on line %d
+
+Warning: imap_body(): Bad message number in %s on line %d
+bool(false) \ No newline at end of file
diff --git a/ext/imap/tests/imap_body_basic.phpt b/ext/imap/tests/imap_body_basic.phpt
new file mode 100644
index 0000000..0eb4a2b
--- /dev/null
+++ b/ext/imap/tests/imap_body_basic.phpt
@@ -0,0 +1,48 @@
+--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));
+
+//Access via FT_UID
+var_dump(imap_body($imap_stream, 1, FT_UID));
+
+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
+%unicode|string%(%d) "1: this is a test message, please ignore%a"
+%unicode|string%(%d) "1: this is a test message, please ignore%a"
+===Done===
diff --git a/ext/imap/tests/imap_bodystruct_basic.phpt b/ext/imap/tests/imap_bodystruct_basic.phpt
new file mode 100644
index 0000000..cc643a6
--- /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 '{%s}%s' 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 0000000..4269688
--- /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 '{%s}%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 0000000..a998530
--- /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 0000000..fd32f3e
--- /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: 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===
diff --git a/ext/imap/tests/imap_close_variation1.phpt b/ext/imap/tests/imap_close_variation1.phpt
new file mode 100644
index 0000000..3203905
--- /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() 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===
diff --git a/ext/imap/tests/imap_close_variation2.phpt b/ext/imap/tests/imap_close_variation2.phpt
new file mode 100644
index 0000000..feadfed
--- /dev/null
+++ b/ext/imap/tests/imap_close_variation2.phpt
@@ -0,0 +1,227 @@
+--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 '{%s}%s' 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===
diff --git a/ext/imap/tests/imap_close_variation3.phpt b/ext/imap/tests/imap_close_variation3.phpt
new file mode 100644
index 0000000..6f6161a
--- /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 0000000..ca82619
--- /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 '{%s}%s' 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 0000000..431d59f
--- /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 0000000..91be328
--- /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 occurred.
+ * 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_expunge_error.phpt b/ext/imap/tests/imap_expunge_error.phpt
new file mode 100644
index 0000000..d99dcf0
--- /dev/null
+++ b/ext/imap/tests/imap_expunge_error.phpt
@@ -0,0 +1,27 @@
+--TEST--
+imap_num_recent() incorrect parameter count
+--CREDITS--
+Paul Sohier
+#phptestfest utrecht
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+echo "Checking with no parameters\n";
+imap_num_recent();
+
+echo "Checking with incorrect parameter type\n";
+imap_num_recent('');
+imap_num_recent(false);
+?>
+--EXPECTF--
+Checking with no parameters
+
+Warning: imap_num_recent() expects exactly 1 parameter, 0 given in %s on line %d
+Checking with incorrect parameter type
+
+Warning: imap_num_recent() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d
+
+Warning: imap_num_recent() expects parameter 1 to be resource, boolean given in %s on line %d
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 0000000..83fab12
--- /dev/null
+++ b/ext/imap/tests/imap_fetch_overview_basic.phpt
@@ -0,0 +1,96 @@
+--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;
+
+// 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";
+displayOverviewFields($a[0]);
+
+// 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";
+displayOverviewFields($a[0]);
+
+//Second object in array
+echo "\n--> Object #2\n";
+displayOverviewFields($a[1]);
+
+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 '{%s}%s' 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
+udate is OK
+
+-- 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
+udate is OK
+
+--> 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
+udate is OK
+===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 0000000..e300e62
--- /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}%s' created
+
+Warning: imap_fetch_overview() expects at most 3 parameters, 4 given in %s on line %d
+NULL
+
+-- Testing imap_fetch_overview() function with less than expected no. of arguments --
+
+Warning: imap_fetch_overview() expects at least 2 parameters, 1 given 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 0000000..150c555
--- /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() expects parameter 1 to be resource, integer given in %s on line %d
+NULL
+
+-- Testing with first argument value: int(1)
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, integer given in %s on line %d
+NULL
+
+-- Testing with first argument value: int(12345)
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, integer given in %s on line %d
+NULL
+
+-- Testing with first argument value: int(-2345)
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, integer given in %s on line %d
+NULL
+
+-- Testing with first argument value: float(10.5)
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, double given in %s on line %d
+NULL
+
+-- Testing with first argument value: float(-10.5)
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, double given in %s on line %d
+NULL
+
+-- Testing with first argument value: float(123456789000)
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, double given in %s on line %d
+NULL
+
+-- Testing with first argument value: float(1.23456789E-9)
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, double given in %s on line %d
+NULL
+
+-- Testing with first argument value: float(0.5)
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, double given in %s on line %d
+NULL
+
+-- Testing with first argument value: NULL
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, null given in %s on line %d
+NULL
+
+-- Testing with first argument value: NULL
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, null given in %s on line %d
+NULL
+
+-- Testing with first argument value: bool(true)
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, boolean given in %s on line %d
+NULL
+
+-- Testing with first argument value: bool(false)
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, boolean given in %s on line %d
+NULL
+
+-- Testing with first argument value: bool(true)
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, boolean given in %s on line %d
+NULL
+
+-- Testing with first argument value: bool(false)
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, boolean given in %s on line %d
+NULL
+
+-- Testing with first argument value: %string|unicode%(0) ""
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d
+NULL
+
+-- Testing with first argument value: %string|unicode%(0) ""
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d
+NULL
+
+-- Testing with first argument value: array(0) {
+}
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, array given in %s on line %d
+NULL
+
+-- Testing with first argument value: %string|unicode%(6) "string"
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d
+NULL
+
+-- Testing with first argument value: %string|unicode%(6) "string"
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d
+NULL
+
+-- Testing with first argument value: %string|unicode%(11) "hello world"
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d
+NULL
+
+-- Testing with first argument value: object(classA)#1 (0) {
+}
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, object given in %s on line %d
+NULL
+
+-- Testing with first argument value: NULL
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, null given in %s on line %d
+NULL
+
+-- Testing with first argument value: NULL
+
+Warning: imap_fetch_overview() expects parameter 1 to be resource, null given in %s on line %d
+NULL
+===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 0000000..086885f
--- /dev/null
+++ b/ext/imap/tests/imap_fetch_overview_variation2.phpt
@@ -0,0 +1,230 @@
+--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
+
+//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 {
+ displayOverviewFields($overview[0]);
+ }
+ $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 '{%s}%s' 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
+udate is OK
+
+-- 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
+udate is OK
+
+-- 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
+udate is OK
+
+-- Testing with second argument value: bool(false)
+Sequence out of range
+
+-- Testing with second argument value: %string|unicode%(0) ""
+Sequence out of range
+
+-- Testing with second argument value: %string|unicode%(0) ""
+Sequence out of range
+
+-- Testing with second argument value: array(0) {
+}
+
+Warning: imap_fetch_overview() expects parameter 2 to be %binary_string_optional%, array given in %s on line %d
+Sequence out of range
+
+-- Testing with second argument value: %string|unicode%(6) "string"
+Syntax error in sequence
+
+-- Testing with second argument value: %string|unicode%(6) "string"
+Syntax error in sequence
+
+-- Testing with second argument value: %string|unicode%(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)
+
+Warning: imap_fetch_overview() expects parameter 2 to be %binary_string_optional%, resource given in %s on line %d
+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 0000000..7bd78d8
--- /dev/null
+++ b/ext/imap/tests/imap_fetch_overview_variation3.phpt
@@ -0,0 +1,80 @@
+--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 '{%s}%s' created
+
+Testing with option value:%string|unicode%(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 0000000..a5c2666
--- /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 0000000..5feeedb
--- /dev/null
+++ b/ext/imap/tests/imap_fetch_overview_variation5.phpt
@@ -0,0 +1,138 @@
+--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
+
+$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";
+ displayOverviewFields($ov);
+ }
+ }
+}
+
+// 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 '{%s}%s' 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
+udate is OK
+
+-- $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
+udate is OK
+
+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
+udate is OK
+
+-- $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
+udate is OK
+
+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
+udate is OK
+
+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
+udate is OK
+===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 0000000..bdf0557
--- /dev/null
+++ b/ext/imap/tests/imap_fetch_overview_variation6.phpt
@@ -0,0 +1,109 @@
+--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);
+
+// refresh msg numbers
+imap_check($stream_id);
+$msg_no = 1;
+
+$a = imap_fetch_overview($stream_id, $msg_no);
+echo "\n--> Object #1\n";
+displayOverviewFields($a[0]);
+
+
+
+
+/**
+ * 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 '{%s}%s' 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
+udate is OK
+===DONE===
diff --git a/ext/imap/tests/imap_fetchbody_basic.phpt b/ext/imap/tests/imap_fetchbody_basic.phpt
new file mode 100644
index 0000000..66b84b1
--- /dev/null
+++ b/ext/imap/tests/imap_fetchbody_basic.phpt
@@ -0,0 +1,81 @@
+--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('', 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 '{%s}%s' 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===
diff --git a/ext/imap/tests/imap_fetchbody_error.phpt b/ext/imap/tests/imap_fetchbody_error.phpt
new file mode 100644
index 0000000..f496fbd
--- /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}%s' 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===
diff --git a/ext/imap/tests/imap_fetchbody_variation1.phpt b/ext/imap/tests/imap_fetchbody_variation1.phpt
new file mode 100644
index 0000000..5f587df
--- /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() 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===
diff --git a/ext/imap/tests/imap_fetchbody_variation2.phpt b/ext/imap/tests/imap_fetchbody_variation2.phpt
new file mode 100644
index 0000000..64b7a32
--- /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 '{%s}%s' created
+
+-- Iteration 1 --
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 2 --
+%unicode|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 --
+%unicode|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 --
+%unicode|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() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d
+NULL
+
+-- Iteration 17 --
+
+Warning: imap_fetchbody() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d
+NULL
+
+-- Iteration 18 --
+
+Warning: imap_fetchbody() expects parameter 2 to be long, array given in %s on line %d
+NULL
+
+-- Iteration 19 --
+
+Warning: imap_fetchbody() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d
+NULL
+
+-- Iteration 20 --
+
+Warning: imap_fetchbody() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d
+NULL
+
+-- Iteration 21 --
+
+Warning: imap_fetchbody() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d
+NULL
+
+-- Iteration 22 --
+
+Warning: imap_fetchbody() expects parameter 2 to be long, object given in %s on line %d
+NULL
+
+-- 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 0000000..dc1778e
--- /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 --
+%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===
diff --git a/ext/imap/tests/imap_fetchbody_variation4.phpt b/ext/imap/tests/imap_fetchbody_variation4.phpt
new file mode 100644
index 0000000..d8126bc
--- /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 '{%s}%s' 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 0000000..dfc5e9f
--- /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(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===
diff --git a/ext/imap/tests/imap_fetchbody_variation6.phpt b/ext/imap/tests/imap_fetchbody_variation6.phpt
new file mode 100644
index 0000000..52a50a7
--- /dev/null
+++ b/ext/imap/tests/imap_fetchbody_variation6.phpt
@@ -0,0 +1,70 @@
+--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}%s' 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===
diff --git a/ext/imap/tests/imap_fetchheader_basic.phpt b/ext/imap/tests/imap_fetchheader_basic.phpt
new file mode 100644
index 0000000..5502c55
--- /dev/null
+++ b/ext/imap/tests/imap_fetchheader_basic.phpt
@@ -0,0 +1,83 @@
+--TEST--
+Test imap_fetchheader() function : basic function
+--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 0000000..e2f5b12
--- /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: imap_fetchheader() expects at most 3 parameters, 4 given in %s on line %d
+NULL
+
+-- Testing imap_fetchheader() function with less than expected no. of arguments --
+
+Warning: imap_fetchheader() expects at least 2 parameters, 1 given 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 0000000..0c0e9e1
--- /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() expects parameter 1 to be resource, integer given in %s on line %d
+NULL
+
+-- Iteration 2 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, integer given in %s on line %d
+NULL
+
+-- Iteration 3 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, integer given in %s on line %d
+NULL
+
+-- Iteration 4 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, integer given in %s on line %d
+NULL
+
+-- Iteration 5 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, double given in %s on line %d
+NULL
+
+-- Iteration 6 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, double given in %s on line %d
+NULL
+
+-- Iteration 7 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, double given in %s on line %d
+NULL
+
+-- Iteration 8 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, double given in %s on line %d
+NULL
+
+-- Iteration 9 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, double given in %s on line %d
+NULL
+
+-- Iteration 10 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, null given in %s on line %d
+NULL
+
+-- Iteration 11 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, null given in %s on line %d
+NULL
+
+-- Iteration 12 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, boolean given in %s on line %d
+NULL
+
+-- Iteration 13 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, boolean given in %s on line %d
+NULL
+
+-- Iteration 14 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, boolean given in %s on line %d
+NULL
+
+-- Iteration 15 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, boolean given in %s on line %d
+NULL
+
+-- Iteration 16 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d
+NULL
+
+-- Iteration 17 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d
+NULL
+
+-- Iteration 18 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d
+NULL
+
+-- Iteration 19 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d
+NULL
+
+-- Iteration 20 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d
+NULL
+
+-- Iteration 21 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, array given in %s on line %d
+NULL
+
+-- Iteration 22 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, array given in %s on line %d
+NULL
+
+-- Iteration 23 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, array given in %s on line %d
+NULL
+
+-- Iteration 24 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, array given in %s on line %d
+NULL
+
+-- Iteration 25 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, object given in %s on line %d
+NULL
+
+-- Iteration 26 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, null given in %s on line %d
+NULL
+
+-- Iteration 27 --
+
+Warning: imap_fetchheader() expects parameter 1 to be resource, null given in %s on line %d
+NULL
+===DONE===
diff --git a/ext/imap/tests/imap_fetchheader_variation2.phpt b/ext/imap/tests/imap_fetchheader_variation2.phpt
new file mode 100644
index 0000000..fe11577
--- /dev/null
+++ b/ext/imap/tests/imap_fetchheader_variation2.phpt
@@ -0,0 +1,274 @@
+--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 '{%s}%s' created
+
+-- Iteration 1 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 2 --
+%unicode|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 --
+%unicode|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 --
+%unicode|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() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d
+NULL
+
+-- Iteration 17 --
+
+Warning: imap_fetchheader() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d
+NULL
+
+-- Iteration 18 --
+
+Warning: imap_fetchheader() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d
+NULL
+
+-- Iteration 19 --
+
+Warning: imap_fetchheader() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d
+NULL
+
+-- Iteration 20 --
+
+Warning: imap_fetchheader() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d
+NULL
+
+-- Iteration 21 --
+
+Warning: imap_fetchheader() expects parameter 2 to be long, array given in %s on line %d
+NULL
+
+-- Iteration 22 --
+
+Warning: imap_fetchheader() expects parameter 2 to be long, array given in %s on line %d
+NULL
+
+-- Iteration 23 --
+
+Warning: imap_fetchheader() expects parameter 2 to be long, array given in %s on line %d
+NULL
+
+-- Iteration 24 --
+
+Warning: imap_fetchheader() expects parameter 2 to be long, array given in %s on line %d
+NULL
+
+-- Iteration 25 --
+
+Warning: imap_fetchheader() expects parameter 2 to be long, object given in %s on line %d
+NULL
+
+-- 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() expects parameter 2 to be long, resource given in %s on line %d
+NULL
+===DONE===
diff --git a/ext/imap/tests/imap_fetchheader_variation3.phpt b/ext/imap/tests/imap_fetchheader_variation3.phpt
new file mode 100644
index 0000000..feba766
--- /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 '{%s}%s' 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 0000000..b4b19e3
--- /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 0000000..ed2aa84
--- /dev/null
+++ b/ext/imap/tests/imap_fetchheader_variation5.phpt
@@ -0,0 +1,83 @@
+--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 '{%s}%s' 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 --
+
+Notice: A non well formed numeric value encountered in %s on line %d
+%unicode|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 --
+
+Notice: A non well formed numeric value encountered in %s on line %d
+%unicode|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_fetchstructure_basic.phpt b/ext/imap/tests/imap_fetchstructure_basic.phpt
new file mode 100644
index 0000000..7ad4fc5
--- /dev/null
+++ b/ext/imap/tests/imap_fetchstructure_basic.phpt
@@ -0,0 +1,70 @@
+--TEST--
+imap_fetchstructure() function : basic functionality
+--CREDITS--
+Olivier Doucet
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+echo "Checking with no parameters\n";
+imap_fetchstructure();
+
+echo "Checking with incorrect parameter type\n";
+imap_fetchstructure('');
+imap_fetchstructure(false);
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+$stream_id = setup_test_mailbox('', 1);
+
+imap_fetchstructure($stream_id);
+imap_fetchstructure($stream_id,0);
+
+$z = imap_fetchstructure($stream_id,1);
+
+
+$fields = array('type','encoding','ifsubtype','subtype',
+'ifdescription','lines','bytes','parameters');
+
+foreach ($fields as $key) {
+ var_dump(isset($z->$key));
+}
+var_dump($z->type);
+var_dump($z->encoding);
+var_dump($z->bytes);
+var_dump($z->lines);
+var_dump(is_object($z->parameters));
+
+imap_close($stream_id);
+?>
+--CLEAN--
+<?php
+require_once('clean.inc');
+?>
+--EXPECTF--
+Checking with no parameters
+
+Warning: imap_fetchstructure() expects at least 2 parameters, 0 given in %s on line %d
+Checking with incorrect parameter type
+
+Warning: imap_fetchstructure() expects at least 2 parameters, 1 given in %s on line %d
+
+Warning: imap_fetchstructure() expects at least 2 parameters, 1 given in %s on line %d
+Create a temporary mailbox and add 1 msgs
+.. mailbox '{%s}%s' created
+
+Warning: imap_fetchstructure() expects at least 2 parameters, 1 given in %s on line %d
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+int(%d)
+int(%d)
+int(%d)
+int(%d)
+bool(true) \ No newline at end of file
diff --git a/ext/imap/tests/imap_gc_error.phpt b/ext/imap/tests/imap_gc_error.phpt
new file mode 100644
index 0000000..f8e6201
--- /dev/null
+++ b/ext/imap/tests/imap_gc_error.phpt
@@ -0,0 +1,35 @@
+--TEST--
+imap_gc() incorrect parameter count
+--CREDITS--
+Paul Sohier
+#phptestfest utrecht
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+echo "Checking with no parameters\n";
+imap_gc();
+
+echo "Checking with incorrect parameter type\n";
+imap_gc('', false);
+imap_gc(false, false);
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+$stream_id = imap_open($default_mailbox, $username, $password) or
+ die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
+imap_gc($stream_id, -1);
+
+?>
+--EXPECTF--
+Checking with no parameters
+
+Warning: imap_gc() expects exactly 2 parameters, 0 given in %s on line %d
+Checking with incorrect parameter type
+
+Warning: imap_gc() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d
+
+Warning: imap_gc() expects parameter 1 to be resource, boolean given in %s on line %d
+
+Warning: imap_gc(): invalid value for the flags parameter in %s on line %d
diff --git a/ext/imap/tests/imap_getsubscribed_basic.phpt b/ext/imap/tests/imap_getsubscribed_basic.phpt
new file mode 100644
index 0000000..ba8a42d
--- /dev/null
+++ b/ext/imap/tests/imap_getsubscribed_basic.phpt
@@ -0,0 +1,68 @@
+--TEST--
+imap_getsubscribed() function : basic functionality
+--CREDITS--
+Olivier Doucet
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+echo "Checking with no parameters\n";
+imap_getsubscribed();
+
+echo "Checking with incorrect parameter type\n";
+imap_getsubscribed('');
+imap_getsubscribed(false);
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+$stream_id = imap_open($default_mailbox, $username, $password) or
+ die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
+
+imap_getsubscribed($stream_id);
+imap_getsubscribed($stream_id,$default_mailbox);
+var_dump(imap_getsubscribed($stream_id,$default_mailbox,'ezDvfXvbvcxSerz'));
+
+
+echo "Checking OK\n";
+
+$newbox = $default_mailbox . "." . $mailbox_prefix;
+
+imap_createmailbox($stream_id, $newbox);
+imap_subscribe($stream_id, $newbox);
+
+$z = imap_getsubscribed($stream_id,$default_mailbox,'*');
+
+var_dump(is_array($z));
+var_dump($z[0]);
+
+imap_close($stream_id);
+?>
+--CLEAN--
+<?php
+require_once('clean.inc');
+?>
+--EXPECTF--
+Checking with no parameters
+
+Warning: imap_getsubscribed() expects exactly 3 parameters, 0 given in %s on line %d
+Checking with incorrect parameter type
+
+Warning: imap_getsubscribed() expects exactly 3 parameters, 1 given in %s on line %d
+
+Warning: imap_getsubscribed() expects exactly 3 parameters, 1 given in %s on line %d
+
+Warning: imap_getsubscribed() expects exactly 3 parameters, 1 given in %s on line %d
+
+Warning: imap_getsubscribed() expects exactly 3 parameters, 2 given in %s on line %d
+bool(false)
+Checking OK
+bool(true)
+object(stdClass)#%d (%d) {
+ [%sname"]=>
+ string(%d) "{%s}%s"
+ [%sattributes"]=>
+ int(%d)
+ [%sdelimiter"]=>
+ string(%d) "%s"
+} \ No newline at end of file
diff --git a/ext/imap/tests/imap_headerinfo_basic.phpt b/ext/imap/tests/imap_headerinfo_basic.phpt
new file mode 100644
index 0000000..b772476
--- /dev/null
+++ b/ext/imap/tests/imap_headerinfo_basic.phpt
@@ -0,0 +1,129 @@
+--TEST--
+imap_headerinfo() function : basic functionality
+--CREDITS--
+Olivier Doucet
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+$stream_id = setup_test_mailbox('', 1);
+
+$z = imap_headerinfo($stream_id, 1);
+
+$fields = array ('toaddress','to','fromaddress','from',
+'reply_toaddress','reply_to',
+ 'senderaddress', 'sender',
+'subject','Subject',
+ 'Recent','Unseen','Flagged','Answered','Deleted','Draft',
+ 'Msgno','MailDate','Size','udate');
+
+echo "Check general fields\n";
+foreach ($fields as $key) {
+ var_dump(isset($z->$key));
+}
+
+echo "Check type\n";
+var_dump($z->toaddress);
+var_dump($z->fromaddress);
+var_dump($z->reply_toaddress);
+var_dump($z->senderaddress);
+var_dump($z->subject);
+var_dump($z->Subject);
+
+if ($z->Recent == 'R' || $z->Recent == 'N' || $z->Recent == ' ') {
+ echo "Recent: OK";
+} else {
+ echo "Recent: error: ".$z->Recent;
+}
+echo "\n";
+
+if ($z->Unseen == 'U' || $z->Unseen == ' ') {
+ echo "Unseen: OK";
+} else {
+ echo "Unseen: error: ".$z->Unseen;
+}
+echo "\n";
+
+if ($z->Flagged == 'F' || $z->Flagged == ' ') {
+ echo "Flagged: OK";
+} else {
+ echo "Flagged: error: ".$z->Flagged;
+}
+echo "\n";
+
+if ($z->Answered == 'A' || $z->Answered == ' ') {
+ echo "Answered: OK";
+} else {
+ echo "Answered: error";
+}
+echo "\n";
+
+if ($z->Deleted == 'D' || $z->Deleted == ' ') {
+ echo "Deleted: OK";
+} else {
+ echo "Deleted: error";
+}
+echo "\n";
+
+if ($z->Draft == 'X' || $z->Draft == ' ') {
+ echo "Draft: OK";
+} else {
+ echo "Draft: error";
+}
+echo "\n";
+
+var_dump($z->Msgno);
+var_dump($z->Size);
+var_dump($z->udate);
+
+imap_close($stream_id);
+
+?>
+--CLEAN--
+<?php
+require_once('clean.inc');
+?>
+--EXPECTF--
+Create a temporary mailbox and add 1 msgs
+.. mailbox '{%s}%s' created
+Check general fields
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Check type
+string(%d) "%s"
+string(%d) "%s"
+string(%d) "%s"
+string(%d) "%s"
+string(%d) "%s"
+string(%d) "%s"
+Recent: OK
+Unseen: OK
+Flagged: OK
+Answered: OK
+Deleted: OK
+Draft: OK
+string(%d) "%s"
+string(%d) "%d"
+int(%d) \ No newline at end of file
diff --git a/ext/imap/tests/imap_headerinfo_error.phpt b/ext/imap/tests/imap_headerinfo_error.phpt
new file mode 100644
index 0000000..b526096
--- /dev/null
+++ b/ext/imap/tests/imap_headerinfo_error.phpt
@@ -0,0 +1,36 @@
+--TEST--
+imap_headerinfo() incorrect parameter count
+--CREDITS--
+Olivier Doucet
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+echo "Checking with no parameters\n";
+imap_headerinfo();
+
+echo "Checking with incorrect parameter type\n";
+imap_headerinfo('');
+imap_headerinfo(false);
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+$stream_id = imap_open($default_mailbox, $username, $password) or
+ die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
+
+imap_headerinfo($stream_id);
+
+imap_close($stream_id);
+?>
+--EXPECTF--
+Checking with no parameters
+
+Warning: imap_headerinfo() expects at least 2 parameters, 0 given in %s on line %d
+Checking with incorrect parameter type
+
+Warning: imap_headerinfo() expects at least 2 parameters, 1 given in %s on line %d
+
+Warning: imap_headerinfo() expects at least 2 parameters, 1 given in %s on line %d
+
+Warning: imap_headerinfo() expects at least 2 parameters, 1 given in %s on line %d
diff --git a/ext/imap/tests/imap_headers.phpt b/ext/imap/tests/imap_headers.phpt
new file mode 100644
index 0000000..93c51f9
--- /dev/null
+++ b/ext/imap/tests/imap_headers.phpt
@@ -0,0 +1,28 @@
+--TEST--
+imap_headers() incorrect parameter count
+--CREDITS--
+Paul Sohier
+#phptestfest utrecht
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+echo "Checking with no parameters\n";
+imap_headers();
+
+echo "Checking with incorrect parameter type\n";
+imap_headers('');
+imap_headers(false);
+?>
+--EXPECTF--
+Checking with no parameters
+
+Warning: imap_headers() expects exactly 1 parameter, 0 given in %s on line %d
+Checking with incorrect parameter type
+
+Warning: imap_headers() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d
+
+Warning: imap_headers() expects parameter 1 to be resource, boolean given in %s on line %d
+
diff --git a/ext/imap/tests/imap_include.inc b/ext/imap/tests/imap_include.inc
new file mode 100644
index 0000000..ed36239
--- /dev/null
+++ b/ext/imap/tests/imap_include.inc
@@ -0,0 +1,196 @@
+<?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
+
+// record test start time (used by displayOverviewFields())
+$start_time = time();
+
+// list of fields to expect
+$mandatory_overview_fields = array(
+ 'size',
+ 'uid',
+ 'msgno',
+ 'recent',
+ 'flagged',
+ 'answered',
+ 'deleted',
+ 'seen',
+ 'draft',
+ 'udate',
+ );
+
+/**
+ * Display all fields in an element from an imap_fetch_overview() response
+ *
+ * Special handling for 'udate', which will vary run-to-run; assumes an IMAP
+ * server with its clock synced to the current system, which is consistent with
+ * setup instructions in ext/imap/tests/README
+ *
+ * @param array resp element from the return value of imap_fetch_overview()
+ */
+function displayOverviewFields($resp, $fields=null) {
+ global $mandatory_overview_fields;
+ global $start_time;
+
+ foreach ($fields ? $fields : $mandatory_overview_fields as $mf)
+ {
+ $z = $resp->$mf;
+ if ($mf == 'udate') {
+ if (($z >= $start_time) && ($z <= time())) {
+ echo "$mf is OK\n";
+ } else {
+ echo "$mf is BAD ($z)\n";
+ }
+ } else {
+ echo "$mf is $z\n";
+ }
+ }
+}
+
+
+/**
+ * Create a test mailbox and populate with msgs
+ *
+ * @param string mailbox_suffix Suffix used to uniquely identify mailboxes
+ * @param int message_count number of test msgs to be written to new mailbox
+ *
+ * @return IMAP stream to new mailbox on 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/imap_list_basic.phpt b/ext/imap/tests/imap_list_basic.phpt
new file mode 100644
index 0000000..36f07f7
--- /dev/null
+++ b/ext/imap/tests/imap_list_basic.phpt
@@ -0,0 +1,47 @@
+--TEST--
+imap_list() function : basic functionality
+--CREDITS--
+Olivier Doucet
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+echo "Checking with no parameters\n";
+imap_list();
+
+echo "Checking with incorrect parameter type\n";
+imap_list('');
+imap_list(false);
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+$stream_id = imap_open($default_mailbox, $username, $password) or
+ die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
+
+imap_list($stream_id);
+imap_list($stream_id,$default_mailbox);
+imap_list($stream_id,$default_mailbox,'ezerz');
+
+
+$z = imap_list($stream_id,$default_mailbox,'*');
+var_dump(is_array($z));
+var_dump($z[0]);
+
+imap_close($stream_id);
+?>
+--EXPECTF--
+Checking with no parameters
+
+Warning: imap_list() expects exactly 3 parameters, 0 given in %s on line %d
+Checking with incorrect parameter type
+
+Warning: imap_list() expects exactly 3 parameters, 1 given in %s on line %d
+
+Warning: imap_list() expects exactly 3 parameters, 1 given in %s on line %d
+
+Warning: imap_list() expects exactly 3 parameters, 1 given in %s on line %d
+
+Warning: imap_list() expects exactly 3 parameters, 2 given in %s on line %d
+bool(true)
+string(%s) "{%s}%s" \ No newline at end of file
diff --git a/ext/imap/tests/imap_lsub_basic.phpt b/ext/imap/tests/imap_lsub_basic.phpt
new file mode 100644
index 0000000..153ca2a
--- /dev/null
+++ b/ext/imap/tests/imap_lsub_basic.phpt
@@ -0,0 +1,61 @@
+--TEST--
+imap_lsub() function : basic functionality
+--CREDITS--
+Olivier Doucet
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+echo "Checking with no parameters\n";
+imap_lsub();
+
+echo "Checking with incorrect parameter type\n";
+imap_lsub('');
+imap_lsub(false);
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+$stream_id = imap_open($default_mailbox, $username, $password) or
+ die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
+
+imap_lsub($stream_id);
+imap_lsub($stream_id,$default_mailbox);
+var_dump(imap_lsub($stream_id,$default_mailbox,'ezDvfXvbvcxSerz'));
+
+
+echo "Checking OK\n";
+
+$newbox = $default_mailbox . "." . $mailbox_prefix;
+
+imap_createmailbox($stream_id, $newbox);
+imap_subscribe($stream_id, $newbox);
+
+$z = imap_lsub($stream_id,$default_mailbox,'*');
+
+var_dump(is_array($z));
+var_dump($z[0]);
+
+imap_close($stream_id);
+?>
+--CLEAN--
+<?php
+require_once('clean.inc');
+?>
+--EXPECTF--
+Checking with no parameters
+
+Warning: imap_lsub() expects exactly 3 parameters, 0 given in %s on line %d
+Checking with incorrect parameter type
+
+Warning: imap_lsub() expects exactly 3 parameters, 1 given in %s on line %d
+
+Warning: imap_lsub() expects exactly 3 parameters, 1 given in %s on line %d
+
+Warning: imap_lsub() expects exactly 3 parameters, 1 given in %s on line %d
+
+Warning: imap_lsub() expects exactly 3 parameters, 2 given in %s on line %d
+bool(false)
+Checking OK
+bool(true)
+string(%s) "{%s}%s" \ No newline at end of file
diff --git a/ext/imap/tests/imap_mail_copy.phpt b/ext/imap/tests/imap_mail_copy.phpt
new file mode 100644
index 0000000..47c5e61
--- /dev/null
+++ b/ext/imap/tests/imap_mail_copy.phpt
@@ -0,0 +1,54 @@
+--TEST--
+Test imap_mail_copy() incorrect parameters
+--CREDITS--
+Olivier Doucet
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+echo "Checking with no parameters\n";
+imap_mail_copy();
+
+
+echo "Checking with incorrect parameter type\n";
+imap_mail_copy('');
+imap_mail_copy(false);
+
+
+// more tests
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+
+echo "Test with IMAP server\n";
+$stream_id = imap_open($default_mailbox, $username, $password) or
+ die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
+
+var_dump(imap_mail_copy($stream_id));
+var_dump(imap_mail_copy($stream_id,-1));
+var_dump(imap_mail_copy($stream_id, ''));
+
+imap_close($stream_id);
+?>
+===Done===
+--EXPECTF--
+Checking with no parameters
+
+Warning: imap_mail_copy() expects at least 3 parameters, 0 given in %s on line %d
+Checking with incorrect parameter type
+
+Warning: imap_mail_copy() expects at least 3 parameters, 1 given in %s on line %d
+
+Warning: imap_mail_copy() expects at least 3 parameters, 1 given in %s on line %d
+Test with IMAP server
+
+Warning: imap_mail_copy() expects at least 3 parameters, 1 given in %s on line %d
+NULL
+
+Warning: imap_mail_copy() expects at least 3 parameters, 2 given in %s on line %d
+NULL
+
+Warning: imap_mail_copy() expects at least 3 parameters, 2 given in %s on line %d
+NULL
+===Done=== \ No newline at end of file
diff --git a/ext/imap/tests/imap_mail_copy_basic.phpt b/ext/imap/tests/imap_mail_copy_basic.phpt
new file mode 100644
index 0000000..a7b9421
--- /dev/null
+++ b/ext/imap/tests/imap_mail_copy_basic.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Test imap_mail_copy() function : basic functionality
+--CREDITS--
+Olivier Doucet
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : bool imap_mail_copy ( resource $imap_stream , string $msglist , string $mailbox [, int $options = 0 ] )
+ * Description: Copies mail messages specified by msglist to specified mailbox.
+ * Source code: ext/imap/php_imap.c
+ */
+
+echo "*** Testing imap_mail_copy() : 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";
+
+var_dump(imap_mail_copy($imap_stream, '1', 'INBOX.'.$mailbox_prefix));
+
+imap_close($imap_stream);
+?>
+===Done===
+--CLEAN--
+<?php
+require_once('clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_mail_copy() : 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
+bool(true)
+===Done=== \ No newline at end of file
diff --git a/ext/imap/tests/imap_mail_move.phpt b/ext/imap/tests/imap_mail_move.phpt
new file mode 100644
index 0000000..67ddea7
--- /dev/null
+++ b/ext/imap/tests/imap_mail_move.phpt
@@ -0,0 +1,54 @@
+--TEST--
+Test imap_mail_move() incorrect parameters
+--CREDITS--
+Olivier Doucet
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+echo "Checking with no parameters\n";
+imap_mail_move();
+
+
+echo "Checking with incorrect parameter type\n";
+imap_mail_move('');
+imap_mail_move(false);
+
+
+// more tests
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+
+echo "Test with IMAP server\n";
+$stream_id = imap_open($default_mailbox, $username, $password) or
+ die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
+
+var_dump(imap_mail_move($stream_id));
+var_dump(imap_mail_move($stream_id,-1));
+var_dump(imap_mail_move($stream_id, ''));
+
+imap_close($stream_id);
+?>
+===Done===
+--EXPECTF--
+Checking with no parameters
+
+Warning: imap_mail_move() expects at least 3 parameters, 0 given in %s on line %d
+Checking with incorrect parameter type
+
+Warning: imap_mail_move() expects at least 3 parameters, 1 given in %s on line %d
+
+Warning: imap_mail_move() expects at least 3 parameters, 1 given in %s on line %d
+Test with IMAP server
+
+Warning: imap_mail_move() expects at least 3 parameters, 1 given in %s on line %d
+NULL
+
+Warning: imap_mail_move() expects at least 3 parameters, 2 given in %s on line %d
+NULL
+
+Warning: imap_mail_move() expects at least 3 parameters, 2 given in %s on line %d
+NULL
+===Done=== \ No newline at end of file
diff --git a/ext/imap/tests/imap_mail_move_basic.phpt b/ext/imap/tests/imap_mail_move_basic.phpt
new file mode 100644
index 0000000..a543582
--- /dev/null
+++ b/ext/imap/tests/imap_mail_move_basic.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Test imap_mail_move() function : basic functionality
+--CREDITS--
+Olivier Doucet
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype : bool imap_mail_move ( resource $imap_stream , string $msglist , string $mailbox [, int $options = 0 ] )
+ * Description: Copies mail messages specified by msglist to specified mailbox.
+ * Source code: ext/imap/php_imap.c
+ */
+
+echo "*** Testing imap_mail_move() : 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";
+
+var_dump(imap_mail_move($imap_stream, '1', 'INBOX.'.$mailbox_prefix));
+
+imap_close($imap_stream);
+?>
+===Done===
+--CLEAN--
+<?php
+require_once('clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_mail_move() : 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
+bool(true)
+===Done=== \ No newline at end of file
diff --git a/ext/imap/tests/imap_mutf7_to_utf8.phpt b/ext/imap/tests/imap_mutf7_to_utf8.phpt
new file mode 100644
index 0000000..7a1a54a
--- /dev/null
+++ b/ext/imap/tests/imap_mutf7_to_utf8.phpt
@@ -0,0 +1,23 @@
+--TEST--
+imap_mutf7_to_utf8
+--SKIPIF--
+<?php if (!extension_loaded("imap")) print "skip"; ?>
+<?php if (!function_exists("imap_mutf7_to_utf8")) print "skip"; ?>
+--FILE--
+<?php
+
+var_dump(imap_mutf7_to_utf8(""));
+var_dump(imap_mutf7_to_utf8(1));
+var_dump(imap_mutf7_to_utf8(array(1,2)));
+var_dump(imap_mutf7_to_utf8("t&AOQ-st"));
+
+echo "Done\n";
+?>
+--EXPECTF--
+string(0) ""
+string(1) "1"
+
+Warning: imap_mutf7_to_utf8() expects parameter 1 to be string, array given in %s on line %d
+NULL
+string(5) "täst"
+Done
diff --git a/ext/imap/tests/imap_num_msg_error.phpt b/ext/imap/tests/imap_num_msg_error.phpt
new file mode 100644
index 0000000..6c4f50e
--- /dev/null
+++ b/ext/imap/tests/imap_num_msg_error.phpt
@@ -0,0 +1,28 @@
+--TEST--
+imap_num_msg() incorrect parameter count
+--CREDITS--
+Paul Sohier
+#phptestfest utrecht
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+echo "Checking with no parameters\n";
+imap_num_msg();
+
+echo "Checking with incorrect parameter type\n";
+imap_num_msg('');
+imap_num_msg(false);
+?>
+--EXPECTF--
+Checking with no parameters
+
+Warning: imap_num_msg() expects exactly 1 parameter, 0 given in %s on line %d
+Checking with incorrect parameter type
+
+Warning: imap_num_msg() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d
+
+Warning: imap_num_msg() expects parameter 1 to be resource, boolean given in %s on line %d
+
diff --git a/ext/imap/tests/imap_num_recent_error.phpt b/ext/imap/tests/imap_num_recent_error.phpt
new file mode 100644
index 0000000..e723473
--- /dev/null
+++ b/ext/imap/tests/imap_num_recent_error.phpt
@@ -0,0 +1,27 @@
+--TEST--
+imap_expunge() incorrect parameter count
+--CREDITS--
+Paul Sohier
+#phptestfest utrecht
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+echo "Checking with no parameters\n";
+imap_expunge();
+
+echo "Checking with incorrect parameter type\n";
+imap_expunge('');
+imap_expunge(false);
+?>
+--EXPECTF--
+Checking with no parameters
+
+Warning: imap_expunge() expects exactly 1 parameter, 0 given in %s on line %d
+Checking with incorrect parameter type
+
+Warning: imap_expunge() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d
+
+Warning: imap_expunge() expects parameter 1 to be resource, boolean given in %s on line %d
diff --git a/ext/imap/tests/imap_open_error.phpt b/ext/imap/tests/imap_open_error.phpt
new file mode 100644
index 0000000..83b0eba
--- /dev/null
+++ b/ext/imap/tests/imap_open_error.phpt
@@ -0,0 +1,47 @@
+--TEST--
+imap_open() incorrect parameter count
+--CREDITS--
+Paul Sohier
+#phptestfest utrecht
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+echo "Checking with no parameters\n";
+imap_open();
+imap_open(false);
+imap_open(false, false);
+imap_open('');
+imap_open('', '');
+
+echo "Checking with incorrect parameters\n" ;
+imap_open('', '', '');
+imap_open('', '', '', -1);
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+imap_open($default_mailbox, $username, $password, NIL, -1);
+
+?>
+--EXPECTF--
+Checking with no parameters
+
+Warning: imap_open() expects at least 3 parameters, 0 given in %s on line %d
+
+Warning: imap_open() expects at least 3 parameters, 1 given in %s on line %d
+
+Warning: imap_open() expects at least 3 parameters, 2 given in %s on line %d
+
+Warning: imap_open() expects at least 3 parameters, 1 given in %s on line %d
+
+Warning: imap_open() expects at least 3 parameters, 2 given in %s on line %d
+Checking with incorrect parameters
+
+Warning: imap_open(): Couldn't open stream in %s on line %d
+
+Warning: imap_open(): Couldn't open stream in %s on line %d
+
+Warning: imap_open(): Retries must be greater or equal to 0 in %s on line %d
+
+Notice: Unknown: Can't open mailbox : no such mailbox (errflg=2) in Unknown on line 0
diff --git a/ext/imap/tests/imap_ping_error.phpt b/ext/imap/tests/imap_ping_error.phpt
new file mode 100644
index 0000000..7c87867
--- /dev/null
+++ b/ext/imap/tests/imap_ping_error.phpt
@@ -0,0 +1,27 @@
+--TEST--
+imap_ping() incorrect parameter count
+--CREDITS--
+Paul Sohier
+#phptestfest utrecht
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+echo "Checking with no parameters\n";
+imap_ping();
+
+echo "Checking with incorrect parameter type\n";
+imap_ping('');
+imap_ping(false);
+?>
+--EXPECTF--
+Checking with no parameters
+
+Warning: imap_ping() expects exactly 1 parameter, 0 given in %s on line %d
+Checking with incorrect parameter type
+
+Warning: imap_ping() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d
+
+Warning: imap_ping() expects parameter 1 to be resource, boolean given in %s on line %d
diff --git a/ext/imap/tests/imap_renamemailbox_basic.phpt b/ext/imap/tests/imap_renamemailbox_basic.phpt
new file mode 100644
index 0000000..b445f1d
--- /dev/null
+++ b/ext/imap/tests/imap_renamemailbox_basic.phpt
@@ -0,0 +1,66 @@
+--TEST--
+imap_renamemailbox() function : basic functionality
+--CREDITS--
+Olivier Doucet
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+echo "Checking with no parameters\n";
+imap_renamemailbox();
+
+echo "Checking with incorrect parameter type\n";
+imap_renamemailbox('');
+imap_renamemailbox(false);
+
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+$stream_id = setup_test_mailbox('', 1);
+
+if (!is_resource($stream_id)) {
+ exit("TEST FAILED: Unable to create test mailbox\n");
+}
+
+$newbox = $default_mailbox . "." . $mailbox_prefix;
+
+imap_renamemailbox($stream_id, $newbox.'not');
+imap_renamemailbox($stream_id, $newbox);
+
+//commented because of bug #49901
+//$ancError = error_reporting(0);
+//$z = imap_renamemailbox($stream_id, $newbox.'not2', $newbox.'2');
+//var_dump($z);
+//error_reporting($ancError);
+echo "Checking OK\n";
+
+
+var_dump(imap_createmailbox($stream_id, $newbox.'.test'));
+var_dump(imap_renamemailbox($stream_id, $newbox.'.test', $newbox.'.testd'));
+
+imap_close($stream_id);
+?>
+--CLEAN--
+<?php
+require_once('clean.inc');
+?>
+--EXPECTF--
+Checking with no parameters
+
+Warning: imap_renamemailbox() expects exactly 3 parameters, 0 given in %s on line %d
+Checking with incorrect parameter type
+
+Warning: imap_renamemailbox() expects exactly 3 parameters, 1 given in %s on line %d
+
+Warning: imap_renamemailbox() expects exactly 3 parameters, 1 given in %s on line %d
+Create a temporary mailbox and add 1 msgs
+.. mailbox '{%s}%s' created
+
+Warning: imap_renamemailbox() expects exactly 3 parameters, 2 given in %s on line %d
+
+Warning: imap_renamemailbox() expects exactly 3 parameters, 2 given in %s on line %d
+Checking OK
+bool(true)
+bool(true)
diff --git a/ext/imap/tests/imap_rfc822_parse_headers_basic.phpt b/ext/imap/tests/imap_rfc822_parse_headers_basic.phpt
new file mode 100644
index 0000000..e425392
--- /dev/null
+++ b/ext/imap/tests/imap_rfc822_parse_headers_basic.phpt
@@ -0,0 +1,122 @@
+--TEST--
+imap_rfc822_parse_headers() function : basic functionality
+--CREDITS--
+Olivier Doucet
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+$stream_id = setup_test_mailbox('', 1);
+
+$z = imap_headerinfo($stream_id, 1);
+
+$fields = array ('toaddress','to','fromaddress','from',
+'reply_toaddress','reply_to',
+ 'senderaddress', 'sender',
+'subject','Subject',
+ 'MailDate','Size','udate');
+
+
+echo "Check general fields\n";
+foreach ($fields as $key) {
+ var_dump(isset($z->$key));
+}
+
+echo "Check type\n";
+var_dump($z->toaddress);
+var_dump($z->fromaddress);
+var_dump($z->reply_toaddress);
+var_dump($z->senderaddress);
+var_dump($z->subject);
+var_dump($z->Subject);
+
+if ($z->Recent == 'R' || $z->Recent == 'N' || $z->Recent == ' ') {
+ echo "Recent: OK";
+} else {
+ echo "Recent: error";
+}
+echo "\n";
+
+if ($z->Unseen == 'U' || $z->Unseen == ' ') {
+ echo "Unseen: OK";
+} else {
+ echo "Unseen: error";
+}
+echo "\n";
+
+if ($z->Flagged == 'F' || $z->Flagged == ' ') {
+ echo "Flagged: OK";
+} else {
+ echo "Flagged: error";
+}
+echo "\n";
+
+if ($z->Answered == 'A' || $z->Answered == ' ') {
+ echo "Answered: OK";
+} else {
+ echo "Answered: error";
+}
+echo "\n";
+
+if ($z->Deleted == 'D' || $z->Deleted == ' ') {
+ echo "Deleted: OK";
+} else {
+ echo "Deleted: error";
+}
+echo "\n";
+
+if ($z->Draft == 'X' || $z->Draft == ' ') {
+ echo "Draft: OK";
+} else {
+ echo "Draft: error";
+}
+echo "\n";
+
+var_dump($z->Msgno);
+var_dump($z->Size);
+var_dump($z->udate);
+
+imap_close($stream_id);
+
+?>
+--CLEAN--
+<?php
+require_once('clean.inc');
+?>
+--EXPECTF--
+Create a temporary mailbox and add 1 msgs
+.. mailbox '{%s}%s' created
+Check general fields
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Check type
+string(%d) "%s"
+string(%d) "%s"
+string(%d) "%s"
+string(%d) "%s"
+string(%d) "%s"
+string(%d) "%s"
+Recent: OK
+Unseen: OK
+Flagged: OK
+Answered: OK
+Deleted: OK
+Draft: OK
+string(%d) "%s"
+string(%d) "%d"
+int(%d) \ No newline at end of file
diff --git a/ext/imap/tests/imap_savebody_basic.phpt b/ext/imap/tests/imap_savebody_basic.phpt
new file mode 100644
index 0000000..91e6ce0
--- /dev/null
+++ b/ext/imap/tests/imap_savebody_basic.phpt
@@ -0,0 +1,61 @@
+--TEST--
+imap_savebody() function : basic functionality
+--CREDITS--
+Olivier Doucet
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+echo "Checking with no parameters\n";
+imap_savebody();
+
+echo "Checking with incorrect parameter type\n";
+imap_savebody('');
+imap_savebody(false);
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+$stream_id = setup_test_mailbox('', 1);
+
+imap_savebody($stream_id);
+
+$file = dirname(__FILE__).'/tmpsavebody.txt';
+
+//with URL
+$z = imap_savebody($stream_id, $file, 1);
+var_dump($z);
+echo "Size: ".filesize($file)."\n";
+
+//With FOPEN
+$fp = fopen($file, 'w');
+$z = imap_savebody($stream_id, $fp, 1);
+fclose($fp);
+var_dump($z);
+echo "Size: ".filesize($file)."\n";
+
+imap_close($stream_id);
+?>
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__).'/tmpsavebody.txt');
+require_once('clean.inc');
+?>
+--EXPECTF--
+Checking with no parameters
+
+Warning: imap_savebody() expects at least 3 parameters, 0 given in %s on line %d
+Checking with incorrect parameter type
+
+Warning: imap_savebody() expects at least 3 parameters, 1 given in %s on line %d
+
+Warning: imap_savebody() expects at least 3 parameters, 1 given in %s on line %d
+Create a temporary mailbox and add 1 msgs
+.. mailbox '{%s}%s' created
+
+Warning: imap_savebody() expects at least 3 parameters, 1 given in %s on line %d
+bool(true)
+Size: %d
+bool(true)
+Size: %d
+
diff --git a/ext/imap/tests/imap_timeout_basic.phpt b/ext/imap/tests/imap_timeout_basic.phpt
new file mode 100644
index 0000000..c2727e5
--- /dev/null
+++ b/ext/imap/tests/imap_timeout_basic.phpt
@@ -0,0 +1,60 @@
+--TEST--
+imap_timeout() function : basic functionality
+--CREDITS--
+Olivier Doucet
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+echo "Checking with no parameters\n";
+imap_timeout();
+
+echo "Checking with incorrect parameter type\n";
+imap_timeout('');
+imap_timeout(false);
+
+echo "GET values:\n";
+var_dump(imap_timeout(IMAP_OPENTIMEOUT));
+var_dump(imap_timeout(IMAP_READTIMEOUT));
+var_dump(imap_timeout(IMAP_WRITETIMEOUT));
+var_dump(imap_timeout(IMAP_CLOSETIMEOUT));
+
+echo "SET values:\n";
+var_dump(imap_timeout(IMAP_OPENTIMEOUT, 10));
+var_dump(imap_timeout(IMAP_READTIMEOUT, 10));
+var_dump(imap_timeout(IMAP_WRITETIMEOUT, 10));
+
+//IMAP_CLOSETIMEOUT not implemented
+//var_dump(imap_timeout(IMAP_CLOSETIMEOUT, 10));
+
+echo "CHECK values:\n";
+var_dump(imap_timeout(IMAP_OPENTIMEOUT));
+var_dump(imap_timeout(IMAP_READTIMEOUT));
+var_dump(imap_timeout(IMAP_WRITETIMEOUT));
+
+//IMAP_CLOSETIMEOUT not implemented
+//var_dump(imap_timeout(IMAP_CLOSETIMEOUT));
+
+?>
+--EXPECTF--
+Checking with no parameters
+
+Warning: imap_timeout() expects at least 1 parameter, 0 given in %s on line %d
+Checking with incorrect parameter type
+
+Warning: imap_timeout() expects parameter 1 to be long, %s given in %s on line %d
+GET values:
+int(%d)
+int(%d)
+int(%d)
+int(%d)
+SET values:
+bool(true)
+bool(true)
+bool(true)
+CHECK values:
+int(10)
+int(10)
+int(10)
diff --git a/ext/imap/tests/imap_undelete_basic.phpt b/ext/imap/tests/imap_undelete_basic.phpt
new file mode 100644
index 0000000..4b48b1b
--- /dev/null
+++ b/ext/imap/tests/imap_undelete_basic.phpt
@@ -0,0 +1,29 @@
+--TEST--
+imap_undelete() function : basic functionality
+--CREDITS--
+Olivier Doucet
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+$stream_id = setup_test_mailbox('', 1);
+
+imap_delete($stream_id, 1);
+
+var_dump(imap_undelete($stream_id, 1));
+
+imap_close($stream_id);
+
+?>
+--CLEAN--
+<?php
+require_once('clean.inc');
+?>
+--EXPECTF--
+Create a temporary mailbox and add 1 msgs
+.. mailbox '{%s}%s' created
+bool(true) \ No newline at end of file
diff --git a/ext/imap/tests/imap_undelete_error.phpt b/ext/imap/tests/imap_undelete_error.phpt
new file mode 100644
index 0000000..c82801e
--- /dev/null
+++ b/ext/imap/tests/imap_undelete_error.phpt
@@ -0,0 +1,36 @@
+--TEST--
+imap_undelete() incorrect parameter count
+--CREDITS--
+Olivier Doucet
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+echo "Checking with no parameters\n";
+imap_undelete();
+
+echo "Checking with incorrect parameter type\n";
+imap_undelete('');
+imap_undelete(false);
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+$stream_id = imap_open($default_mailbox, $username, $password) or
+ die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
+
+imap_undelete($stream_id);
+
+imap_close($stream_id);
+?>
+--EXPECTF--
+Checking with no parameters
+
+Warning: imap_undelete() expects at least 2 parameters, 0 given in %s on line %d
+Checking with incorrect parameter type
+
+Warning: imap_undelete() expects at least 2 parameters, 1 given in %s on line %d
+
+Warning: imap_undelete() expects at least 2 parameters, 1 given in %s on line %d
+
+Warning: imap_undelete() expects at least 2 parameters, 1 given in %s on line %d
diff --git a/ext/imap/tests/imap_utf8.phpt b/ext/imap/tests/imap_utf8.phpt
new file mode 100644
index 0000000..f701f82
--- /dev/null
+++ b/ext/imap/tests/imap_utf8.phpt
@@ -0,0 +1,22 @@
+--TEST--
+imap_utf8() tests
+--SKIPIF--
+<?php if (!extension_loaded("imap")) print "skip"; ?>
+--FILE--
+<?php
+
+var_dump(imap_utf8(""));
+var_dump(imap_utf8(1));
+var_dump(imap_utf8(array(1,2)));
+var_dump(imap_utf8("test"));
+
+echo "Done\n";
+?>
+--EXPECTF--
+string(0) ""
+string(1) "1"
+
+Warning: imap_utf8() expects parameter 1 to be string, array given in %s on line %d
+NULL
+string(4) "%s"
+Done
diff --git a/ext/imap/tests/imap_utf8_to_mutf7_basic.phpt b/ext/imap/tests/imap_utf8_to_mutf7_basic.phpt
new file mode 100644
index 0000000..54b43ef
--- /dev/null
+++ b/ext/imap/tests/imap_utf8_to_mutf7_basic.phpt
@@ -0,0 +1,23 @@
+--TEST--
+imap_utf8_to_mutf7
+--SKIPIF--
+<?php if (!extension_loaded("imap")) print "skip imap extension not loaded"; ?>
+<?php if (!function_exists("imap_utf8_to_mutf7")) print "skip imap_utf8_to_mutf7() not available"; ?>
+--FILE--
+<?php
+
+var_dump(imap_utf8_to_mutf7(""));
+var_dump(imap_utf8_to_mutf7(1));
+var_dump(imap_utf8_to_mutf7(array(1,2)));
+var_dump(imap_utf8_to_mutf7("täst"));
+
+echo "Done\n";
+?>
+--EXPECTF--
+string(0) ""
+string(1) "1"
+
+Warning: imap_utf8_to_mutf7() expects parameter 1 to be string, array given in %s on line %d
+NULL
+string(8) "t&AOQ-st"
+Done
diff --git a/ext/imap/tests/skipif.inc b/ext/imap/tests/skipif.inc
new file mode 100644
index 0000000..47bfd08
--- /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);
+?>