bug72964.phpt 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. imap_delete($imap_stream, $i);
  31. $found = true;
  32. break;
  33. }
  34. }
  35. $repeat_count--;
  36. }
  37. imap_close($imap_stream, CL_EXPUNGE);
  38. return $found;
  39. }
  40. $to = "{$users[2]}@$domain";
  41. $subject = bin2hex(random_bytes(16));
  42. $message = 'hello';
  43. $headers = "From: webmaster@example.com\r\n"
  44. . "Cc: {$users[0]}@$domain,\r\n\t{$users[1]}@$domain\r\n"
  45. . "Bcc: {$users[2]}@$domain,\r\n {$users[3]}@$domain\r\n";
  46. $res = mail($to, $subject, $message, $headers);
  47. if ($res !== true) {
  48. die("TEST FAILED : Unable to send test email\n");
  49. } else {
  50. echo "Message sent OK\n";
  51. }
  52. foreach ($users as $user) {
  53. if (!find_and_delete_message("$user@$domain", $subject)) {
  54. echo "TEST FAILED: email not delivered\n";
  55. } else {
  56. echo "TEST PASSED: Message sent and deleted OK\n";
  57. }
  58. }
  59. ?>
  60. --EXPECT--
  61. Message sent OK
  62. TEST PASSED: Message sent and deleted OK
  63. TEST PASSED: Message sent and deleted OK
  64. TEST PASSED: Message sent and deleted OK
  65. TEST PASSED: Message sent and deleted OK