Skip to content

Commit 382c355

Browse files
committed
Replaced imap with mailpit and refreshed the test.
1 parent c774a8d commit 382c355

16 files changed

+378
-974
lines changed

ext/standard/tests/mail/bug72964.phpt

Lines changed: 43 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,67 @@
11
--TEST--
22
Bug #72964 (White space not unfolded for CC/Bcc headers)
3-
--EXTENSIONS--
4-
imap
5-
--CONFLICTS--
6-
imap
73
--SKIPIF--
84
<?php
9-
if (PHP_OS_FAMILY !== 'Windows') die('skip Windows only test');
105
if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
11-
require_once __DIR__ . '/mail_skipif.inc';
6+
require_once __DIR__.'/mail_windows_skipif.inc';
127
?>
138
--INI--
149
SMTP=localhost
15-
smtp_port=25
10+
smtp_port=1025
11+
sendmail_from=from@example.com
1612
--FILE--
1713
<?php
18-
require_once __DIR__ . '/mail_include.inc';
1914

20-
function find_and_delete_message($username, $subject) {
21-
global $default_mailbox, $password;
15+
require_once __DIR__.'/mailpit_utils.inc';
2216

23-
$imap_stream = imap_open($default_mailbox, $username, $password);
24-
if ($imap_stream === false) {
25-
die("Cannot connect to IMAP server $server: " . imap_last_error() . "\n");
26-
}
27-
28-
$found = false;
29-
$repeat_count = 20; // we will repeat a max of 20 times
30-
while (!$found && $repeat_count > 0) {
31-
// sleep for a while to allow msg to be delivered
32-
sleep(1);
33-
34-
$num_messages = imap_check($imap_stream)->Nmsgs;
35-
for ($i = $num_messages; $i > 0; $i--) {
36-
$info = imap_headerinfo($imap_stream, $i);
37-
if ($info->subject === $subject) {
38-
imap_delete($imap_stream, $i);
39-
$found = true;
40-
break;
41-
}
42-
}
43-
$repeat_count--;
44-
}
45-
46-
imap_close($imap_stream, CL_EXPUNGE);
47-
return $found;
48-
}
49-
50-
$to = "{$users[2]}@$domain";
17+
$to = 'bug72964_to@example.com';
18+
$from = ini_get('sendmail_from');
19+
$cc = ['bug72964_cc_1@example.com', 'bug72964_cc_2@example.com'];
20+
$bcc = ['bug72964_bcc_1@example.com', 'bug72964_bcc_2@example.com'];
5121
$subject = bin2hex(random_bytes(16));
5222
$message = 'hello';
53-
$headers = "From: webmaster@example.com\r\n"
54-
. "Cc: {$users[0]}@$domain,\r\n\t{$users[1]}@$domain\r\n"
55-
. "Bcc: {$users[2]}@$domain,\r\n {$users[3]}@$domain\r\n";
23+
$headers = "From: {$from}\r\n"
24+
. "Cc: {$cc[0]},\r\n\t{$cc[1]}\r\n"
25+
. "Bcc: {$bcc[0]},\r\n {$bcc[1]}\r\n";
5626

5727
$res = mail($to, $subject, $message, $headers);
28+
5829
if ($res !== true) {
59-
die("TEST FAILED : Unable to send test email\n");
30+
exit("Unable to send the email.\n");
6031
} else {
61-
echo "Message sent OK\n";
32+
echo "Sent the email.\n";
6233
}
6334

