bug80706.phpt 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. function find_and_delete_message($username, $subject) {
  16. global $default_mailbox, $password;
  17. $imap_stream = imap_open($default_mailbox, $username, $password);
  18. if ($imap_stream === false) {
  19. die("Cannot connect to IMAP server $server: " . imap_last_error() . "\n");
  20. }
  21. $found = false;
  22. $repeat_count = 20; // we will repeat a max of 20 times
  23. while (!$found && $repeat_count > 0) {
  24. // sleep for a while to allow msg to be delivered
  25. sleep(1);
  26. $num_messages = imap_check($imap_stream)->Nmsgs;
  27. for ($i = $num_messages; $i > 0; $i--) {
  28. $info = imap_headerinfo($imap_stream, $i);
  29. if ($info->subject === $subject) {
  30. $header = imap_fetchheader($imap_stream, $i);
  31. echo "X-Mailer header found: ";
  32. var_dump(strpos($header, 'X-Mailer: bug80706') !== false);
  33. imap_delete($imap_stream, $i);
  34. $found = true;
  35. break;
  36. }
  37. }
  38. $repeat_count--;
  39. }
  40. imap_close($imap_stream, CL_EXPUNGE);
  41. return $found;
  42. }
  43. $to = "{$users[1]}@$domain";
  44. $subject = bin2hex(random_bytes(16));
  45. $message = 'hello';
  46. $headers = "From: webmaster@example.com\r\n"
  47. . "Bcc: {$users[2]}@$domain\r\n"
  48. . "X-Mailer: bug80706";
  49. $res = mail($to, $subject, $message, $headers);
  50. if ($res !== true) {
  51. die("TEST FAILED : Unable to send test email\n");
  52. } else {
  53. echo "Message sent OK\n";
  54. }
  55. foreach ([$users[1], $users[2]] as $user) {
  56. if (!find_and_delete_message("$user@$domain", $subject)) {
  57. echo "TEST FAILED: email not delivered\n";
  58. } else {
  59. echo "TEST PASSED: Message sent and deleted OK\n";
  60. }
  61. }
  62. ?>
  63. --EXPECT--
  64. Message sent OK
  65. X-Mailer header found: bool(true)
  66. TEST PASSED: Message sent and deleted OK
  67. X-Mailer header found: bool(true)
  68. TEST PASSED: Message sent and deleted OK