Skip to content

Commit c734351

Browse files
committedNov 19, 2020
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #72964: White space not unfolded for CC/Bcc headers
2 parents 2e27bb8 + 881e43a commit c734351

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed
 

‎NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ PHP NEWS
55
- Core:
66
. Fixed bug #80345 (PHPIZE configuration has outdated PHP_RELEASE_VERSION).
77
(cmb)
8+
. Fixed bug #72964 (White space not unfolded for CC/Bcc headers). (cmb)
89

910
26 Nov 2020, PHP 8.0.0
1011

‎ext/standard/tests/mail/bug72964.phpt

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
imap_delete($imap_stream, $i);
35+
$found = true;
36+
break;
37+
}
38+
}
39+
$repeat_count--;
40+
}
41+
42+
imap_close($imap_stream, CL_EXPUNGE);
43+
return $found;
44+
}
45+
46+
$to = "{$users[2]}@$domain";
47+
$subject = bin2hex(random_bytes(16));
48+
$message = 'hello';
49+
$headers = "From: webmaster@example.com\r\n"
50+
. "Cc: {$users[0]}@$domain,\r\n\t{$users[1]}@$domain\r\n"
51+
. "Bcc: {$users[2]}@$domain,\r\n {$users[3]}@$domain\r\n";
52+
53+
$res = mail($to, $subject, $message, $headers);
54+
if ($res !== true) {
55+
die("TEST FAILED : Unable to send test email\n");
56+
} else {
57+
echo "Message sent OK\n";
58+
}
59+
60+
foreach ($users as $user) {
61+
if (!find_and_delete_message("$user@$domain", $subject)) {
62+
echo "TEST FAILED: email not delivered\n";
63+
} else {
64+
echo "TEST PASSED: Message sent and deleted OK\n";
65+
}
66+
}
67+
?>
68+
--EXPECT--
69+
Message sent OK
70+
TEST PASSED: Message sent and deleted OK
71+
TEST PASSED: Message sent and deleted OK
72+
TEST PASSED: Message sent and deleted OK
73+
TEST PASSED: Message sent and deleted OK

‎win32/sendmail.c

+25
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,16 @@ static int SendText(char *RPath, const char *Subject, const char *mailTo, char *
459459
if (NULL == (pos2 = strstr(pos1, "\r\n"))) {
460460
tempMailTo = estrndup(pos1, strlen(pos1));
461461
} else {
462+
char *pos3;
463+
while (pos2[2] == ' ' || pos2[2] == '\t') {
464+
pos3 = strstr(pos2 + 2, "\r\n");
465+
if (pos3 != NULL) {
466+
pos2 = pos3;
467+
} else {
468+
pos2 += strlen(pos2);
469+
break;
470+
}
471+
}
462472
tempMailTo = estrndup(pos1, pos2 - pos1);
463473
}
464474

@@ -517,7 +527,22 @@ static int SendText(char *RPath, const char *Subject, const char *mailTo, char *
517527
header we know it was the last thing. */
518528
pos2 = pos1;
519529
} else {
530+
char *pos3 = NULL;
531+
while (pos2[2] == ' ' || pos2[2] == '\t') {
532+
pos3 = strstr(pos2 + 2, "\r\n");
533+
if (pos3 != NULL) {
534+
pos2 = pos3;
535+
} else {
536+
pos2 += strlen(pos2);
537+
break;
538+
}
539+
}
520540
tempMailTo = estrndup(pos1, pos2 - pos1);
541+
if (pos3 == NULL) {
542+
/* Later, when we remove the Bcc: out of the
543+
header we know it was the last thing. */
544+
pos2 = pos1;
545+
}
521546
}
522547

523548
token = strtok(tempMailTo, ",");

0 commit comments

Comments
 (0)
Failed to load comments.