Modernize IMAP tests

Use constants when appropriate, drop some ouputs which depends on env vars

Enable parallel testing.

Closes GH-6380
This commit is contained in:
George Peter Banyard 2020-11-03 09:49:18 +00:00
parent e1cbfb38f6
commit 06ddda22fe
61 changed files with 431 additions and 383 deletions

View File

@ -42,6 +42,11 @@ steps:
snmp-mibs-downloader \
unixodbc-dev \
llvm \
libc-client-dev libkrb5-dev dovecot-core dovecot-pop3d dovecot-imapd \
libc-client-dev \
libkrb5-dev \
dovecot-core \
dovecot-pop3d \
dovecot-imapd \
sendmail \
${{ parameters.packages }}
displayName: 'APT'

View File

@ -20,8 +20,8 @@ steps:
set -e
sudo groupadd -g 5000 vmail
sudo useradd -m -d /var/vmail -s /bin/false -u 5000 -g vmail vmail
sudo cp ext/imap/tests/dovecot.conf /etc/dovecot/dovecot.conf
sudo cp ext/imap/tests/dovecotpass /etc/dovecot/dovecotpass
sudo cp ext/imap/tests/setup/dovecot.conf /etc/dovecot/dovecot.conf
sudo cp ext/imap/tests/setup/dovecotpass /etc/dovecot/dovecotpass
sudo service dovecot restart
displayName: 'Configure IMAP'

View File

@ -1 +0,0 @@
imap

View File

@ -11,14 +11,14 @@ hMailServer on Windows. The tests are intended to be mailserver agnostic.
## Set-up tests on Ubuntu (checked on Ubuntu 18.04 (Bionic))
The necessary packages can be installed using the following command;
`apt-get install libc-client-dev libkrb5-dev dovecot-core dovecot-pop3d dovecot-imapd`
`apt-get install libc-client-dev libkrb5-dev dovecot-core dovecot-pop3d dovecot-imapd sendmail`
The build of PHP will need to be compiled with the following flags:
```
--with-imap --with-kerberos --with-imap-ssl
```
Then run the set-up script `ext/imap/tests/setup.sh` which will add the `vmail`
Then run the set-up script `ext/imap/tests/setup/setup.sh` which will add the `vmail`
group and user which is used by Dovecot for the mailbox. It will also copy the
`ext/imap/tests/dovecot.conf` and `ext/imap/tests/dovecotpass` to the correct
`ext/imap/tests/setup/dovecot.conf` and `ext/imap/tests/setup/dovecotpass` to the correct
location for Dovecot and restarts it for the new configuration to be enabled.

View File

@ -2,9 +2,7 @@
Bug #31142 test #2 (imap_mail_compose() generates incorrect output)
--SKIPIF--
<?php
if (!extension_loaded("imap")) {
die("skip imap extension not available");
}
extension_loaded('imap') or die('skip imap extension not available in this build');
?>
--FILE--
<?php

View File

@ -2,9 +2,7 @@
Bug #32589 (crash inside imap_mail_compose() function)
--SKIPIF--
<?php
if (!extension_loaded("imap")) {
die("skip imap extension not available");
}
extension_loaded('imap') or die('skip imap extension not available in this build');
?>
--FILE--
<?php

View File

@ -2,9 +2,7 @@
Bug #35669 (imap_mail_compose() crashes with multipart-multiboundary-email)
--SKIPIF--
<?php
if (!extension_loaded("imap")) {
die("skip imap extension not available");
}
extension_loaded('imap') or die('skip imap extension not available in this build');
?>
--FILE--
<?php

View File

@ -2,19 +2,14 @@
Bug #44098 (imap_utf8() returns only capital letters)
--SKIPIF--
<?php
if (!extension_loaded("imap")) {
die("skip imap extension not available");
}
extension_loaded('imap') or die('skip imap extension not available in this build');
?>
--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";
}
var_dump($res);
?>
--EXPECT--
ok
string(17) "Luzon®14 dot CoM"

View File

@ -2,9 +2,7 @@
Bug #45705 test #1 (imap rfc822_parse_adrlist() modifies passed address parameter)
--SKIPIF--
<?php
if (!extension_loaded("imap")) {
die("skip imap extension not available");
}
extension_loaded('imap') or die('skip imap extension not available in this build');
?>
--FILE--
<?php

View File

@ -2,9 +2,7 @@
Bug #45705 test #2 (imap rfc822_parse_adrlist() modifies passed address parameter)
--SKIPIF--
<?php
if (!extension_loaded("imap")) {
die("skip imap extension not available");
}
extension_loaded('imap') or die('skip imap extension not available in this build');
?>
--FILE--
<?php

View File

@ -2,9 +2,7 @@
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");
}
extension_loaded('imap') or die('skip imap extension not available in this build');
?>
--FILE--
<?php

View File

