-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix #80751: Comma in recipient name breaks email delivery #6735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
27d3632
Fix #80751: Comma in recipient name breaks email delivery
cmb69 d4d9ba6
Skip character after backslash in quoted-string instead of looking back
cmb69 418d688
Handle case where backslash in quoted-string is last char
cmb69 b5eedff
Don't break out of loop on backslash outside of quoted-strings
cmb69 c92dd66
Fix minor issues
cmb69 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
--TEST-- | ||
Bug #80751 (Comma in recipient name breaks email delivery) | ||
--SKIPIF-- | ||
<?php | ||
if (PHP_OS_FAMILY !== 'Windows') die('skip Windows only test'); | ||
if (getenv("SKIP_SLOW_TESTS")) die('skip slow test'); | ||
require_once __DIR__ . '/mail_skipif.inc'; | ||
?> | ||
--INI-- | ||
SMTP=localhost | ||
smtp_port=25 | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . '/mail_include.inc'; | ||
|
||
function find_and_delete_message($username, $subject) { | ||
global $default_mailbox, $password; | ||
|
||
$imap_stream = imap_open($default_mailbox, $username, $password); | ||
if ($imap_stream === false) { | ||
die("Cannot connect to IMAP server $server: " . imap_last_error() . "\n"); | ||
} | ||
|
||
$found = false; | ||
$repeat_count = 20; // we will repeat a max of 20 times | ||
while (!$found && $repeat_count > 0) { | ||
// sleep for a while to allow msg to be delivered | ||
sleep(1); | ||
|
||
$num_messages = imap_check($imap_stream)->Nmsgs; | ||
for ($i = $num_messages; $i > 0; $i--) { | ||
$info = imap_headerinfo($imap_stream, $i); | ||
if ($info->subject === $subject) { | ||
$header = imap_fetchheader($imap_stream, $i); | ||
echo "Return-Path header found: "; | ||
var_dump(strpos($header, 'Return-Path: [email protected]') !== false); | ||
echo "To header found: "; | ||
var_dump(strpos($header, 'To: "<[email protected]>" <[email protected]>') !== false); | ||
echo "From header found: "; | ||
var_dump(strpos($header, 'From: "<[email protected]>" <[email protected]>') !== false); | ||
echo "Cc header found: "; | ||
var_dump(strpos($header, 'Cc: "Lastname, Firstname\\\\" <[email protected]>') !== false); | ||
imap_delete($imap_stream, $i); | ||
$found = true; | ||
break; | ||
} | ||
} | ||
$repeat_count--; | ||
} | ||
|
||
imap_close($imap_stream, CL_EXPUNGE); | ||
return $found; | ||
} | ||
|
||
$to = "\"<[email protected]>\" <{$users[1]}@$domain>"; | ||
$subject = bin2hex(random_bytes(16)); | ||
$message = 'hello'; | ||
$headers = "From: \"<[email protected]>\" <[email protected]>\r\n" | ||
. "Cc: \"Lastname, Firstname\\\\\" <{$users[2]}@$domain>\r\n" | ||
. "Bcc: \"Firstname \\\"Ni,ck\\\" Lastname\" <{$users[3]}@$domain>\r\n"; | ||
|
||
$res = mail($to, $subject, $message, $headers); | ||
if ($res !== true) { | ||
die("TEST FAILED : Unable to send test email\n"); | ||
} else { | ||
echo "Message sent OK\n"; | ||
} | ||
|
||
foreach ([$users[1], $users[2], $users[3]] as $user) { | ||
if (!find_and_delete_message("$user@$domain", $subject)) { | ||
echo "TEST FAILED: email not delivered\n"; | ||
} else { | ||
echo "TEST PASSED: Message sent and deleted OK\n"; | ||
} | ||
} | ||
?> | ||
--EXPECT-- | ||
Message sent OK | ||
Return-Path header found: bool(true) | ||
To header found: bool(true) | ||
From header found: bool(true) | ||
Cc header found: bool(true) | ||
TEST PASSED: Message sent and deleted OK | ||
Return-Path header found: bool(true) | ||
To header found: bool(true) | ||
From header found: bool(true) | ||
Cc header found: bool(true) | ||
TEST PASSED: Message sent and deleted OK | ||
Return-Path header found: bool(true) | ||
To header found: bool(true) | ||
From header found: bool(true) | ||
Cc header found: bool(true) | ||
TEST PASSED: Message sent and deleted OK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.