Skip to content

Commit e28adc5

Browse files
committed
Replaced imap with mailhog and refreshed the test.
1 parent c774a8d commit e28adc5

16 files changed

+423
-971
lines changed

ext/standard/tests/mail/bug72964.phpt

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,75 @@
11
--TEST--
22
Bug #72964 (White space not unfolded for CC/Bcc headers)
33
--EXTENSIONS--
4-
imap
5-
--CONFLICTS--
6-
imap
4+
curl
75
--SKIPIF--
86
<?php
9-
if (PHP_OS_FAMILY !== 'Windows') die('skip Windows only test');
107
if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
11-
require_once __DIR__ . '/mail_skipif.inc';
8+
require_once __DIR__.'/mail_windows_skipif.inc';
129
?>
1310
--INI--
1411
SMTP=localhost
15-
smtp_port=25
12+
smtp_port=1025
13+
sendmail_from=from@example.com
1614
--FILE--
1715
<?php
18-
require_once __DIR__ . '/mail_include.inc';
1916

20-
function find_and_delete_message($username, $subject) {
21-
global $default_mailbox, $password;
17+
require_once __DIR__.'/mailhog_utils.inc';
2218

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";
19+
$to = 'bug72964_to@example.com';
20+
$from = ini_get('sendmail_from');
21+
$cc = ['bug72964_cc_1@example.com', 'bug72964_cc_2@example.com'];
22+
$bcc = ['bug72964_bcc_1@example.com', 'bug72964_bcc_2@example.com'];
5123
$subject = bin2hex(random_bytes(16));
5224
$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";
25+
$headers = "From: {$from}\r\n"
26+
. "Cc: {$cc[0]},\r\n\t{$cc[1]}\r\n"
27+
. "Bcc: {$bcc[0]},\r\n {$bcc[1]}\r\n";
5628

5729
$res = mail($to, $subject, $message, $headers);
30+
5831
if ($res !== true) {
59-
die("TEST FAILED : Unable to send test email\n");
32+
exit("Unable to send the email.\n");
6033
} else {
61-
echo "Message sent OK\n";
34+
echo "Sent the email.\n";
6235
}
6336

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";
37+
$res = searchEmailByToAddress($to);
38+
39+
if (
40+
$res &&
41+
getFromAddress($res) === $from &&
42+
getToAddresses($res)[0] === $to &&
43+
getSubject($res) === $subject &&
44+
getBody($res) === "\r\n".$message // The last newline in the header goes in first.
45+
) {
46+
echo "Received the email.\n";
47+
48+
$recipients = getRecipientAddresses($res);
49+
50+
if (in_array($cc[0], $recipients, true)) {
51+
echo "cc1 Received the email.\n";
52+
}
53+
54+
if (in_array($cc[1], $recipients, true)) {
55+
echo "cc2 Received the email.\n";
56+
}
57+
58+
if (in_array($bcc[0], $recipients, true)) {
59+
echo "bcc1 Received the email.\n";
60+
}
61+
62+
if (in_array($bcc[1], $recipients, true)) {
63+
echo "bcc2 Received the email.";
6964
}
65+
66+
deleteEmail($res);
7067
}
7168
?>
7269
--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
70+
Sent the email.
71+
Received the email.
72+
cc1 Received the email.
73+
cc2 Received the email.
74+
bcc1 Received the email.
75+
bcc2 Received the email.

ext/standard/tests/mail/bug80706.phpt

Lines changed: 42 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,66 @@
11
--TEST--
2-
Bug #72964 (White space not unfolded for CC/Bcc headers)
2+
Bug #80706 (Headers after Bcc headers may be ignored)
33
--EXTENSIONS--
4-
imap
5-
--CONFLICTS--
6-
imap
4+
curl
75
--SKIPIF--
86
<?php
9-
if (PHP_OS_FAMILY !== 'Windows') die('skip Windows only test');
107
if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
11-
require_once __DIR__ . '/mail_skipif.inc';
8+
require_once __DIR__.'/mail_windows_skipif.inc';
129
?>
1310
--INI--
1411
SMTP=localhost
15-
smtp_port=25
12+
smtp_port=1025
13+
sendmail_from=from@example.com
1614
--FILE--
1715
<?php
18-
require_once __DIR__ . '/mail_include.inc';
1916

20-
function find_and_delete_message($username, $subject) {
21-
global $default_mailbox, $password;
17+
require_once __DIR__.'/mailhog_utils.inc';
2218

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";
19+
$to = 'bug80706_to@example.com';
20+
$from = ini_get('sendmail_from');
21+
$bcc = 'bug80706_bcc@exsample.com';
5422
$subject = bin2hex(random_bytes(16));
5523
$message = 'hello';
56-
$headers = "From: webmaster@example.com\r\n"
57-
. "Bcc: {$users[2]}@$domain\r\n"
58-
. "X-Mailer: bug80706";
24+
$xMailer = 'bug80706_x_mailer';
25+
$headers = "From: {$from}\r\n"
26+
. "Bcc: {$bcc}\r\n"
27+
. "X-Mailer: {$xMailer}";
5928

6029
$res = mail($to, $subject, $message, $headers);
30+
6131
if ($res !== true) {
62-
die("TEST FAILED : Unable to send test email\n");
32+
exit("Unable to send the email.\n");
6333
} else {
64-
echo "Message sent OK\n";
34+
echo "Sent the email.\n";
6535
}
6636

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";
37+
$res = searchEmailByToAddress($to);
38+
39+
if (
40+
$res &&
41+
getFromAddress($res) === $from &&
42+
getToAddresses($res)[0] === $to &&
43+
getSubject($res) === $subject &&
44+
getBody($res) === $message
45+
) {
46+
echo "Received the email.\n";
47+
48+
$recipients = getRecipientAddresses($res);
49+
50+
if (in_array($bcc, $recipients, true)) {
51+
echo "bcc Received the email.\n";
7252
}
53+
54+
$headers = getHeaders($res);
55+
if ($headers['X-Mailer'][0] === $xMailer) {
56+
echo "The specified x-Mailer exists.";
57+
}
58+
59+
deleteEmail($res);
7360
}
7461
?>
7562
--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
63+
Sent the email.
64+
Received the email.
65+
bcc Received the email.
66+
The specified x-Mailer exists.

0 commit comments

Comments
 (0)