@ -4,11 +4,11 @@ imap_open() DISABLE_AUTHENTICATOR ignores array param
<?php
extension_loaded('imap') or die('skip imap extension not available in this build');
require_once(__DIR__.'/imap_include.inc');
require_once(__DIR__. '/setup/imap_include.inc');
$in = @imap_open($default_mailbox, $username, $password, OP_HALFOPEN, 1);
$in = @imap_open(IMAP_SERVER_DEBUG, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD, OP_HALFOPEN, 1);
if (!$in) {
die("skip could not connect to mailbox $default_mailbox");
die("skip could not connect to mailbox " . IMAP_SERVER_DEBUG);
}
$kerberos = false;
if (is_array($errors = imap_errors())) {
@ -22,16 +22,19 @@ if (!$kerberos) {
die("skip need a GSSAPI/Kerberos aware server");
}
?>
--CONFLICTS--
defaultmailbox
--FILE--
<?php
// TODO Test Kerberos on CI
$tests = array(
'Array' => array('DISABLE_AUTHENTICATOR' => array('GSSAPI','NTLM')),
'String' => array('DISABLE_AUTHENTICATOR' => 'GSSAPI'),
);
require_once(__DIR__.'/imap_include.inc');
require_once(__DIR__. '/setup/imap_include.inc');
foreach ($tests as $name => $testparams) {
echo "Test for $name\n";
$in = imap_open($default_mailbox, $username, $password, OP_HALFOPEN, 1, $testparams);
$in = imap_open(IMAP_SERVER_DEBUG, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD, OP_HALFOPEN, 1, $testparams);
if ($in) {
if (is_array($errors = imap_errors())) {
foreach ($errors as $err) {

View File

@ -2,22 +2,23 @@
Bug #64076 (imap_sort() does not return FALSE on failure)
--SKIPIF--
<?php
require_once __DIR__ . '/skipif.inc';
require_once __DIR__ . '/setup/skipif.inc';
?>
--FILE--
<?php
require_once __DIR__ . '/imap_include.inc';
$stream = setup_test_mailbox('', 2);
require_once __DIR__ . '/setup/imap_include.inc';
$stream = setup_test_mailbox('bug64076', 2);
imap_errors(); // clear error stack
var_dump(imap_sort($stream, SORTFROM, 0, 0, 'UNSUPPORTED SEARCH CRITERIUM'));
var_dump(imap_errors() !== false);
?>
--CLEAN--
<?php
require_once __DIR__ . '/clean.inc';
$mailbox_suffix = 'bug64076';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 2 msgs
.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created
New mailbox created
bool(false)
bool(true)

View File

@ -6,8 +6,8 @@ if (!extension_loaded('imap')) die('skip imap extension not available');
?>
--FILE--
<?php
imap_mail('1', 1, NULL);
@imap_mail('1', 1, NULL);
echo 'done'
?>
--EXPECTF--
Warning: imap_mail(): No message string in mail command in %s on line %d
%S
%Adone

View File

@ -1,10 +1,8 @@
--TEST--
--TEST--
Bug #77153 (imap_open allows to run arbitrary shell commands via mailbox parameter)
--SKIPIF--
<?php
if (!extension_loaded("imap")) {
die("skip imap extension not available");
}
extension_loaded('imap') or die('skip imap extension not available in this build');
?>
--FILE--
<?php
@ -21,4 +19,4 @@ bool(false)
--CLEAN--
<?php
if(file_exists(__DIR__ . '/__bug')) unlink(__DIR__ . '/__bug');
?>
?>

View File

@ -14,8 +14,13 @@ $body = [[
'type.parameters' => ['param'],
'disposition' => ['disp'],
]];
imap_mail_compose($envelope, $body);
var_dump(imap_mail_compose($envelope, $body));
echo "done\n";
?>
--EXPECT--
string(67) "MIME-Version: 1.0
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
"
done

View File

@ -2,12 +2,16 @@
Bug #80226 (imap_sort() leaks sortpgm memory)
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--CONFLICTS--
defaultmailbox
--FILE--
<?php
require_once(__DIR__.'/imap_include.inc');
$stream = imap_open($default_mailbox, $username, $password);
imap_sort($stream, SORTFROM, 0);
require_once(__DIR__.'/setup/imap_include.inc');
$stream = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);
var_dump(imap_sort($stream, SORTFROM, 0));
?>
--EXPECT--
array(0) {
}

View File

@ -1,25 +0,0 @@
<?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);
?>

View File

@ -2,22 +2,19 @@
Test imap_append() function : basic functionality
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__. '/setup/skipif.inc');
?>
--FILE--
<?php
echo "*** Testing imap_append() : basic functionality ***\n";
require_once(__DIR__.'/imap_include.inc');
require_once(__DIR__. '/setup/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");
}
$imap_stream = setup_test_mailbox("imapappendbaisc", 0);
$mb_details = imap_mailboxmsginfo($imap_stream);
echo "Add a couple of msgs to new mailbox " . $mb_details->Mailbox . "\n";
echo "Add a couple of msgs to the new mailbox\n";
var_dump(imap_append($imap_stream, $mb_details->Mailbox
, "From: webmaster@something.com\r\n"
. "To: info@something.com\r\n"
@ -44,14 +41,15 @@ imap_close($imap_stream);
?>
--CLEAN--
<?php
require_once('clean.inc');
$mailbox_suffix = 'imapappendbaisc';
require_once(__DIR__ . '/setup/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
New mailbox created
Add a couple of msgs to the new mailbox
bool(true)
bool(true)
Msg Count after append : 2

View File

@ -5,14 +5,17 @@ Paul Sohier
#phptestfest utrecht
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--CONFLICTS--
# Might not be needed
defaultmailbox
--FILE--
<?php
require_once(__DIR__.'/imap_include.inc');
$stream_id = imap_open($default_mailbox, $username, $password) or
die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = imap_open(IMAP_SERVER, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD) or
die("Cannot connect to mailbox ". IMAP_SERVER. ": " . imap_last_error());
try {
imap_body($stream_id,-1);

View File

@ -2,16 +2,16 @@
Test imap_body() function : basic functionality
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
echo "*** Testing imap_body() : basic functionality ***\n";
require_once(__DIR__.'/imap_include.inc');
require_once(__DIR__.'/setup/imap_include.inc');
echo "Create a new mailbox for test\n";
$imap_stream = setup_test_mailbox("", 1);
$imap_stream = setup_test_mailbox("imapbodybasic", 1);
if (!is_resource($imap_stream)) {
exit("TEST FAILED: Unable to create test mailbox\n");
}
@ -29,15 +29,16 @@ imap_close($imap_stream);
?>
--CLEAN--
<?php
require_once('clean.inc');
$mailbox_suffix = 'imapbodybasic';
require_once __DIR__.'/setup/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
New mailbox created
Msg Count in new mailbox: 1
string(%d) "1: this is a test message, please ignore
"
newline%r\R?%r"
string(%d) "1: this is a test message, please ignore
"
newline%r\R?%r"

View File

@ -2,15 +2,15 @@
Test imap_bodystruct() function : basic functionality
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
echo "*** Testing string imap_bodystruct : basic functionality ***\n";
require_once(__DIR__.'/imap_include.inc');
require_once(__DIR__.'/setup/imap_include.inc');
echo "Create a new mailbox for test and add a multipart msgs\n";
$imap_stream = setup_test_mailbox("", 1, $mailbox, "multipart");
$imap_stream = setup_test_mailbox("imapbodystructbasic", 1, $mailbox, "multipart");
if (!is_resource($imap_stream)) {
exit("TEST FAILED: Unable to create test mailbox\n");
}
@ -65,13 +65,14 @@ return $result;
?>
--CLEAN--
<?php
require_once('clean.inc');
$mailbox_suffix = 'imapbodystructbasic';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECTF--
--EXPECT--
*** Testing string imap_bodystruct : basic functionality ***
Create a new mailbox for test and add a multipart msgs
Create a temporary mailbox and add 1 msgs
.. mailbox '{%s}%s' created
New mailbox created
Get and validate structure of body part 1
ifsubtype is 0 or 1

View File

@ -2,16 +2,16 @@
Test imap_clearflag_full() function : basic functionality
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
echo "*** Testing imap_clearflag_full() : basic functionality ***\n";
require_once(__DIR__.'/imap_include.inc');
require_once(__DIR__.'/setup/imap_include.inc');
echo "Create a new mailbox for test\n";
$imap_stream = setup_test_mailbox("", 10);
$imap_stream = setup_test_mailbox("imapclearflagfullbasic", 10);
if (!is_resource($imap_stream)) {
exit("TEST FAILED: Unable to create test mailbox\n");
}
@ -44,13 +44,14 @@ imap_close($imap_stream);
?>
--CLEAN--
<?php
require_once('clean.inc');
$mailbox_suffix = 'imapclearflagfullbasic';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECTF--
--EXPECT--
*** Testing imap_clearflag_full() : basic functionality ***
Create a new mailbox for test
Create a temporary mailbox and add 10 msgs
.. mailbox '{%s}%s' created
New mailbox created
Initial msg count in new_mailbox : 10
Set some flags
bool(true)

View File

@ -2,17 +2,17 @@
Test imap_close() function : basic functionality
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
echo "*** Testing imap_close() : basic functionality ***\n";
// include file for required variables in imap_open()
require_once(__DIR__.'/imap_include.inc');
require_once(__DIR__.'/setup/imap_include.inc');
// Initialize required variables
$stream_id = setup_test_mailbox('', 3, $mailbox); // set up temp mailbox with 3 messages
$stream_id = setup_test_mailbox('imapclosebasic', 3, $mailbox); // set up temp mailbox with 3 messages
$options = CL_EXPUNGE;
// mark messages in inbox for deletion
@ -25,7 +25,7 @@ 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);
$stream_id = imap_open($mailbox, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);
echo "There are now " . imap_num_msg($stream_id) . " msgs in mailbox '$mailbox'\n";
// Calling imap_close() with mandatory arguments
@ -34,16 +34,17 @@ var_dump( imap_close($stream_id) );
?>
--CLEAN--
<?php
require_once(__DIR__.'/clean.inc');
$mailbox_suffix = 'imapclosebasic';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
*** Testing imap_close() : basic functionality ***
Create a temporary mailbox and add 3 msgs
.. mailbox '%sINBOX.phpttest' created
New mailbox created
-- Call to imap_close() with all possible arguments --
bool(true)
There are now 0 msgs in mailbox '%sINBOX.phpttest'
There are now 0 msgs in mailbox '%sINBOX.phpttestimapclosebasic'
-- Call to imap_close() with mandatory arguments --
bool(true)

View File

@ -2,8 +2,11 @@
Test imap_close() function : usage variations - different ints as $flags arg
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--CONFLICTS--
# It should be possible to use a custom mailbox instead of conflicting with the default one
defaultmailbox
--FILE--
<?php
/*
@ -13,11 +16,11 @@ require_once(__DIR__.'/skipif.inc');
echo "*** Testing imap_close() : usage variations ***\n";
require_once(__DIR__.'/imap_include.inc');
require_once(__DIR__.'/setup/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
$stream_id = setup_test_mailbox('imapclosevar4', 3, $mailbox); // set up temp mailbox with 3 messages
// loop through each element of $inputs to check the behavior of imap_close()
$iterator = 1;
@ -40,7 +43,7 @@ foreach($inputs as $input) {
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);
$imap_stream = imap_open($mailbox, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);
$num_msg = imap_num_msg($imap_stream);
if ($num_msg != 0) {
echo "CL_EXPUNGE was not set, $num_msg msgs in mailbox\n";
@ -53,19 +56,20 @@ foreach($inputs as $input) {
$iterator++;
// get $stream_id for next iteration
$stream_id = imap_open($mailbox, $username, $password);
$stream_id = imap_open($mailbox, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);
populate_mailbox($stream_id, $mailbox, 3);
};
?>
--CLEAN--
<?php
require_once(__DIR__.'/clean.inc');
$mailbox_suffix = 'imapclosevar4';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
--EXPECT--
*** Testing imap_close() : usage variations ***
Create a temporary mailbox and add 3 msgs
.. mailbox '{%s}%s' created
New mailbox created
-- Iteration 1 --
bool(true)

View File

@ -2,22 +2,24 @@
Test imap_createmailbox() function : basic functionality
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once __DIR__.'/setup/skipif.inc';
?>
--CONFLICTS--
defaultmailbox
--FILE--
<?php
echo "*** Testing imap_createmailbox() : basic functionality ***\n";
require_once(__DIR__.'/imap_include.inc');
require_once __DIR__.'/setup/imap_include.inc';
$imap_stream = imap_open($default_mailbox, $username, $password) or
die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
$imap_stream = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD) or
die("Cannot connect to mailbox ". IMAP_DEFAULT_MAILBOX. ": " . imap_last_error());
$newname = "phpnewbox";
echo "Newname will be '$newname'\n";
$newbox = imap_utf7_encode($server.$newname);
$newbox = imap_utf7_encode(IMAP_SERVER.$newname);
if (imap_createmailbox($imap_stream, $newbox)) {
echo "Add a couple of msgs to '$newname' mailbox\n";
@ -48,6 +50,11 @@ if (imap_createmailbox($imap_stream, $newbox)) {
imap_close($imap_stream);
?>
--CLEAN--
<?php
$mailbox_suffix = '';
require_once __DIR__ . '/setup/clean.inc';
?>
--EXPECTF--
*** Testing imap_createmailbox() : basic functionality ***

View File

@ -2,16 +2,16 @@
Test imap_errors() function : invalid password
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once __DIR__.'/setup/skipif.inc';
?>
--FILE--
<?php
echo "*** Testing imap_errors() : invalid password ***\n";
require_once(__DIR__.'/imap_include.inc');
require_once __DIR__.'/setup/imap_include.inc';
$password = "bogus"; // invalid password to use in this test
echo "Issue opening with invalid password, 1 retry\n";
$mbox = imap_open($default_mailbox, $username, $password, OP_READONLY, 1);
$mbox = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, $password, OP_READONLY, 1);
echo "List any errors\n";
var_dump(imap_errors());

View File

@ -2,16 +2,18 @@
Test imap_fetch_overview() function : basic functionality
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--CONFLICTS--
defaultmailbox
--FILE--
<?php
echo "*** Testing imap_fetch_overview() : basic functionality ***\n";
require_once(__DIR__.'/imap_include.inc');
require_once __DIR__.'/setup/imap_include.inc';
// create a new mailbox and add two new messages to it
$stream_id = setup_test_mailbox('', 2, $mailbox, 'notSimple');
$stream_id = setup_test_mailbox('', 2, $mailbox, false);
// get UID for new message
$msg_no = imap_uid($stream_id, 1);
@ -40,12 +42,13 @@ imap_close($stream_id);
?>
--CLEAN--
<?php
require_once(__DIR__.'/clean.inc');
$mailbox_suffix = '';
require_once __DIR__.'/setup/clean.inc';
?>
--EXPECTF--
*** Testing imap_fetch_overview() : basic functionality ***
Create a temporary mailbox and add 2 msgs
.. mailbox '{%s}%s' created
New mailbox created
-- All possible arguments --

View File

@ -2,8 +2,10 @@
Test imap_fetch_overview() function : usage variations - FT_UID option
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--CONFLICTS--
defaultmailbox
--FILE--
<?php
/*
@ -14,19 +16,20 @@ require_once(__DIR__.'/skipif.inc');
echo "*** Testing imap_fetch_overview() : usage variations ***\n";
require_once(__DIR__.'/imap_include.inc');
require_once __DIR__.'/setup/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);
$flags = array ('1',
true,
1.000000000000001,
0.00001e5,
245
);
$flags = [
'1',
true,
1.000000000000001,
0.00001e5,
245,
];
imap_check($stream_id);
foreach($flags as $option) {
@ -45,12 +48,13 @@ foreach($flags as $option) {
?>
--CLEAN--
<?php
require_once(__DIR__.'/clean.inc');
$mailbox_suffix = '';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
--EXPECT--
*** Testing imap_fetch_overview() : usage variations ***
Create a temporary mailbox and add 1 msgs
.. mailbox '{%s}%s' created
New mailbox created
Testing with option value:string(1) "1"
imap_fetch_overview() returns an object

View File

@ -2,8 +2,10 @@
Test imap_fetch_overview() function : usage variations - $msg_no argument
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--CONFLICTS--
defaultmailbox
--FILE--
<?php
/*
@ -12,25 +14,31 @@ require_once(__DIR__.'/skipif.inc');
*/
echo "*** Testing imap_fetch_overview() : usage variations ***\n";
require_once(__DIR__.'/imap_include.inc');
require_once __DIR__.'/setup/imap_include.inc';
$stream_id = setup_test_mailbox('', 3, $mailbox, 'notSimple'); // set up temp mailbox with 3 msgs
$stream_id = setup_test_mailbox('', 3, $mailbox, false); // 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
$sequences = [
0,
4, // out of range
'4', // out of range
'2',
'1,3',
'1, 2',
'1:3', // pass uid without setting FT_UID option
];
foreach($sequences as $msg_no) {
foreach ($sequences as $msg_no) {
echo "\n-- \$msg_no is $msg_no --\n";
$overview = imap_fetch_overview($stream_id, $msg_no);
$overview = imap_fetch_overview($stream_id, $msg_no);
if (!$overview) {
echo imap_last_error() . "\n";
} else {
} else {
foreach($overview as $ov) {
echo "\n";
displayOverviewFields($ov);
}
}
}
}
// clear error stack
@ -38,12 +46,13 @@ imap_errors();
?>
--CLEAN--
<?php
require_once(__DIR__.'/clean.inc');
$mailbox_suffix = '';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
*** Testing imap_fetch_overview() : usage variations ***
Create a temporary mailbox and add 3 msgs
.. mailbox '{%s}%s' created
New mailbox created
-- $msg_no is 0 --
Sequence out of range

View File

@ -2,8 +2,10 @@
Test imap_fetch_overview() function : usage variations - multipart message
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--CONFLICTS--
defaultmailbox
--FILE--
<?php
/*
@ -12,7 +14,7 @@ require_once(__DIR__.'/skipif.inc');
echo "*** Testing imap_fetch_overview() : usage variations ***\n";
require_once(__DIR__.'/imap_include.inc');
require_once __DIR__.'/setup/imap_include.inc';
$stream_id = setup_test_mailbox('', 0, $mailbox); // setup temp mailbox
create_multipart_message($stream_id, $mailbox);
@ -37,7 +39,7 @@ displayOverviewFields($a[0]);
function create_multipart_message($imap_stream, $mailbox) {
global $users, $domain;
$envelope["from"]= "foo@anywhere.com";
$envelope["to"] = "$users[0]@$domain";
$envelope["to"] = IMAP_USERS[0] . '@' . IMAP_MAIL_DOMAIN;
$envelope["subject"] = "Test msg 1";
$part1["type"] = TYPEMULTIPART;
@ -82,12 +84,13 @@ function create_multipart_message($imap_stream, $mailbox) {
?>
--CLEAN--
<?php
require_once(__DIR__.'/clean.inc');
$mailbox_suffix = '';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
*** Testing imap_fetch_overview() : usage variations ***
Create a temporary mailbox and add 0 msgs
.. mailbox '{%s}%s' created
New mailbox created
--> Object #1
size is %d

View File

@ -2,8 +2,10 @@
Test imap_fetchbody() function : basic functionality
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--CONFLICTS--
defaultmailbox
--FILE--
<?php
/* [, int $options])
@ -12,12 +14,12 @@ require_once(__DIR__.'/skipif.inc');
*/
echo "*** Testing imap_fetchbody() : basic functionality ***\n";
require_once(__DIR__.'/imap_include.inc');
require_once(__DIR__.'/setup/imap_include.inc');
// Initialise all required variables
// set up mailbox with one message
$stream_id = setup_test_mailbox('', 1, $mailbox, 'notSimple');
$stream_id = setup_test_mailbox('', 1, $mailbox, false);
$msg_no = 1;
$section = '2';
@ -57,12 +59,13 @@ var_dump( $overview[0]->seen );
?>
--CLEAN--
<?php
require_once(__DIR__.'/clean.inc');
$mailbox_suffix = '';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
*** Testing imap_fetchbody() : basic functionality ***
Create a temporary mailbox and add 1 msgs
.. mailbox '{%s}%s' created
New mailbox created
-- All possible arguments --
-- Option is FT_UID --

View File

@ -2,7 +2,7 @@
Test imap_fetchbody() function : usage variations - FT_UID option
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
@ -13,10 +13,10 @@ require_once(__DIR__.'/skipif.inc');
*/
echo "*** Testing imap_fetchbody() : usage variations ***\n";
require_once(__DIR__.'/imap_include.inc');
require_once(__DIR__.'/setup/imap_include.inc');
// Initialise required variables
$stream_id = setup_test_mailbox('', 1); // set up temporary mailbox with one simple message
$stream_id = setup_test_mailbox('imapfetchbodyvar4', 1); // set up temporary mailbox with one simple message
$msg_no = 1;
$msg_uid = imap_uid($stream_id, $msg_no);
$section = 1;
@ -47,12 +47,13 @@ foreach($flags as $option) {
?>
--CLEAN--
<?php
require_once(__DIR__.'/clean.inc');
$mailbox_suffix = 'imapfetchbodyvar4';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
--EXPECT--
*** Testing imap_fetchbody() : usage variations ***
Create a temporary mailbox and add 1 msgs
.. mailbox '{%s}%s' created
New mailbox created
-- Iteration 1 --
FT_UID valid

View File

@ -2,7 +2,7 @@
Test imap_fetchbody() function : usage variations - $message_num arg
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
@ -13,10 +13,10 @@ require_once(__DIR__.'/skipif.inc');
echo "*** Testing imap_fetchbody() : usage variations ***\n";
require_once(__DIR__.'/imap_include.inc');
require_once(__DIR__.'/setup/imap_include.inc');
//Initialise required variables
$stream_id = setup_test_mailbox('', 3); // set up temp mailbox with simple msgs
$stream_id = setup_test_mailbox('imapfetchbodyvar6', 3); // set up temp mailbox with simple msgs
$section = 1;
$sequences = [0, /* out of range */ 4, 1];
@ -32,12 +32,13 @@ foreach($sequences as $message_num) {
?>
--CLEAN--
<?php
require_once(__DIR__.'/clean.inc');
$mailbox_suffix = 'imapfetchbodyvar6';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
*** Testing imap_fetchbody() : usage variations ***
Create a temporary mailbox and add 3 msgs
.. mailbox '{%s}%s' created
New mailbox created
-- $message_num is 0 --
imap_fetchbody(): Argument #2 ($message_num) must be greater than 0
@ -48,5 +49,5 @@ Warning: imap_fetchbody(): Bad message number in %s on line %d
bool(false)
-- $message_num is 1 --
string(%s) "1: this is a test message, please ignore
%A"
string(%d) "1: this is a test message, please ignore
newline%r\R?%r"

View File

@ -2,15 +2,15 @@
Test imap_fetchheader() function : basic function
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
echo "*** Testing imap_fetchheader() : basic functionality ***\n";
require_once(__DIR__.'/imap_include.inc');
require_once(__DIR__.'/setup/imap_include.inc');
// Initialise all required variables
$stream_id = setup_test_mailbox('', 1, $mailbox, 'multiPart'); // setup temp mailbox with 1 msg
$stream_id = setup_test_mailbox('imapfetchheaderbasic', 1, $mailbox, false); // setup temp mailbox with 1 msg
$msg_no = 1;
$options = array('FT_UID' => FT_UID, 'FT_INTERNAL' => FT_INTERNAL,
'FT_PREFETCHTEXT' => FT_PREFETCHTEXT);
@ -33,12 +33,13 @@ var_dump( imap_fetchheader($stream_id, $msg_no) );
?>
--CLEAN--
<?php
require_once(__DIR__.'/clean.inc');
$mailbox_suffix = 'imapfetchheaderbasic';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
*** Testing imap_fetchheader() : basic functionality ***
Create a temporary mailbox and add 1 msgs
.. mailbox '%s.phpttest' created
New mailbox created
-- All possible arguments --
-- Option is FT_UID --

View File

@ -2,7 +2,7 @@
Test imap_fetchheader() function : usage variations - FT_UID option
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
@ -14,10 +14,10 @@ require_once(__DIR__.'/skipif.inc');
echo "*** Testing imap_fetchheader() : usage variations ***\n";
require_once(__DIR__.'/imap_include.inc');
require_once(__DIR__.'/setup/imap_include.inc');
// Initialise required variables
$stream_id = setup_test_mailbox('', 1); // set up temporary mailbox with one simple message
$stream_id = setup_test_mailbox('imapfetchheadervar3', 1); // set up temporary mailbox with one simple message
$msg_no = 1;
$msg_uid = imap_uid($stream_id, $msg_no);
@ -44,12 +44,13 @@ foreach($flags as $option) {
?>
--CLEAN--
<?php
require_once(__DIR__.'/clean.inc');
$mailbox_suffix = 'imapfetchheadervar3';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECTF--
--EXPECT--
*** Testing imap_fetchheader() : usage variations ***
Create a temporary mailbox and add 1 msgs
.. mailbox '{%s}%s' created
New mailbox created
-- Iteration 1 --
FT_UID valid

View File

@ -2,7 +2,7 @@
Test imap_fetchheader() function : usage variations - $message_num argument
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
@ -13,9 +13,9 @@ require_once(__DIR__.'/skipif.inc');
echo "*** Testing imap_fetchheader() : usage variations ***\n";
require_once(__DIR__.'/imap_include.inc');
require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = setup_test_mailbox('', 3, $mailbox, 'notSimple'); // set up temp mailbox with 3 msgs
$stream_id = setup_test_mailbox('imapfetchheadervar5', 3, $mailbox, false); // set up temp mailbox with 3 msgs
$sequences = [0, /* out of range */ 4, 1];
@ -33,12 +33,13 @@ imap_errors();
?>
--CLEAN--
<?php
require_once(__DIR__.'/clean.inc');
$mailbox_suffix = 'imapfetchheadervar5';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
*** Testing imap_fetchheader() : usage variations ***
Create a temporary mailbox and add 3 msgs
.. mailbox '{%s}%s' created
New mailbox created
-- $message_num is 0 --
imap_fetchheader(): Argument #2 ($message_num) must be greater than 0

View File

@ -4,13 +4,13 @@ imap_fetchstructure() function : basic functionality
Olivier Doucet
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
require_once(__DIR__.'/imap_include.inc');
$stream_id = setup_test_mailbox('', 1);
require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = setup_test_mailbox('imapfetchstructurebasic', 1);
try {
imap_fetchstructure($stream_id,0);
@ -38,11 +38,12 @@ imap_close($stream_id);
?>
--CLEAN--
<?php
require_once('clean.inc');
$mailbox_suffix = 'imapfetchstructurebasic';
require_once('setup/clean.inc');
?>
--EXPECTF--
Create a temporary mailbox and add 1 msgs
.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created
New mailbox created
imap_fetchstructure(): Argument #2 ($message_num) must be greater than 0
bool(true)
bool(true)

View File

@ -1,18 +1,18 @@
--TEST--
imap_gc() incorrect parameter count
imap_gc() ValueError
--CREDITS--
Paul Sohier
#phptestfest utrecht
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
require_once(__DIR__.'/imap_include.inc');
$stream_id = imap_open($default_mailbox, $username, $password) or
die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD) or
die("Cannot connect to mailbox ". IMAP_DEFAULT_MAILBOX .": " . imap_last_error());
try {
imap_gc($stream_id, -1);

View File

@ -4,27 +4,29 @@ imap_getsubscribed() function : basic functionality
Olivier Doucet
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
if (getenv("SKIP_ASAN")) die("skip asan chokes on this: 'LeakSanitizer does not work under ptrace (strace, gdb, etc)'");
?>
--CONFLICTS--
defaultmailbox
--FILE--
<?php
require_once(__DIR__.'/imap_include.inc');
$stream_id = imap_open($default_mailbox, $username, $password) or
die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD) or
die("Cannot connect to mailbox ". IMAP_DEFAULT_MAILBOX. ": " . imap_last_error());
var_dump(imap_getsubscribed($stream_id,$default_mailbox,'ezDvfXvbvcxSerz'));
var_dump(imap_getsubscribed($stream_id, IMAP_DEFAULT_MAILBOX, 'ezDvfXvbvcxSerz'));
echo "Checking OK\n";
$newbox = $default_mailbox . "." . $mailbox_prefix;
$newbox = IMAP_DEFAULT_MAILBOX . "." . IMAP_MAILBOX_PHPT_PREFIX;
imap_createmailbox($stream_id, $newbox);
imap_subscribe($stream_id, $newbox);
$z = imap_getsubscribed($stream_id,$default_mailbox,'*');
$z = imap_getsubscribed($stream_id, IMAP_DEFAULT_MAILBOX, '*');
var_dump(is_array($z));
var_dump($z[0]);
@ -33,7 +35,8 @@ imap_close($stream_id);
?>
--CLEAN--
<?php
require_once('clean.inc');
$mailbox_suffix = '';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECTF--
bool(false)

View File

@ -4,13 +4,13 @@ imap_headerinfo() function : basic functionality
Olivier Doucet
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
require_once(__DIR__.'/imap_include.inc');
$stream_id = setup_test_mailbox('', 1);
require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = setup_test_mailbox('imapheaderinfobasic', 1);
$z = imap_headerinfo($stream_id, 1);
@ -85,11 +85,12 @@ imap_close($stream_id);
?>
--CLEAN--
<?php
require_once('clean.inc');
$mailbox_suffix = 'imapheaderinfobasic';
require_once('setup/clean.inc');
?>
--EXPECTF--
Create a temporary mailbox and add 1 msgs
.. mailbox '{%s}%s' created
New mailbox created
Check general fields
bool(true)
bool(true)

View File

@ -4,20 +4,22 @@ imap_list() function : basic functionality
Olivier Doucet
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
require_once(__DIR__.'/imap_include.inc');
$stream_id = imap_open($default_mailbox, $username, $password) or
die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD) or
die("Cannot connect to mailbox " .IMAP_DEFAULT_MAILBOX.": " . imap_last_error());
imap_list($stream_id,$default_mailbox,'ezerz');
imap_list($stream_id, IMAP_DEFAULT_MAILBOX,'ezerz');
$z = imap_list($stream_id,$default_mailbox,'*');
$z = imap_list($stream_id, IMAP_DEFAULT_MAILBOX,'*');
var_dump(is_array($z));
// e.g. "{127.0.0.1:143/norsh}INBOX"
var_dump($z[0]);
imap_close($stream_id);

View File

@ -4,36 +4,41 @@ imap_lsub() function : basic functionality
Olivier Doucet
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
if (getenv("SKIP_ASAN")) die("skip leak sanitizer crashes");
?>
--CONFLICTS--
defaultmailbox
--FILE--
<?php
require_once(__DIR__.'/imap_include.inc');
$stream_id = imap_open($default_mailbox, $username, $password) or
die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD) or
die("Cannot connect to mailbox " .IMAP_DEFAULT_MAILBOX. ": " . imap_last_error());
var_dump(imap_lsub($stream_id,$default_mailbox,'ezDvfXvbvcxSerz'));
var_dump(imap_lsub($stream_id, IMAP_DEFAULT_MAILBOX, 'ezDvfXvbvcxSerz'));
echo "Checking OK\n";
$newbox = $default_mailbox . "." . $mailbox_prefix;
$newbox = IMAP_DEFAULT_MAILBOX . "." . IMAP_MAILBOX_PHPT_PREFIX;
imap_createmailbox($stream_id, $newbox);
imap_subscribe($stream_id, $newbox);
$z = imap_lsub($stream_id,$default_mailbox,'*');
$z = imap_lsub($stream_id, IMAP_DEFAULT_MAILBOX, '*');
var_dump(is_array($z));
// e.g. "{127.0.0.1:143/norsh}INBOX.phpttest"
var_dump($z[0]);
imap_close($stream_id);
?>
--CLEAN--
<?php
require_once('clean.inc');
$mailbox_suffix = '';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
bool(false)

View File

@ -4,13 +4,15 @@ Test imap_mail_copy() function : basic functionality
Olivier Doucet
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--CONFLICTS--
defaultmailbox
--FILE--
<?php
echo "*** Testing imap_mail_copy() : basic functionality ***\n";
require_once(__DIR__.'/imap_include.inc');
require_once(__DIR__.'/setup/imap_include.inc');
echo "Create a new mailbox for test\n";
@ -22,18 +24,19 @@ if (!is_resource($imap_stream)) {
$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));
var_dump(imap_mail_copy($imap_stream, '1', 'INBOX.'.IMAP_MAILBOX_PHPT_PREFIX));
imap_close($imap_stream);
?>
--CLEAN--
<?php
require_once('clean.inc');
$mailbox_suffix = '';
require_once('setup/clean.inc');
?>
--EXPECTF--
--EXPECT--
*** Testing imap_mail_copy() : basic functionality ***
Create a new mailbox for test
Create a temporary mailbox and add 1 msgs
.. mailbox '%s' created
New mailbox created
Msg Count in new mailbox: 1
bool(true)

View File

@ -4,13 +4,15 @@ Test imap_mail_move() function : basic functionality
Olivier Doucet
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--CONFLICTS--
defaultmailbox
--FILE--
<?php
echo "*** Testing imap_mail_move() : basic functionality ***\n";
require_once(__DIR__.'/imap_include.inc');
require_once(__DIR__.'/setup/imap_include.inc');
echo "Create a new mailbox for test\n";
@ -22,18 +24,19 @@ if (!is_resource($imap_stream)) {
$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));
var_dump(imap_mail_move($imap_stream, '1', 'INBOX.'. IMAP_MAILBOX_PHPT_PREFIX));
imap_close($imap_stream);
?>
--CLEAN--
<?php
require_once('clean.inc');
$mailbox_suffix = '';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECTF--
--EXPECT--
*** Testing imap_mail_move() : basic functionality ***
Create a new mailbox for test
Create a temporary mailbox and add 1 msgs
.. mailbox '%s' created
New mailbox created
Msg Count in new mailbox: 1
bool(true)

View File

@ -2,7 +2,6 @@
imap_mutf7_to_utf8
--SKIPIF--
<?php if (!extension_loaded("imap")) print "skip"; ?>
<?php if (!function_exists("imap_mutf7_to_utf8")) print "skip"; ?>
--FILE--
<?php

View File

@ -5,7 +5,7 @@ Paul Sohier
#phptestfest utrecht
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
if (getenv("SKIP_ASAN")) die("skip leak sanitizer crashes");
?>
--FILE--
@ -20,10 +20,8 @@ try {
echo $e->getMessage() . \PHP_EOL;
}
require_once(__DIR__.'/imap_include.inc');
try {
imap_open($default_mailbox, $username, $password, NIL, -1);
imap_open('', '', '', NIL, -1);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}

View File

@ -4,20 +4,20 @@ imap_renamemailbox() function : basic functionality
Olivier Doucet
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
require_once(__DIR__.'/imap_include.inc');
require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = setup_test_mailbox('', 1);
$stream_id = setup_test_mailbox('imaprenamemailbox', 1);
if (!is_resource($stream_id)) {
exit("TEST FAILED: Unable to create test mailbox\n");
}
$newbox = $default_mailbox . "." . $mailbox_prefix;
$newbox = IMAP_DEFAULT_MAILBOX . "." . IMAP_MAILBOX_PHPT_PREFIX;
//commented because of bug #49901
//$ancError = error_reporting(0);
@ -34,11 +34,12 @@ imap_close($stream_id);
?>
--CLEAN--
<?php
require_once('clean.inc');
$mailbox_suffix = 'imaprenamemailbox';
require_once('setup/clean.inc');
?>
--EXPECTF--
--EXPECT--
Create a temporary mailbox and add 1 msgs
.. mailbox '{%s}%s' created
New mailbox created
Checking OK
bool(true)
bool(true)

View File

@ -4,13 +4,13 @@ imap_rfc822_parse_headers() function : basic functionality
Olivier Doucet
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
require_once(__DIR__.'/imap_include.inc');
$stream_id = setup_test_mailbox('', 1);
require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = setup_test_mailbox('imaprfc822parseheadersbasic', 1);
$z = imap_headerinfo($stream_id, 1);
@ -85,11 +85,12 @@ imap_close($stream_id);
?>
--CLEAN--
<?php
require_once('clean.inc');
$mailbox_suffix = 'imaprfc822parseheadersbasic';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECTF--
Create a temporary mailbox and add 1 msgs
.. mailbox '{%s}%s' created
New mailbox created
Check general fields
bool(true)
bool(true)

View File

@ -4,13 +4,13 @@ imap_savebody() function : basic functionality
Olivier Doucet
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
require_once(__DIR__.'/imap_include.inc');
$stream_id = setup_test_mailbox('', 1);
require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = setup_test_mailbox('imapsavebodybasic', 1);
$file = __DIR__.'/tmpsavebody.txt';
@ -31,11 +31,12 @@ imap_close($stream_id);
--CLEAN--
<?php
@unlink(__DIR__.'/tmpsavebody.txt');
require_once('clean.inc');
$mailbox_suffix = 'imapsavebodybasic';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECTF--
Create a temporary mailbox and add 1 msgs
.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created
New mailbox created
bool(true)
Size: %d
bool(true)

View File

@ -4,7 +4,7 @@ imap_timeout() function : basic functionality
Olivier Doucet
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

View File

@ -4,13 +4,13 @@ imap_undelete() function : basic functionality
Olivier Doucet
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php
require_once(__DIR__.'/imap_include.inc');
$stream_id = setup_test_mailbox('', 1);
require_once(__DIR__.'/setup/imap_include.inc');
$stream_id = setup_test_mailbox('imapundeletebasic', 1);
imap_delete($stream_id, 1);
@ -21,9 +21,10 @@ imap_close($stream_id);
?>
--CLEAN--
<?php
require_once('clean.inc');
$mailbox_suffix = 'imapundeletebasic';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECTF--
--EXPECT--
Create a temporary mailbox and add 1 msgs
.. mailbox '{%s}%s' created
New mailbox created
bool(true)

View File

@ -11,8 +11,8 @@ var_dump(imap_utf8("test"));
echo "Done\n";
?>
--EXPECTF--
--EXPECT--
string(0) ""
string(1) "1"
string(4) "%s"
string(4) "test"
Done

View File

@ -2,7 +2,6 @@
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

View File

@ -0,0 +1,23 @@
<?php
require_once 'imap_include.inc';
$imap_stream = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_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);
}
if (!isset($mailbox_suffix)) { throw new Exception("No suffix provided"); }
$mailboxes = imap_getmailboxes($imap_stream, IMAP_SERVER, '*');
foreach($mailboxes as $value) {
// Only delete mailbox with our prefix (+ optional test suffix)
if (preg_match('/\{.*?\}INBOX\.' . IMAP_MAILBOX_PHPT_PREFIX . $mailbox_suffix .'/', $value->name, $match) == 1) {
imap_deletemailbox($imap_stream, $value->name);
}
}
imap_close($imap_stream, CL_EXPUNGE);

View File

@ -1,31 +1,34 @@
<?php
// Change these to make tests run successfully
$server = '{127.0.0.1:143/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
/** If required change these values to make the test runs */
const IMAP_SERVER_NO_DEBUG = '{127.0.0.1:143/norsh}';
const IMAP_SERVER_DEBUG = '{127.0.0.1:143/debug/norsh}';
const IMAP_SERVER = IMAP_SERVER_DEBUG;
const IMAP_DEFAULT_MAILBOX = IMAP_SERVER . 'INBOX';
const IMAP_MAIL_DOMAIN = 'something.com';
const IMAP_ADMIN_USER = 'webmaster'; // a user with admin access
const IMAP_MAILBOX_USERNAME = IMAP_ADMIN_USER . '@' . IMAP_MAIL_DOMAIN;
const IMAP_MAILBOX_PASSWORD = 'p4ssw0rd';
const IMAP_MAILBOX_PHPT_PREFIX = 'phpttest';
/** Tests require 4 valid userids */
const IMAP_USERS = ["webmaster", "info", "admin", "foo"];
/** list of fields to expect */
const MANDATORY_OVERVIEW_FIELDS = [
'size',
'uid',
'msgno',
'recent',
'flagged',
'answered',
'deleted',
'seen',
'draft',
'udate',
];
// 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
*
@ -33,25 +36,23 @@ $mandatory_overview_fields = array(
* server with its clock synced to the current system, which is consistent with
* setup instructions in ext/imap/tests/README.md
*
* @param array resp element from the return value of imap_fetch_overview()
* @param $resp
* @param string[] $fields
*/
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";
function displayOverviewFields($resp, array $fields = MANDATORY_OVERVIEW_FIELDS) {
global $start_time;
foreach ($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";
}
}
}
}
@ -60,33 +61,27 @@ function displayOverviewFields($resp, $fields=null) {
*
* @param string mailbox_suffix Suffix used to uniquely identify mailboxes
* @param int message_count number of test msgs to be written to new mailbox
*
* @return IMAP stream to new mailbox on success; FALSE on failure
* @param null $new_mailbox
* @param bool $simpleMessages
* @return resource IMAP stream to new mailbox
* @throws Exception
*/
function setup_test_mailbox($mailbox_suffix, $message_count, &$new_mailbox = null, $msg_type = "simple"){
global $server, $default_mailbox, $username, $password;
function setup_test_mailbox(string $mailbox_suffix, int $message_count, &$new_mailbox = null, bool $simpleMessages = true){
// open a stream to default mailbox
$imap_stream = imap_open($default_mailbox, $username, $password);
$imap_stream = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);
if ($imap_stream === false) {
echo "Cannot connect to IMAP server $server: " . imap_last_error() . "\n";
return false;
throw new Exception("Cannot connect to IMAP server " . IMAP_SERVER . ": " . imap_last_error());
}
echo "Create a temporary mailbox and add " . $message_count . " msgs\n";
$new_mailbox = create_mailbox($imap_stream, $mailbox_suffix, $message_count, $msg_type);
if ($new_mailbox === false) {
echo "Can't create a temporary mailbox: " . imap_last_error(). "\n";
return false;
}
$new_mailbox = create_mailbox($imap_stream, $mailbox_suffix, $message_count, $simpleMessages);
echo ".. mailbox '$new_mailbox' created\n";
echo "New mailbox created\n";
// reopen stream to new mailbox
if (imap_reopen($imap_stream, $new_mailbox) === false) {
echo "can't re-open '$new_mailbox' mailbox: " . imap_last_error() . "\n";
return false;
throw new Exception("Can't re-open '$new_mailbox' mailbox: " . imap_last_error());
}
return $imap_stream;
@ -96,11 +91,14 @@ function setup_test_mailbox($mailbox_suffix, $message_count, &$new_mailbox = nul
* Create mailbox and fill with generic emails
*
* @param resource $imap_stream
* @param string $mailbox
* @param string $mailbox_suffix
* @param int $message_count
* @param bool $simpleMessages
* @return string
* @throws Exception
*/
function create_mailbox($imap_stream, $mailbox_suffix, $message_count, $msg_type= "simple"){
global $default_mailbox, $mailbox_prefix;
$mailbox = $default_mailbox . "." . $mailbox_prefix . $mailbox_suffix;
function create_mailbox($imap_stream, string $mailbox_suffix, int $message_count, bool $simpleMessages = true): string {
$mailbox = IMAP_DEFAULT_MAILBOX . '.' . IMAP_MAILBOX_PHPT_PREFIX . $mailbox_suffix;
$mailboxes = imap_getmailboxes($imap_stream, $mailbox, '*');
@ -108,18 +106,18 @@ function create_mailbox($imap_stream, $mailbox_suffix, $message_count, $msg_type
if ($mailboxes) {
foreach($mailboxes as $value) {
if ($value->name == $mailbox) {
exit ("TEST FAILED : Mailbox '$mailbox' already exists\n");
throw new Exception("Mailbox '$mailbox' already exists");
}
}
}
if (imap_createmailbox($imap_stream, $mailbox) === false) {
return false;
throw new Exception("Can't create a temporary mailbox: " . imap_last_error());
}
// Add number of test msgs requested
if ($message_count > 0) {
populate_mailbox($imap_stream, $mailbox, $message_count, $msg_type);
populate_mailbox($imap_stream, $mailbox, $message_count, $simpleMessages);
}
return $mailbox;
@ -130,21 +128,20 @@ function create_mailbox($imap_stream, $mailbox_suffix, $message_count, $msg_type
*
* @param resource $imap_stream
* @param string $mailbox
* @param int $message_count
* @param bool $simpleMessages
*/
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") {
function populate_mailbox($imap_stream, string $mailbox, int $message_count, bool $simpleMessages = true): void {
for ($i = 1; $i <= $message_count; $i++) {
if ($simpleMessages) {
$msg = "From: foo@anywhere.com\r\n"
. "To: $users[0]@$domain\r\n"
. "To: ". IMAP_USERS[0] . "@" . IMAP_MAIL_DOMAIN . "\r\n"
. "Subject: test$i\r\n"
. "\r\n"
. "$i: this is a test message, please ignore\r\n";
. "$i: this is a test message, please ignore\r\nnewline";
} else {
$envelope["from"]= "foo@anywhere.com";
$envelope["to"] = "$users[0]@$domain";
$envelope["to"] = IMAP_USERS[0] . "@" . IMAP_MAIL_DOMAIN;
$envelope["subject"] = "Test msg $i";
$part1["type"] = TYPEMULTIPART;
@ -181,16 +178,13 @@ function populate_mailbox($imap_stream, $mailbox, $message_count, $msg_type = "s
* Get the mailbox name from a mailbox description, i.e strip off server details.
*
* @param string mailbox complete mailbox name
* @return mailbox name
* @return string mailbox name
*/
function get_mailbox_name($mailbox){
function get_mailbox_name(string $mailboxName): string {
if (preg_match('/\{.*?\}(.*)/', $mailbox, $match) != 1) {
echo "Unrecpognized mailbox name\n";
return false;
if (preg_match('/\{.*?\}(.*)/', $mailboxName, $match) != 1) {
throw new Exception("Unrecognized mailbox name '$mailboxName'");
}
return $match[1];
}
?>

View File

@ -1,6 +1,6 @@
sudo service dovecot stop
sudo groupadd -g 5000 vmail
sudo useradd -m -d /var/vmail -s /bin/false -u 5000 -g vmail vmail
sudo cp ext/imap/tests/dovecot.conf /etc/dovecot/dovecot.conf
sudo cp ext/imap/tests/dovecotpass /etc/dovecot/dovecotpass
sudo cp ext/imap/tests/setup/dovecot.conf /etc/dovecot/dovecot.conf
sudo cp ext/imap/tests/setup/dovecotpass /etc/dovecot/dovecotpass
sudo service dovecot start

View File

@ -0,0 +1,13 @@
<?php
extension_loaded('imap') or die('skip imap extension not available in this build');
include __DIR__ . '/imap_include.inc';
$options = OP_HALFOPEN; // this should be enough to verify server present
$retries = 0; // don't retry connect on failure
$mbox = @imap_open(IMAP_SERVER, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD, $options, $retries);
if (!$mbox) {
die("skip could not connect to mailbox " . IMAP_SERVER);
}
imap_close($mbox);

View File

@ -1,16 +0,0 @@
<?php
extension_loaded('imap') or die('skip imap extension not available in this build');
// Change these to make tests run successfully
$mailbox = '{127.0.0.1:143/debug/norsh}';
$username = 'webmaster@something.com';
$password = 'p4ssw0rd';
$options = OP_HALFOPEN; // this should be enough to verify server present
$retries = 0; // don't 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);
?>