|
1 | 1 | --TEST--
|
2 | 2 | Bug #72964 (White space not unfolded for CC/Bcc headers)
|
3 | 3 | --EXTENSIONS--
|
4 |
| -imap |
5 |
| ---CONFLICTS-- |
6 |
| -imap |
| 4 | +curl |
7 | 5 | --SKIPIF--
|
8 | 6 | <?php
|
9 |
| -if (PHP_OS_FAMILY !== 'Windows') die('skip Windows only test'); |
10 | 7 | if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
|
11 |
| -require_once __DIR__ . '/mail_skipif.inc'; |
| 8 | +require_once __DIR__.'/mail_windows_skipif.inc'; |
12 | 9 | ?>
|
13 | 10 | --INI--
|
14 | 11 | SMTP=localhost
|
15 |
| -smtp_port=25 |
| 12 | +smtp_port=1025 |
| 13 | +sendmail_from=from@example.com |
16 | 14 | --FILE--
|
17 | 15 | <?php
|
18 |
| -require_once __DIR__ . '/mail_include.inc'; |
19 | 16 |
|
20 |
| -function find_and_delete_message($username, $subject) { |
21 |
| - global $default_mailbox, $password; |
| 17 | +require_once __DIR__.'/mailhog_utils.inc'; |
22 | 18 |
|
23 |
| - $imap_stream = imap_open($default_mailbox, $username, $password); |
24 |
| - if ($imap_stream === false) { |
25 |
| - die("Cannot connect to IMAP server $server: " . imap_last_error() . "\n"); |
26 |
| - } |
27 |
| - |
28 |
| - $found = false; |
29 |
| - $repeat_count = 20; // we will repeat a max of 20 times |
30 |
| - while (!$found && $repeat_count > 0) { |
31 |
| - // sleep for a while to allow msg to be delivered |
32 |
| - sleep(1); |
33 |
| - |
34 |
| - $num_messages = imap_check($imap_stream)->Nmsgs; |
35 |
| - for ($i = $num_messages; $i > 0; $i--) { |
36 |
| - $info = imap_headerinfo($imap_stream, $i); |
37 |
| - if ($info->subject === $subject) { |
38 |
| - imap_delete($imap_stream, $i); |
39 |
| - $found = true; |
40 |
| - break; |
41 |
| - } |
42 |
| - } |
43 |
| - $repeat_count--; |
44 |
| - } |
45 |
| - |
46 |
| - imap_close($imap_stream, CL_EXPUNGE); |
47 |
| - return $found; |
48 |
| -} |
49 |
| - |
50 |
| -$to = "{$users[2]}@$domain"; |
| 19 | +$to = 'bug72964_to@example.com'; |
| 20 | +$from = ini_get('sendmail_from'); |
| 21 | +$cc = ['bug72964_cc_1@example.com', 'bug72964_cc_2@example.com']; |
| 22 | +$bcc = ['bug72964_bcc_1@example.com', 'bug72964_bcc_2@example.com']; |
51 | 23 | $subject = bin2hex(random_bytes(16));
|
52 | 24 | $message = 'hello';
|
53 |
| -$headers = "From: webmaster@example.com\r\n" |
54 |
| - . "Cc: {$users[0]}@$domain,\r\n\t{$users[1]}@$domain\r\n" |
55 |
| - . "Bcc: {$users[2]}@$domain,\r\n {$users[3]}@$domain\r\n"; |
| 25 | +$headers = "From: {$from}\r\n" |
| 26 | + . "Cc: {$cc[0]},\r\n\t{$cc[1]}\r\n" |
| 27 | + . "Bcc: {$bcc[0]},\r\n {$bcc[1]}\r\n"; |
56 | 28 |
|
57 | 29 | $res = mail($to, $subject, $message, $headers);
|
| 30 | + |
58 | 31 | if ($res !== true) {
|
59 |
| - die("TEST FAILED : Unable to send test email\n"); |
| 32 | + exit("Unable to send the email.\n"); |
60 | 33 | } else {
|
61 |
| - echo "Message sent OK\n"; |
| 34 | + echo "Sent the email.\n"; |
62 | 35 | }
|
63 | 36 |
|
64 |
| -foreach ($users as $user) { |
65 |
| - if (!find_and_delete_message("$user@$domain", $subject)) { |
66 |
| - echo "TEST FAILED: email not delivered\n"; |
67 |
| - } else { |
68 |
| - echo "TEST PASSED: Message sent and deleted OK\n"; |
| 37 | +$res = searchEmailByToAddress($to); |
| 38 | + |
| 39 | +if ( |
| 40 | + $res && |
| 41 | + getFromAddress($res) === $from && |
| 42 | + getToAddresses($res)[0] === $to && |
| 43 | + getSubject($res) === $subject && |
| 44 | + getBody($res) === "\r\n".$message // The last newline in the header goes in first. |
| 45 | +) { |
| 46 | + echo "Received the email.\n"; |
| 47 | + |
| 48 | + $recipients = getRecipientAddresses($res); |
| 49 | + |
| 50 | + if (in_array($cc[0], $recipients, true)) { |
| 51 | + echo "cc1 Received the email.\n"; |
| 52 | + } |
| 53 | + |
| 54 | + if (in_array($cc[1], $recipients, true)) { |
| 55 | + echo "cc2 Received the email.\n"; |
| 56 | + } |
| 57 | + |
| 58 | + if (in_array($bcc[0], $recipients, true)) { |
| 59 | + echo "bcc1 Received the email.\n"; |
| 60 | + } |
| 61 | + |
| 62 | + if (in_array($bcc[1], $recipients, true)) { |
| 63 | + echo "bcc2 Received the email."; |
69 | 64 | }
|
| 65 | + |
| 66 | + deleteEmail($res); |
70 | 67 | }
|
71 | 68 | ?>
|
72 | 69 | --EXPECT--
|
73 |
| -Message sent OK |
74 |
| -TEST PASSED: Message sent and deleted OK |
75 |
| -TEST PASSED: Message sent and deleted OK |
76 |
| -TEST PASSED: Message sent and deleted OK |
77 |
| -TEST PASSED: Message sent and deleted OK |
| 70 | +Sent the email. |
| 71 | +Received the email. |
| 72 | +cc1 Received the email. |
| 73 | +cc2 Received the email. |
| 74 | +bcc1 Received the email. |
| 75 | +bcc2 Received the email. |
0 commit comments