bug80751.phpt 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. --TEST--
  2. Bug #80751 (Comma in recipient name breaks email delivery)
  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 "Return-Path header found: ";
  32. var_dump(strpos($header, 'Return-Path: joe@example.com') !== false);
  33. echo "To header found: ";
  34. var_dump(strpos($header, 'To: "<bob@example.com>" <info@mail.local>') !== false);
  35. echo "From header found: ";
  36. var_dump(strpos($header, 'From: "<bob@example.com>" <joe@example.com>') !== false);
  37. echo "Cc header found: ";
  38. var_dump(strpos($header, 'Cc: "Lastname, Firstname\\\\" <admin@mail.local>') !== false);
  39. imap_delete($imap_stream, $i);
  40. $found = true;
  41. break;
  42. }
  43. }
  44. $repeat_count--;
  45. }
  46. imap_close($imap_stream, CL_EXPUNGE);
  47. return $found;
  48. }
  49. $to = "\"<bob@example.com>\" <{$users[1]}@$domain>";
  50. $subject = bin2hex(random_bytes(16));
  51. $message = 'hello';
  52. $headers = "From: \"<bob@example.com>\" <joe@example.com>\r\n"
  53. . "Cc: \"Lastname, Firstname\\\\\" <{$users[2]}@$domain>\r\n"
  54. . "Bcc: \"Firstname \\\"Ni,ck\\\" Lastname\" <{$users[3]}@$domain>\r\n";
  55. $res = mail($to, $subject, $message, $headers);
  56. if ($res !== true) {
  57. die("TEST FAILED : Unable to send test email\n");
  58. } else {
  59. echo "Message sent OK\n";
  60. }
  61. foreach ([$users[1], $users[2], $users[3]] as $user) {
  62. if (!find_and_delete_message("$user@$domain", $subject)) {
  63. echo "TEST FAILED: email not delivered\n";
  64. } else {
  65. echo "TEST PASSED: Message sent and deleted OK\n";
  66. }
  67. }
  68. ?>
  69. --EXPECT--
  70. Message sent OK
  71. Return-Path header found: bool(true)
  72. To header found: bool(true)
  73. From header found: bool(true)
  74. Cc header found: bool(true)
  75. TEST PASSED: Message sent and deleted OK
  76. Return-Path header found: bool(true)
  77. To header found: bool(true)
  78. From header found: bool(true)
  79. Cc header found: bool(true)
  80. TEST PASSED: Message sent and deleted OK
  81. Return-Path header found: bool(true)
  82. To header found: bool(true)
  83. From header found: bool(true)
  84. Cc header found: bool(true)
  85. TEST PASSED: Message sent and deleted OK