-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Replaced imap with mailhog and refreshed the test. #13197
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
2 commits
Select commit
Hold shift + click to select a range
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
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
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 |
---|---|---|
@@ -1,77 +1,75 @@ | ||
--TEST-- | ||
Bug #72964 (White space not unfolded for CC/Bcc headers) | ||
--EXTENSIONS-- | ||
imap | ||
--CONFLICTS-- | ||
imap | ||
curl | ||
--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'; | ||
require_once __DIR__.'/mail_windows_skipif.inc'; | ||
?> | ||
--INI-- | ||
SMTP=localhost | ||
smtp_port=25 | ||
smtp_port=1025 | ||
sendmail_from=from@example.com | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . '/mail_include.inc'; | ||
|
||
function find_and_delete_message($username, $subject) { | ||
global $default_mailbox, $password; | ||
require_once __DIR__.'/mailhog_utils.inc'; | ||
|
||
$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) { | ||
imap_delete($imap_stream, $i); | ||
$found = true; | ||
break; | ||
} | ||
} | ||
$repeat_count--; | ||
} | ||
|
||
imap_close($imap_stream, CL_EXPUNGE); | ||
return $found; | ||
} | ||
|
||
$to = "{$users[2]}@$domain"; | ||
$to = 'bug72964_to@example.com'; | ||
$from = ini_get('sendmail_from'); | ||
$cc = ['bug72964_cc_1@example.com', 'bug72964_cc_2@example.com']; | ||
$bcc = ['bug72964_bcc_1@example.com', 'bug72964_bcc_2@example.com']; | ||
$subject = bin2hex(random_bytes(16)); | ||
$message = 'hello'; | ||
$headers = "From: webmaster@example.com\r\n" | ||
. "Cc: {$users[0]}@$domain,\r\n\t{$users[1]}@$domain\r\n" | ||
. "Bcc: {$users[2]}@$domain,\r\n {$users[3]}@$domain\r\n"; | ||
$headers = "From: {$from}\r\n" | ||
. "Cc: {$cc[0]},\r\n\t{$cc[1]}\r\n" | ||
. "Bcc: {$bcc[0]},\r\n {$bcc[1]}\r\n"; | ||
|
||
$res = mail($to, $subject, $message, $headers); | ||
|
||
if ($res !== true) { | ||
die("TEST FAILED : Unable to send test email\n"); | ||
exit("Unable to send the email.\n"); | ||
} else { | ||
echo "Message sent OK\n"; | ||
echo "Sent the email.\n"; | ||
} | ||
|
||
foreach ($users 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"; | ||
$res = searchEmailByToAddress($to); | ||
|
||
if ( | ||
$res && | ||
getFromAddress($res) === $from && | ||
getToAddresses($res)[0] === $to && | ||
getSubject($res) === $subject && | ||
getBody($res) === "\r\n".$message // The last newline in the header goes in first. | ||
) { | ||
echo "Received the email.\n"; | ||
|
||
$recipients = getRecipientAddresses($res); | ||
|
||
if (in_array($cc[0], $recipients, true)) { | ||
echo "cc1 Received the email.\n"; | ||
} | ||
|
||
if (in_array($cc[1], $recipients, true)) { | ||
echo "cc2 Received the email.\n"; | ||
} | ||
|
||
if (in_array($bcc[0], $recipients, true)) { | ||
echo "bcc1 Received the email.\n"; | ||
} | ||
|
||
if (in_array($bcc[1], $recipients, true)) { | ||
echo "bcc2 Received the email."; | ||
} | ||
|
||
deleteEmail($res); | ||
} | ||
?> | ||
--EXPECT-- | ||
Message sent OK | ||
TEST PASSED: Message sent and deleted OK | ||
TEST PASSED: Message sent and deleted OK | ||
TEST PASSED: Message sent and deleted OK | ||
TEST PASSED: Message sent and deleted OK | ||
Sent the email. | ||
Received the email. | ||
cc1 Received the email. | ||
cc2 Received the email. | ||
bcc1 Received the email. | ||
bcc2 Received the email. |
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 |
---|---|---|
@@ -1,80 +1,66 @@ | ||
--TEST-- | ||
Bug #72964 (White space not unfolded for CC/Bcc headers) | ||
Bug #80706 (Headers after Bcc headers may be ignored) | ||
--EXTENSIONS-- | ||
imap | ||
--CONFLICTS-- | ||
imap | ||
curl | ||
--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'; | ||
require_once __DIR__.'/mail_windows_skipif.inc'; | ||
?> | ||
--INI-- | ||
SMTP=localhost | ||
smtp_port=25 | ||
smtp_port=1025 | ||
sendmail_from=from@example.com | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . '/mail_include.inc'; | ||
|
||
function find_and_delete_message($username, $subject) { | ||
global $default_mailbox, $password; | ||
require_once __DIR__.'/mailhog_utils.inc'; | ||
|
||
$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 "X-Mailer header found: "; | ||
var_dump(strpos($header, 'X-Mailer: bug80706') !== false); | ||
imap_delete($imap_stream, $i); | ||
$found = true; | ||
break; | ||
} | ||
} | ||
$repeat_count--; | ||
} | ||
|
||
imap_close($imap_stream, CL_EXPUNGE); | ||
return $found; | ||
} | ||
|
||
$to = "{$users[1]}@$domain"; | ||
$to = 'bug80706_to@example.com'; | ||
$from = ini_get('sendmail_from'); | ||
$bcc = 'bug80706_bcc@exsample.com'; | ||
$subject = bin2hex(random_bytes(16)); | ||
$message = 'hello'; | ||
$headers = "From: webmaster@example.com\r\n" | ||
. "Bcc: {$users[2]}@$domain\r\n" | ||
. "X-Mailer: bug80706"; | ||
$xMailer = 'bug80706_x_mailer'; | ||
$headers = "From: {$from}\r\n" | ||
. "Bcc: {$bcc}\r\n" | ||
. "X-Mailer: {$xMailer}"; | ||
|
||
$res = mail($to, $subject, $message, $headers); | ||
|
||
if ($res !== true) { | ||
die("TEST FAILED : Unable to send test email\n"); | ||
exit("Unable to send the email.\n"); | ||
} else { | ||
echo "Message sent OK\n"; | ||
echo "Sent the email.\n"; | ||
} | ||
|
||
foreach ([$users[1], $users[2]] 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"; | ||
$res = searchEmailByToAddress($to); | ||
|
||
if ( | ||
$res && | ||
getFromAddress($res) === $from && | ||
getToAddresses($res)[0] === $to && | ||
getSubject($res) === $subject && | ||
getBody($res) === $message | ||
) { | ||
echo "Received the email.\n"; | ||
|
||
$recipients = getRecipientAddresses($res); | ||
|
||
if (in_array($bcc, $recipients, true)) { | ||
echo "bcc Received the email.\n"; | ||
} | ||
|
||
$headers = getHeaders($res); | ||
if ($headers['X-Mailer'][0] === $xMailer) { | ||
echo "The specified x-Mailer exists."; | ||
} | ||
|
||
deleteEmail($res); | ||
} | ||
?> | ||
--EXPECT-- | ||
Message sent OK | ||
X-Mailer header found: bool(true) | ||
TEST PASSED: Message sent and deleted OK | ||
X-Mailer header found: bool(true) | ||
TEST PASSED: Message sent and deleted OK | ||
Sent the email. | ||
Received the email. | ||
bcc Received the email. | ||
The specified x-Mailer exists. |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can probably remove this like, right?