diff --git a/.github/scripts/windows/build.bat b/.github/scripts/windows/build.bat index 65f40fb9462a7..df5ecc33ce09c 100644 --- a/.github/scripts/windows/build.bat +++ b/.github/scripts/windows/build.bat @@ -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%" ( diff --git a/.github/scripts/windows/test_task.bat b/.github/scripts/windows/test_task.bat index d7f76bfc483e0..af6d498ea198a 100644 --- a/.github/scripts/windows/test_task.bat +++ b/.github/scripts/windows/test_task.bat @@ -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 diff --git a/ext/standard/tests/mail/bug72964.phpt b/ext/standard/tests/mail/bug72964.phpt index bfe2b5eacbc7c..3b035fcfc3c59 100644 --- a/ext/standard/tests/mail/bug72964.phpt +++ b/ext/standard/tests/mail/bug72964.phpt @@ -1,77 +1,70 @@ --TEST-- Bug #72964 (White space not unfolded for CC/Bcc headers) ---EXTENSIONS-- -imap ---CONFLICTS-- -imap --SKIPIF-- --INI-- SMTP=localhost -smtp_port=25 +smtp_port=1025 +sendmail_from=from@example.com --FILE-- 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-- + --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. diff --git a/ext/standard/tests/mail/bug80706.phpt b/ext/standard/tests/mail/bug80706.phpt index e2774e924f067..7287294992689 100644 --- a/ext/standard/tests/mail/bug80706.phpt +++ b/ext/standard/tests/mail/bug80706.phpt @@ -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-- --INI-- SMTP=localhost -smtp_port=25 +smtp_port=1025 +sendmail_from=from@example.com --FILE-- 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-- + --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. diff --git a/ext/standard/tests/mail/bug80751.phpt b/ext/standard/tests/mail/bug80751.phpt index fd4fa744fe3ce..fcb1b407a44a8 100644 --- a/ext/standard/tests/mail/bug80751.phpt +++ b/ext/standard/tests/mail/bug80751.phpt @@ -1,97 +1,87 @@ --TEST-- Bug #80751 (Comma in recipient name breaks email delivery) ---EXTENSIONS-- -imap ---CONFLICTS-- -imap --SKIPIF-- --INI-- SMTP=localhost -smtp_port=25 +smtp_port=1025 --FILE-- \" <{$to}>"; - $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: joe@example.com') !== false); - echo "To header found: "; - var_dump(strpos($header, "To: \"\" <{$users[1]}@$domain>") !== false); - echo "From header found: "; - var_dump(strpos($header, 'From: "" ') !== false); - echo "Cc header found: "; - var_dump(strpos($header, "Cc: \"Lastname, Firstname\\\\\" <{$users[2]}@$domain>") !== false); - imap_delete($imap_stream, $i); - $found = true; - break; - } - } - $repeat_count--; - } +$from = 'bug80751_from@example.com'; +$fromLine = "\"\" <{$from}>"; - imap_close($imap_stream, CL_EXPUNGE); - return $found; -} +$cc = 'bug80751_cc@example.com'; +$ccLine = "\"Lastname, Firstname\\\\\" <{$cc}>"; -$to = "\"\" <{$users[1]}@$domain>"; +$bcc = 'bug80751_bcc@example.com'; $subject = bin2hex(random_bytes(16)); $message = 'hello'; -$headers = "From: \"\" \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); +$headers = "From: {$fromLine}\r\n" + . "Cc: {$ccLine}\r\n" + . "Bcc: \"Firstname \\\"Ni,ck\\\" Lastname\" <{$bcc}>\r\n"; + +$res = mail($toLine, $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], $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"; +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, $ccAddresses, true)) { + echo "cc is set.\n"; + } + + $bccAddresses = getBccAddresses($res); + if (in_array($bcc, $bccAddresses, true)) { + echo "bcc is set.\n"; + } + + if ($res['ReturnPath'] === $from) { + echo "Return-Path is as expected.\n"; + } + + $headers = getHeaders($res); + if ($headers['To'][0] === $toLine) { + echo "To header is as expected.\n"; + } + + if ($headers['From'][0] === $fromLine) { + echo "From header is as expected.\n"; + } + + if ($headers['Cc'][0] === $ccLine) { + echo "Cc header is as expected."; } } ?> +--CLEAN-- + --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 +Email sent. +Found the email sent. +cc is set. +bcc is set. +Return-Path is as expected. +To header is as expected. +From header is as expected. +Cc header is as expected. diff --git a/ext/standard/tests/mail/mail_basic_alt1-win32.phpt b/ext/standard/tests/mail/mail_basic_alt1-win32.phpt deleted file mode 100644 index a32f5a4443517..0000000000000 --- a/ext/standard/tests/mail/mail_basic_alt1-win32.phpt +++ /dev/null @@ -1,90 +0,0 @@ ---TEST-- -Test mail() function : basic functionality ---EXTENSIONS-- -imap ---CONFLICTS-- -imap ---SKIPIF-- - ---INI-- -max_execution_time = 120 ---FILE-- - 0) { - - // sleep for a while to allow msg to be delivered - sleep(1); - - $current_msg_count = imap_check($imap_stream)->Nmsgs; - - // Iterate over recent msgs to find the one we sent above - for ($i = 1; $i <= $current_msg_count; $i++) { - // get hdr details - $hdr = imap_headerinfo($imap_stream, $i); - - if (substr($hdr->Subject, 0 , strlen($subject_prefix)) == $subject_prefix) { - echo "Id of msg just sent is $i\n"; - echo ".. delete it\n"; - imap_delete($imap_stream, $i); - $found = true; - break; - } - } - - $repeat_count -= 1; -} - -if (!$found) { - echo "TEST FAILED: email not delivered\n"; -} else { - echo "TEST PASSED: Msgs sent and deleted OK\n"; -} - -imap_close($imap_stream, CL_EXPUNGE); -?> ---EXPECTF-- -*** Testing mail() : basic functionality *** -Msg sent OK -Id of msg just sent is %d -.. delete it -TEST PASSED: Msgs sent and deleted OK diff --git a/ext/standard/tests/mail/mail_basic_alt2-win32.phpt b/ext/standard/tests/mail/mail_basic_alt2-win32.phpt deleted file mode 100644 index 7ad202d22af63..0000000000000 --- a/ext/standard/tests/mail/mail_basic_alt2-win32.phpt +++ /dev/null @@ -1,87 +0,0 @@ ---TEST-- -Test mail() function : basic functionality ---EXTENSIONS-- -imap ---CONFLICTS-- -imap ---SKIPIF-- - ---INI-- -max_execution_time = 120 ---FILE-- - 0) { - - // sleep for a while to allow msg to be delivered - sleep(1); - - $current_msg_count = imap_check($imap_stream)->Nmsgs; - - // Iterate over recent msgs to find the one we sent above - for ($i = 1; $i <= $current_msg_count; $i++) { - // get hdr details - $hdr = imap_headerinfo($imap_stream, $i); - - if (substr($hdr->Subject, 0 , strlen($subject_prefix)) == $subject_prefix) { - echo "Id of msg just sent is $i\n"; - echo ".. delete it\n"; - imap_delete($imap_stream, $i); - $found = true; - break; - } - } - - $repeat_count -= 1; -} - -if (!$found) { - echo "TEST FAILED: email not delivered\n"; -} else { - echo "TEST PASSED: Msgs sent and deleted OK\n"; -} - -imap_close($imap_stream, CL_EXPUNGE); -?> ---EXPECTF-- -*** Testing mail() : basic functionality *** -Msg sent OK -Id of msg just sent is %d -.. delete it -TEST PASSED: Msgs sent and deleted OK diff --git a/ext/standard/tests/mail/mail_basic_alt3-win32.phpt b/ext/standard/tests/mail/mail_basic_alt3-win32.phpt deleted file mode 100644 index 15d4619257828..0000000000000 --- a/ext/standard/tests/mail/mail_basic_alt3-win32.phpt +++ /dev/null @@ -1,87 +0,0 @@ ---TEST-- -Test mail() function : basic functionality ---EXTENSIONS-- -imap ---CONFLICTS-- -imap ---SKIPIF-- - ---INI-- -max_execution_time = 120 ---FILE-- - 0) { - - // sleep for a while to allow msg to be delivered - sleep(1); - - $current_msg_count = imap_check($imap_stream)->Nmsgs; - - // Iterate over recent msgs to find the one we sent above - for ($i = 1; $i <= $current_msg_count; $i++) { - // get hdr details - $hdr = imap_headerinfo($imap_stream, $i); - - if (substr($hdr->Subject, 0 , strlen($subject_prefix)) == $subject_prefix) { - echo "Id of msg just sent is $i\n"; - echo ".. delete it\n"; - imap_delete($imap_stream, $i); - $found = true; - break; - } - } - - $repeat_count -= 1; -} - -if (!$found) { - echo "TEST FAILED: email not delivered\n"; -} else { - echo "TEST PASSED: Msgs sent and deleted OK\n"; -} - -imap_close($imap_stream, CL_EXPUNGE); -?> ---EXPECTF-- -*** Testing mail() : basic functionality *** -Msg sent OK -Id of msg just sent is %d -.. delete it -TEST PASSED: Msgs sent and deleted OK diff --git a/ext/standard/tests/mail/mail_basic_alt4-win32.phpt b/ext/standard/tests/mail/mail_basic_alt4-win32.phpt deleted file mode 100644 index 1fd41bf1928ff..0000000000000 --- a/ext/standard/tests/mail/mail_basic_alt4-win32.phpt +++ /dev/null @@ -1,88 +0,0 @@ ---TEST-- -Test mail() function : basic functionality ---EXTENSIONS-- -imap ---CONFLICTS-- -imap ---SKIPIF-- - ---INI-- -max_execution_time = 120 ---FILE-- - 0) { - - // sleep for a while to allow msg to be delivered - sleep(1); - - $current_msg_count = imap_check($imap_stream)->Nmsgs; - - // Iterate over recent msgs to find the one we sent above - for ($i = 1; $i <= $current_msg_count; $i++) { - // get hdr details - $hdr = imap_headerinfo($imap_stream, $i); - - if (substr($hdr->Subject, 0 , strlen($subject_prefix)) == $subject_prefix) { - echo "Id of msg just sent is $i\n"; - echo ".. delete it\n"; - imap_delete($imap_stream, $i); - $found = true; - break; - } - } - - $repeat_count -= 1; -} - -if (!$found) { - echo "TEST FAILED: email not delivered\n"; -} else { - echo "TEST PASSED: Msgs sent and deleted OK\n"; -} - -imap_close($imap_stream, CL_EXPUNGE); -?> ---EXPECTF-- -*** Testing mail() : basic functionality *** -Msg sent OK -Id of msg just sent is %d -.. delete it -TEST PASSED: Msgs sent and deleted OK diff --git a/ext/standard/tests/mail/mail_basic_win.phpt b/ext/standard/tests/mail/mail_basic_win.phpt new file mode 100644 index 0000000000000..2b524675be6fe --- /dev/null +++ b/ext/standard/tests/mail/mail_basic_win.phpt @@ -0,0 +1,97 @@ +--TEST-- +Test mail() function : basic functionality (win) +--SKIPIF-- + +--INI-- +SMTP=localhost +smtp_port=1025 +--FILE-- + 'from@example.com', + 'premise' => function ($from, $to, $subject, $message) { + ini_set('sendmail_from', $from); + return mail($to, $subject, $message); + } + ], + [ + 'from' => 'ex_from@example.com', + 'premise' => function ($from, $to, $subject, $message) { + ini_restore('sendmail_from'); + $headers = "from: {$from}"; + return mail($to, $subject, $message, $headers); + } + ], + [ + 'from' => 'ex_from@example.com', + 'premise' => function ($from, $to, $subject, $message) { + ini_restore('sendmail_from'); + $headers = "FRom: {$from}"; + return mail($to, $subject, $message, $headers); + } + ], + [ + 'from' => 'ex_from@example.com', + 'premise' => function ($from, $to, $subject, $message) { + ini_restore('sendmail_from'); + $headers = "from: {$from}"; + $parameters = 'addons'; // should be ignored + return mail($to, $subject, $message, $headers, $parameters); + } + ], +]; + +foreach ($cases as $index => ['from' => $from, 'premise' => $premise]) { + echo "========== Case {$index} ==========\n"; + + $to = "mail_basic_win_{$index}@example.com"; + $subject = "{$index}: Basic PHPT test for mail() function"; + $message = << +--CLEAN-- + +--EXPECT-- +========== Case 0 ========== +Email sent. +Found the email sent. + +========== Case 1 ========== +Email sent. +Found the email sent. + +========== Case 2 ========== +Email sent. +Found the email sent. + +========== Case 3 ========== +Email sent. +Found the email sent. diff --git a/ext/standard/tests/mail/mail_include.inc b/ext/standard/tests/mail/mail_include.inc deleted file mode 100644 index 60f84aa35cfe6..0000000000000 --- a/ext/standard/tests/mail/mail_include.inc +++ /dev/null @@ -1,150 +0,0 @@ -name == $mailbox) { - exit ("TEST FAILED : Mailbox '$mailbox' already exists\n"); - } - } - } - - if (imap_createmailbox($imap_stream, $mailbox) === false) { - return false; - } - - // Add number of test msgs requested - if ($message_count > 0) { - populate_mailbox($imap_stream, $mailbox, $message_count, $msg_type); - } - - return $mailbox; -} - -/** - * Populate a mailbox with generic emails - * - * @param resource $imap_stream - * @param string $mailbox - */ -function populate_mailbox($imap_stream, $mailbox, $message_count, $msg_type = "simple"){ - - global $users, $domain; - - for($i = 1; $i <= $message_count; $i++) { - if ($msg_type == "simple") { - $msg = "From: foo@anywhere.com\r\n" - . "To: $users[0]@$domain\r\n" - . "Subject: test$i\r\n" - . "\r\n" - . "$i: this is a test message, please ignore\r\n"; - } else { - $envelope["from"]= "foo@anywhere.com"; - $envelope["to"] = "$users[0]@$domain"; - $envelope["subject"] = "Test msg $i"; - - $part1["type"] = TYPEMULTIPART; - $part1["subtype"] = "mixed"; - - $part2["type"] = TYPETEXT; - $part2["subtype"] = "plain"; - $part2["description"] = "imap_mail_compose() function"; - $part2["contents.data"] = "message 1:xxxxxxxxxxxxxxxxxxxxxxxxxx"; - - $part3["type"] = TYPETEXT; - $part3["subtype"] = "plain"; - $part3["description"] = "Example"; - $part3["contents.data"] = "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy"; - - $part4["type"] = TYPETEXT; - $part4["subtype"] = "plain"; - $part4["description"] = "Return Values"; - $part4["contents.data"] = "message 3:zzzzzzzzzzzzzzzzzzzzzzzzzz"; - - $body[1] = $part1; - $body[2] = $part2; - $body[3] = $part3; - $body[4] = $part4; - - $msg = imap_mail_compose($envelope, $body); - } - - imap_append($imap_stream, $mailbox, $msg); - } -} - -/** - * Get the mailbox name from a mailbox description, i.e strip off server details. - * - * @param string mailbox complete mailbox name - * @return mailbox name - */ -function get_mailbox_name($mailbox){ - - if (preg_match('/\{.*?\}(.*)/', $mailbox, $match) != 1) { - echo "Unrecpognized mailbox name\n"; - return false; - } - - return $match[1]; -} - -?> diff --git a/ext/standard/tests/mail/mail_skipif.inc b/ext/standard/tests/mail/mail_skipif.inc deleted file mode 100644 index 83e42817a0a7f..0000000000000 --- a/ext/standard/tests/mail/mail_skipif.inc +++ /dev/null @@ -1,25 +0,0 @@ - 10, 'usec' => 10)); - // imap uses tcp port 143 - socket_connect($socket, "localhost", 143) or die ("skip can't socket to mail server"); -} - -// Change these to make tests run successfully -$mailbox = '{127.0.0.1:143}'; -$username = 'webmaster@example.com'; -$password = 'p4ssw0rd'; -$options = OP_HALFOPEN; // this should be enough to verify server present -$retries = 0; // don't retry connect on failure - -$mbox = @imap_open($mailbox, $username, $password, $options, $retries); -if (!$mbox) { - die("skip could not connect to mailbox $mailbox"); -} -imap_close($mbox); -?> diff --git a/ext/standard/tests/mail/mail_variation_alt1-win32.phpt b/ext/standard/tests/mail/mail_variation_alt1-win32.phpt deleted file mode 100644 index 5551fb3a843fc..0000000000000 --- a/ext/standard/tests/mail/mail_variation_alt1-win32.phpt +++ /dev/null @@ -1,89 +0,0 @@ ---TEST-- -Test mail() function : basic functionality ---EXTENSIONS-- -imap ---CONFLICTS-- -imap ---SKIPIF-- - ---INI-- -max_execution_time = 120 ---FILE-- - 0) { - - // sleep for a while to allow msg to be delivered - sleep(1); - - $current_msg_count = imap_check($imap_stream)->Nmsgs; - - // Iterate over recent msgs to find the one we sent above - for ($i = 1; $i <= $current_msg_count; $i++) { - // get hdr details - $hdr = imap_headerinfo($imap_stream, $i); - - if (substr($hdr->Subject, 0 , strlen($subject_prefix)) == $subject_prefix) { - echo "Id of msg just sent is $i\n"; - echo ".. delete it\n"; - imap_delete($imap_stream, $i); - $found = true; - break; - } - } - - $repeat_count -= 1; -} - -if (!$found) { - echo "TEST FAILED: email not delivered\n"; -} else { - echo "TEST PASSED: Msgs sent and deleted OK\n"; -} - -imap_close($imap_stream, CL_EXPUNGE); -?> -===DONE=== ---EXPECTF-- -*** Testing mail() : basic functionality *** - -Warning: mail(): Failed to connect to mailserver at "localhost" port 2525, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in %s on line %d -TEST COMPLETED : Unable to send test email diff --git a/ext/standard/tests/mail/mail_variation_alt2-win32.phpt b/ext/standard/tests/mail/mail_variation_alt2-win32.phpt deleted file mode 100644 index 38c90fd037190..0000000000000 --- a/ext/standard/tests/mail/mail_variation_alt2-win32.phpt +++ /dev/null @@ -1,89 +0,0 @@ ---TEST-- -Test mail() function : basic functionality ---EXTENSIONS-- -imap ---CONFLICTS-- -imap ---SKIPIF-- - ---INI-- -max_execution_time = 120 ---FILE-- - 0) { - - // sleep for a while to allow msg to be delivered - sleep(1); - - $current_msg_count = imap_check($imap_stream)->Nmsgs; - - // Iterate over recent msgs to find the one we sent above - for ($i = 1; $i <= $current_msg_count; $i++) { - // get hdr details - $hdr = imap_headerinfo($imap_stream, $i); - - if (substr($hdr->Subject, 0 , strlen($subject_prefix)) == $subject_prefix) { - echo "Id of msg just sent is $i\n"; - echo ".. delete it\n"; - imap_delete($imap_stream, $i); - $found = true; - break; - } - } - - $repeat_count -= 1; -} - -if (!$found) { - echo "TEST FAILED: email not delivered\n"; -} else { - echo "TEST PASSED: Msgs sent and deleted OK\n"; -} - -imap_close($imap_stream, CL_EXPUNGE); -?> -===DONE=== ---EXPECTF-- -*** Testing mail() : basic functionality *** - -Warning: mail(): Failed to connect to mailserver at "localplace" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in %s on line %d -TEST COMPLETED : Unable to send test email diff --git a/ext/standard/tests/mail/mail_variation_alt3-win32.phpt b/ext/standard/tests/mail/mail_variation_alt3-win32.phpt deleted file mode 100644 index f4b2bf4a8e63a..0000000000000 --- a/ext/standard/tests/mail/mail_variation_alt3-win32.phpt +++ /dev/null @@ -1,88 +0,0 @@ ---TEST-- -Test mail() function : basic functionality ---EXTENSIONS-- -imap ---CONFLICTS-- -imap ---SKIPIF-- - ---INI-- -max_execution_time = 120 ---FILE-- - 0) { - - // sleep for a while to allow msg to be delivered - sleep(1); - - $current_msg_count = imap_check($imap_stream)->Nmsgs; - - // Iterate over recent msgs to find the one we sent above - for ($i = 1; $i <= $current_msg_count; $i++) { - // get hdr details - $hdr = imap_headerinfo($imap_stream, $i); - - if (substr($hdr->Subject, 0 , strlen($subject_prefix)) == $subject_prefix) { - echo "Id of msg just sent is $i\n"; - echo ".. delete it\n"; - imap_delete($imap_stream, $i); - $found = true; - break; - } - } - - $repeat_count -= 1; -} - -if (!$found) { - echo "TEST FAILED: email not delivered\n"; -} else { - echo "TEST PASSED: Msgs sent and deleted OK\n"; -} - -imap_close($imap_stream, CL_EXPUNGE); -?> -===DONE=== ---EXPECTF-- -*** Testing mail() : basic functionality *** - -Warning: mail(): Bad Message Return Path in %s on line %d -TEST COMPLETED : Unable to send test email diff --git a/ext/standard/tests/mail/mail_variation_win.phpt b/ext/standard/tests/mail/mail_variation_win.phpt new file mode 100644 index 0000000000000..34c6868fe12fa --- /dev/null +++ b/ext/standard/tests/mail/mail_variation_win.phpt @@ -0,0 +1,84 @@ +--TEST-- +Test mail() function : basic functionality (win) +--SKIPIF-- + +--INI-- +SMTP=localhost +smtp_port=1025 +--FILE-- + 'From is not set', + 'premise' => function () { + ini_set('SMTP', 'localhost'); + ini_set('smtp_port', 1025); + } + ], + [ + 'label' => 'Invalid port', + 'premise' => function () { + ini_set('SMTP', 'localhost'); + ini_set('smtp_port', 2525); + ini_set('sendmail_from', 'from@example.com'); + } + ], + [ + 'label' => 'Invalid host', + 'premise' => function () { + ini_set('SMTP', 'localplace'); + ini_set('smtp_port', 1025); + ini_set('sendmail_from', 'from@example.com'); + } + ], +]; + +foreach ($cases as $index => ['label' => $label, 'premise' => $premise]) { + echo "========== {$label} ==========\n"; + + $premise(); + + $to = "mail_variation_win_{$index}@example.com"; + $subject = "{$index}: Basic PHPT test for mail() function"; + $message = << +--CLEAN-- + +--EXPECTF-- +========== From is not set ========== + +Warning: mail(): Bad Message Return Path in %s on line %d +========== Invalid port ========== + +Warning: mail(): Failed to connect to mailserver at "localhost" port 2525, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in %s on line %d +========== Invalid host ========== + +Warning: mail(): Failed to connect to mailserver at "localplace" port 1025, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in %s on line %d + diff --git a/ext/standard/tests/mail/mail_windows_skipif.inc b/ext/standard/tests/mail/mail_windows_skipif.inc new file mode 100644 index 0000000000000..2ff2fc03a6b5d --- /dev/null +++ b/ext/standard/tests/mail/mail_windows_skipif.inc @@ -0,0 +1,14 @@ + diff --git a/ext/standard/tests/mail/mailpit_utils.inc b/ext/standard/tests/mail/mailpit_utils.inc new file mode 100644 index 0000000000000..eb057953007c0 --- /dev/null +++ b/ext/standard/tests/mail/mailpit_utils.inc @@ -0,0 +1,52 @@ + [ + 'method' => 'DELETE', + ], + ])); +} +?>