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