64-
foreach ($users as $user) {
65-
if (!find_and_delete_message("$user@$domain", $subject)) {
66-
echo "TEST FAILED: email not delivered\n";
67-
} else {
68-
echo "TEST PASSED: Message sent and deleted OK\n";
35+
$res = searchEmailByToAddress($to);
36+
37+
if (mailCheckResponse($res, $from, $to, $subject, $message)) {
38+
echo "Received the email.\n";
39+
40+
$ccAddresses = getCcAddresses($res);
41+
if (in_array($cc[0], $ccAddresses, true)) {
42+
echo "cc1 Received the email.\n";
43+
}
44+
45+
if (in_array($cc[1], $ccAddresses, true)) {
46+
echo "cc2 Received the email.\n";
47+
}
48+
49+
$bccAddresses = getBccAddresses($res);
50+
if (in_array($bcc[0], $bccAddresses, true)) {
51+
echo "bcc1 Received the email.\n";
52+
}
53+
54+
if (in_array($bcc[1], $bccAddresses, true)) {
55+
echo "bcc2 Received the email.";
6956
}
57+
58+
deleteEmail($res);
7059
}
7160
?>
7261
--EXPECT--
73-
Message sent OK
74-
TEST PASSED: Message sent and deleted OK
75-
TEST PASSED: Message sent and deleted OK
76-
TEST PASSED: Message sent and deleted OK
77-
TEST PASSED: Message sent and deleted OK
62+
Sent the email.
63+
Received the email.
64+
cc1 Received the email.
65+
cc2 Received the email.
66+
bcc1 Received the email.
67+
bcc2 Received the email.

ext/standard/tests/mail/bug80706.phpt

Lines changed: 34 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,57 @@
11
--TEST--
2-
Bug #72964 (White space not unfolded for CC/Bcc headers)
3-
--EXTENSIONS--
4-
imap
5-
--CONFLICTS--
6-
imap
2+
Bug #80706 (Headers after Bcc headers may be ignored)
73
--SKIPIF--
84
<?php
9-
if (PHP_OS_FAMILY !== 'Windows') die('skip Windows only test');
105
if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
11-
require_once __DIR__ . '/mail_skipif.inc';
6+
require_once __DIR__.'/mail_windows_skipif.inc';
127
?>
138
--INI--
149
SMTP=localhost
15-
smtp_port=25
10+
smtp_port=1025
11+
sendmail_from=from@example.com
1612
--FILE--
1713
<?php
18-
require_once __DIR__ . '/mail_include.inc';
1914

20-
function find_and_delete_message($username, $subject) {
21-
global $default_mailbox, $password;
15+
require_once __DIR__.'/mailpit_utils.inc';
2216

23-
$imap_stream = imap_open($default_mailbox, $username, $password);
24-
if ($imap_stream === false) {
25-
die("Cannot connect to IMAP server $server: " . imap_last_error() . "\n");
26-
}
27-
28-
$found = false;
29-
$repeat_count = 20; // we will repeat a max of 20 times
30-
while (!$found && $repeat_count > 0) {
31-
// sleep for a while to allow msg to be delivered
32-
sleep(1);
33-
34-
$num_messages = imap_check($imap_stream)->Nmsgs;
35-
for ($i = $num_messages; $i > 0; $i--) {
36-
$info = imap_headerinfo($imap_stream, $i);
37-
if ($info->subject === $subject) {
38-
$header = imap_fetchheader($imap_stream, $i);
39-
echo "X-Mailer header found: ";
40-
var_dump(strpos($header, 'X-Mailer: bug80706') !== false);
41-
imap_delete($imap_stream, $i);
42-
$found = true;
43-
break;
44-
}
45-
}
46-
$repeat_count--;
47-
}
48-
49-
imap_close($imap_stream, CL_EXPUNGE);
50-
return $found;
51-
}
52-
53-
$to = "{$users[1]}@$domain";
17+
$to = 'bug80706_to@example.com';
18+
$from = ini_get('sendmail_from');
19+
$bcc = 'bug80706_bcc@exsample.com';
5420
$subject = bin2hex(random_bytes(16));
5521
$message = 'hello';
56-
$headers = "From: webmaster@example.com\r\n"
57-
. "Bcc: {$users[2]}@$domain\r\n"
58-
. "X-Mailer: bug80706";
22+
$xMailer = 'bug80706_x_mailer';
23+
$headers = "From: {$from}\r\n"
24+
. "Bcc: {$bcc}\r\n"
25+
. "X-Mailer: {$xMailer}";
5926

6027
$res = mail($to, $subject, $message, $headers);
28+
6129
if ($res !== true) {
62-
die("TEST FAILED : Unable to send test email\n");
30+
exit("Unable to send the email.\n");
6331
} else {
64-
echo "Message sent OK\n";
32+
echo "Sent the email.\n";
6533
}
6634

67-
foreach ([$users[1], $users[2]] as $user) {
68-
if (!find_and_delete_message("$user@$domain", $subject)) {
69-
echo "TEST FAILED: email not delivered\n";
70-
} else {
71-
echo "TEST PASSED: Message sent and deleted OK\n";
35+
$res = searchEmailByToAddress($to);
36+
37+
if (mailCheckResponse($res, $from, $to, $subject, $message)) {
38+
echo "Received the email.\n";
39+
40+
$bccAddresses = getBccAddresses($res);
41+
if (in_array($bcc, $bccAddresses, true)) {
42+
echo "bcc Received the email.\n";
7243
}
44+
45+
$headers = getHeaders($res);
46+
if ($headers['X-Mailer'][0] === $xMailer) {
47+
echo "The specified x-Mailer exists.";
48+
}
49+
50+
deleteEmail($res);
7351
}
7452
?>
7553
--EXPECT--
76-
Message sent OK
77-
X-Mailer header found: bool(true)
78-
TEST PASSED: Message sent and deleted OK
79-
X-Mailer header found: bool(true)
80-
TEST PASSED: Message sent and deleted OK
54+
Sent the email.
55+
Received the email.
56+
bcc Received the email.
57+
The specified x-Mailer exists.

ext/standard/tests/mail/bug80751.phpt

Lines changed: 58 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,84 @@
11
--TEST--
22
Bug #80751 (Comma in recipient name breaks email delivery)
3-
--EXTENSIONS--
4-
imap
5-
--CONFLICTS--
6-
imap
73
--SKIPIF--
84
<?php
9-
if (PHP_OS_FAMILY !== 'Windows') die('skip Windows only test');
105
if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
11-
require_once __DIR__ . '/mail_skipif.inc';
6+
require_once __DIR__.'/mail_windows_skipif.inc';
127
?>
138
--INI--
149
SMTP=localhost
15-
smtp_port=25
10+
smtp_port=1025
1611
--FILE--
1712
<?php
18-
require_once __DIR__ . '/mail_include.inc';
1913

20-
function find_and_delete_message($username, $subject) {
21-
global $default_mailbox, $password, $users, $domain;
14+
require_once __DIR__.'/mailpit_utils.inc';
2215

23-
$imap_stream = imap_open($default_mailbox, $username, $password);
24-
if ($imap_stream === false) {
25-
die("Cannot connect to IMAP server $server: " . imap_last_error() . "\n");
26-
}
16+
$to = 'bug80751_to@example.com';
17+
$toLine = "\"<bug80751_to_name@example.com>\" <{$to}>";
2718

28-
$found = false;
29-
$repeat_count = 20; // we will repeat a max of 20 times
30-
while (!$found && $repeat_count > 0) {
31-
// sleep for a while to allow msg to be delivered
32-
sleep(1);
33-
34-
$num_messages = imap_check($imap_stream)->Nmsgs;
35-
for ($i = $num_messages; $i > 0; $i--) {
36-
$info = imap_headerinfo($imap_stream, $i);
37-
if ($info->subject === $subject) {
38-
$header = imap_fetchheader($imap_stream, $i);
39-
echo "Return-Path header found: ";
40-
var_dump(strpos($header, 'Return-Path: joe@example.com') !== false);
41-
echo "To header found: ";
42-
var_dump(strpos($header, "To: \"<bob@example.com>\" <{$users[1]}@$domain>") !== false);
43-
echo "From header found: ";
44-
var_dump(strpos($header, 'From: "<bob@example.com>" <joe@example.com>') !== false);
45-
echo "Cc header found: ";
46-
var_dump(strpos($header, "Cc: \"Lastname, Firstname\\\\\" <{$users[2]}@$domain>") !== false);
47-
imap_delete($imap_stream, $i);
48-
$found = true;
49-
break;
50-
}
51-
}
52-
$repeat_count--;
53-
}
19+
$from = 'bug80751_from@example.com';
20+
$fromLine = "\"<bug80751_from_name@example.com>\" <{$from}>";
5421

55-
imap_close($imap_stream, CL_EXPUNGE);
56-
return $found;
57-
}
22+
$cc = 'bug80751_cc@example.com';
23+
$ccLine = "\"Lastname, Firstname\\\\\" <{$cc}>";
5824

59-
$to = "\"<bob@example.com>\" <{$users[1]}@$domain>";
25+
$bcc = 'bug80751_bcc@example.com';
6026
$subject = bin2hex(random_bytes(16));
6127
$message = 'hello';
62-
$headers = "From: \"<bob@example.com>\" <joe@example.com>\r\n"
63-
. "Cc: \"Lastname, Firstname\\\\\" <{$users[2]}@$domain>\r\n"
64-
. "Bcc: \"Firstname \\\"Ni,ck\\\" Lastname\" <{$users[3]}@$domain>\r\n";
6528

66-
$res = mail($to, $subject, $message, $headers);
29+
$headers = "From: {$fromLine}\r\n"
30+
. "Cc: {$ccLine}\r\n"
31+
. "Bcc: \"Firstname \\\"Ni,ck\\\" Lastname\" <{$bcc}>\r\n";
32+
33+
$res = mail($toLine, $subject, $message, $headers);
34+
6735
if ($res !== true) {
68-
die("TEST FAILED : Unable to send test email\n");
36+
exit("Unable to send the email.\n");
6937
} else {
70-
echo "Message sent OK\n";
38+
echo "Sent the email.\n";
7139
}
7240

73-
foreach ([$users[1], $users[2], $users[3]] as $user) {
74-
if (!find_and_delete_message("$user@$domain", $subject)) {
75-
echo "TEST FAILED: email not delivered\n";
76-
} else {
77-
echo "TEST PASSED: Message sent and deleted OK\n";
41+
$res = searchEmailByToAddress($to);
42+
43+
if (mailCheckResponse($res, $from, $to, $subject, $message)) {
44+
echo "Received the email.\n";
45+
46+
$ccAddresses = getCcAddresses($res);
47+
if (in_array($cc, $ccAddresses, true)) {
48+
echo "cc Received the email.\n";
49+
}
50+
51+
$bccAddresses = getBccAddresses($res);
52+
if (in_array($bcc, $bccAddresses, true)) {
53+
echo "bcc Receive the email.\n";
7854
}
55+
56+
if ($res['ReturnPath'] === $from) {
57+
echo "Return-Path is as expected.\n";
58+
}
59+
60+
$headers = getHeaders($res);
61+
if ($headers['To'][0] === $toLine) {
62+
echo "To header is as expected.\n";
63+
}
64+
65+
if ($headers['From'] === $fromLine) {
66+
echo "From header is as expected.\n";
67+
}
68+
69+
if ($headers['Cc'][0] === $ccLine) {
70+
echo "Cc header is as expected.";
71+
}
72+
73+
deleteEmail($res);
7974
}
8075
?>
8176
--EXPECT--
82-
Message sent OK
83-
Return-Path header found: bool(true)
84-
To header found: bool(true)
85-
From header found: bool(true)
86-
Cc header found: bool(true)
87-
TEST PASSED: Message sent and deleted OK
88-
Return-Path header found: bool(true)
89-
To header found: bool(true)
90-
From header found: bool(true)
91-
Cc header found: bool(true)
92-
TEST PASSED: Message sent and deleted OK
93-
Return-Path header found: bool(true)
94-
To header found: bool(true)
95-
From header found: bool(true)
96-
Cc header found: bool(true)
97-
TEST PASSED: Message sent and deleted OK
77+
Sent the email.
78+
Received the email.
79+
cc Received the email.
80+
bcc Receive the email.
81+
Return-Path is as expected.
82+
To header is as expected.
83+
From header is as expected.
84+
Cc header is as expected.

0 commit comments

Comments
 (0)