Skip to content

Commit f731477

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #80706: mail(): Headers after Bcc headers may be ignored
2 parents e2c30c6 + ca7547c commit f731477

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2021, PHP 8.0.3
44

5+
- Core:
6+
. Fixed #80706 (mail(): Headers after Bcc headers may be ignored). (cmb)
7+
58
- Gettext:
69
. Fixed bug #53251 (bindtextdomain with null dir doesn't return old value).
710
(cmb)

ext/standard/tests/mail/bug80706.phpt

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
--TEST--
2+
Bug #72964 (White space not unfolded for CC/Bcc headers)
3+
--SKIPIF--
4+
<?php
5+
if (PHP_OS_FAMILY !== 'Windows') die('skip Windows only test');
6+
if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
7+
require_once __DIR__ . '/mail_skipif.inc';
8+
?>
9+
--INI--
10+
SMTP=localhost
11+
smtp_port=25
12+
--FILE--
13+
<?php
14+
require_once __DIR__ . '/mail_include.inc';
15+
16+
function find_and_delete_message($username, $subject) {
17+
global $default_mailbox, $password;
18+
19+
$imap_stream = imap_open($default_mailbox, $username, $password);
20+
if ($imap_stream === false) {
21+
die("Cannot connect to IMAP server $server: " . imap_last_error() . "\n");
22+
}
23+
24+
$found = false;
25+
$repeat_count = 20; // we will repeat a max of 20 times
26+
while (!$found && $repeat_count > 0) {
27+
// sleep for a while to allow msg to be delivered
28+
sleep(1);
29+
30+
$num_messages = imap_check($imap_stream)->Nmsgs;
31+
for ($i = $num_messages; $i > 0; $i--) {
32+
$info = imap_headerinfo($imap_stream, $i);
33+
if ($info->subject === $subject) {
34+
$header = imap_fetchheader($imap_stream, $i);
35+
echo "X-Mailer header found: ";
36+
var_dump(strpos($header, 'X-Mailer: bug80706') !== false);
37+
imap_delete($imap_stream, $i);
38+
$found = true;
39+
break;
40+
}
41+
}
42+
$repeat_count--;
43+
}
44+
45+
imap_close($imap_stream, CL_EXPUNGE);
46+
return $found;
47+
}
48+
49+
$to = "{$users[1]}@$domain";
50+
$subject = bin2hex(random_bytes(16));
51+
$message = 'hello';
52+
$headers = "From: webmaster@example.com\r\n"
53+
. "Bcc: {$users[2]}@$domain\r\n"
54+
. "X-Mailer: bug80706";
55+
56+
$res = mail($to, $subject, $message, $headers);
57+
if ($res !== true) {
58+
die("TEST FAILED : Unable to send test email\n");
59+
} else {
60+
echo "Message sent OK\n";
61+
}
62+
63+
foreach ([$users[1], $users[2]] as $user) {
64+
if (!find_and_delete_message("$user@$domain", $subject)) {
65+
echo "TEST FAILED: email not delivered\n";
66+
} else {
67+
echo "TEST PASSED: Message sent and deleted OK\n";
68+
}
69+
}
70+
?>
71+
--EXPECT--
72+
Message sent OK
73+
X-Mailer header found: bool(true)
74+
TEST PASSED: Message sent and deleted OK
75+
X-Mailer header found: bool(true)
76+
TEST PASSED: Message sent and deleted OK

win32/sendmail.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ static int SendText(char *RPath, const char *Subject, const char *mailTo, char *
527527
header we know it was the last thing. */
528528
pos2 = pos1;
529529
} else {
530-
char *pos3 = NULL;
530+
char *pos3 = pos2;
531531
while (pos2[2] == ' ' || pos2[2] == '\t') {
532532
pos3 = strstr(pos2 + 2, "\r\n");
533533
if (pos3 != NULL) {

0 commit comments

Comments
 (0)