Skip to content

Replaced imap with mailpit and refreshed the test. #13219

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/scripts/windows/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ if /i "%GITHUB_ACTIONS%" neq "True" (
exit /b 3
)

set SDK_REMOTE=https://github.com/php/php-sdk-binary-tools.git
set SDK_BRANCH=%PHP_BUILD_SDK_BRANCH%
set SDK_REMOTE=https://github.com/SakiTakamachi/php-sdk-binary-tools.git
set SDK_BRANCH=test_mailpit
set SDK_RUNNER=%PHP_BUILD_CACHE_SDK_DIR%\phpsdk-%PHP_BUILD_CRT%-%PLATFORM%.bat

if not exist "%PHP_BUILD_CACHE_BASE_DIR%" (
Expand Down
5 changes: 1 addition & 4 deletions .github/scripts/windows/test_task.bat
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ set PHP_BUILD_DIR=%PHP_BUILD_OBJ_DIR%\Release
if "%THREAD_SAFE%" equ "1" set PHP_BUILD_DIR=%PHP_BUILD_DIR%_TS

rem prepare for mail
curl -sLo hMailServer.exe https://www.hmailserver.com/download_file/?downloadid=271
hMailServer.exe /verysilent
cd %APPVEYOR_BUILD_FOLDER%
%PHP_BUILD_DIR%\php.exe -dextension_dir=%PHP_BUILD_DIR% -dextension=com_dotnet appveyor\setup_hmailserver.php
start %PHP_BUILD_CACHE_SDK_DIR%\bin\mailpit_amd.exe

mkdir %PHP_BUILD_DIR%\test_file_cache
rem generate php.ini
Expand Down
101 changes: 47 additions & 54 deletions ext/standard/tests/mail/bug72964.phpt
Original file line number Diff line number Diff line change
@@ -1,77 +1,70 @@
--TEST--
Bug #72964 (White space not unfolded for CC/Bcc headers)
--EXTENSIONS--
imap
--CONFLICTS--
imap
--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__.'/mailpit_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");
} else {
echo "Message sent OK\n";
exit("Unable to send 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";
echo "Email sent.\n";

$res = searchEmailByToAddress($to);

if (mailCheckResponse($res, $from, $to, $subject, $message)) {
echo "Found the email sent.\n";

$ccAddresses = getCcAddresses($res);
if (in_array($cc[0], $ccAddresses, true)) {
echo "cc1 is set.\n";
}

if (in_array($cc[1], $ccAddresses, true)) {
echo "cc2 is set.\n";
}

$bccAddresses = getBccAddresses($res);
if (in_array($bcc[0], $bccAddresses, true)) {
echo "bcc1 is set.\n";
}

if (in_array($bcc[1], $bccAddresses, true)) {
echo "bcc2 is set.";
}
}
?>
--CLEAN--
<?php
require_once __DIR__.'/mailpit_utils.inc';
deleteEmailByToAddress('bug72964_to@example.com');
?>
--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
Email sent.
Found the email sent.
cc1 is set.
cc2 is set.
bcc1 is set.
bcc2 is set.
96 changes: 38 additions & 58 deletions ext/standard/tests/mail/bug80706.phpt
Original file line number Diff line number Diff line change
@@ -1,80 +1,60 @@
--TEST--
Bug #72964 (White space not unfolded for CC/Bcc headers)
--EXTENSIONS--
imap
--CONFLICTS--
imap
Bug #80706 (Headers after Bcc headers may be ignored)
--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__.'/mailpit_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");
} else {
echo "Message sent OK\n";
exit("Unable to send 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";
echo "Email sent.\n";

$res = searchEmailByToAddress($to);

if (mailCheckResponse($res, $from, $to, $subject, $message)) {
echo "Found the email sent.\n";

$bccAddresses = getBccAddresses($res);
if (in_array($bcc, $bccAddresses, true)) {
echo "bcc is set.\n";
}

$headers = getHeaders($res);
if ($headers['X-Mailer'][0] === $xMailer) {
echo "The specified x-Mailer exists.";
}
}
?>
--CLEAN--
<?php
require_once __DIR__.'/mailpit_utils.inc';
deleteEmailByToAddress('bug72964_to@example.com');
?>
--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
Email sent.
Found the email sent.
bcc is set.
The specified x-Mailer exists.
Loading