|
1 | 1 | --TEST--
|
2 | 2 | Bug #80751 (Comma in recipient name breaks email delivery)
|
3 |
| ---EXTENSIONS-- |
4 |
| -imap |
5 |
| ---CONFLICTS-- |
6 |
| -imap |
7 | 3 | --SKIPIF--
|
8 | 4 | <?php
|
9 |
| -if (PHP_OS_FAMILY !== 'Windows') die('skip Windows only test'); |
10 | 5 | if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
|
11 |
| -require_once __DIR__ . '/mail_skipif.inc'; |
| 6 | +require_once __DIR__.'/mail_windows_skipif.inc'; |
12 | 7 | ?>
|
13 | 8 | --INI--
|
14 | 9 | SMTP=localhost
|
15 |
| -smtp_port=25 |
| 10 | +smtp_port=1025 |
16 | 11 | --FILE--
|
17 | 12 | <?php
|
18 |
| -require_once __DIR__ . '/mail_include.inc'; |
19 | 13 |
|
20 |
| -function find_and_delete_message($username, $subject) { |
21 |
| - global $default_mailbox, $password, $users, $domain; |
| 14 | +require_once __DIR__.'/mailpit_utils.inc'; |
22 | 15 |
|
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 |
| - } |
| 16 | +$to = 'bug80751_to@example.com'; |
| 17 | +$toLine = "\"<bug80751_to_name@example.com>\" <{$to}>"; |
27 | 18 |
|
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 |
| - $header = imap_fetchheader($imap_stream, $i); |
39 |
| - echo "Return-Path header found: "; |
40 |
| - var_dump(strpos($header, 'Return-Path: joe@example.com') !== false); |
41 |
| - echo "To header found: "; |
42 |
| - var_dump(strpos($header, "To: \"<bob@example.com>\" <{$users[1]}@$domain>") !== false); |
43 |
| - echo "From header found: "; |
44 |
| - var_dump(strpos($header, 'From: "<bob@example.com>" <joe@example.com>') !== false); |
45 |
| - echo "Cc header found: "; |
46 |
| - var_dump(strpos($header, "Cc: \"Lastname, Firstname\\\\\" <{$users[2]}@$domain>") !== false); |
47 |
| - imap_delete($imap_stream, $i); |
48 |
| - $found = true; |
49 |
| - break; |
50 |
| - } |
51 |
| - } |
52 |
| - $repeat_count--; |
53 |
| - } |
| 19 | +$from = 'bug80751_from@example.com'; |
| 20 | +$fromLine = "\"<bug80751_from_name@example.com>\" <{$from}>"; |
54 | 21 |
|
55 |
| - imap_close($imap_stream, CL_EXPUNGE); |
56 |
| - return $found; |
57 |
| -} |
| 22 | +$cc = 'bug80751_cc@example.com'; |
| 23 | +$ccLine = "\"Lastname, Firstname\\\\\" <{$cc}>"; |
58 | 24 |
|
59 |
| -$to = "\"<bob@example.com>\" <{$users[1]}@$domain>"; |
| 25 | +$bcc = 'bug80751_bcc@example.com'; |
60 | 26 | $subject = bin2hex(random_bytes(16));
|
61 | 27 | $message = 'hello';
|
62 |
| -$headers = "From: \"<bob@example.com>\" <joe@example.com>\r\n" |
63 |
| - . "Cc: \"Lastname, Firstname\\\\\" <{$users[2]}@$domain>\r\n" |
64 |
| - . "Bcc: \"Firstname \\\"Ni,ck\\\" Lastname\" <{$users[3]}@$domain>\r\n"; |
65 | 28 |
|
66 |
| -$res = mail($to, $subject, $message, $headers); |
| 29 | +$headers = "From: {$fromLine}\r\n" |
| 30 | + . "Cc: {$ccLine}\r\n" |
| 31 | + . "Bcc: \"Firstname \\\"Ni,ck\\\" Lastname\" <{$bcc}>\r\n"; |
| 32 | + |
| 33 | +$res = mail($toLine, $subject, $message, $headers); |
| 34 | + |
67 | 35 | if ($res !== true) {
|
68 |
| - die("TEST FAILED : Unable to send test email\n"); |
| 36 | + exit("Unable to send the email.\n"); |
69 | 37 | } else {
|
70 |
| - echo "Message sent OK\n"; |
| 38 | + echo "Sent the email.\n"; |
71 | 39 | }
|
72 | 40 |
|
73 |
| -foreach ([$users[1], $users[2], $users[3]] as $user) { |
74 |
| - if (!find_and_delete_message("$user@$domain", $subject)) { |
75 |
| - echo "TEST FAILED: email not delivered\n"; |
76 |
| - } else { |
77 |
| - echo "TEST PASSED: Message sent and deleted OK\n"; |
| 41 | +$res = searchEmailByToAddress($to); |
| 42 | + |
| 43 | +if (mailCheckResponse($res, $from, $to, $subject, $message)) { |
| 44 | + echo "Received the email.\n"; |
| 45 | + |
| 46 | + $ccAddresses = getCcAddresses($res); |
| 47 | + if (in_array($cc, $ccAddresses, true)) { |
| 48 | + echo "cc Received the email.\n"; |
| 49 | + } |
| 50 | + |
| 51 | + $bccAddresses = getBccAddresses($res); |
| 52 | + if (in_array($bcc, $bccAddresses, true)) { |
| 53 | + echo "bcc Receive the email.\n"; |
78 | 54 | }
|
| 55 | + |
| 56 | + if ($res['ReturnPath'] === $from) { |
| 57 | + echo "Return-Path is as expected.\n"; |
| 58 | + } |
| 59 | + |
| 60 | + $headers = getHeaders($res); |
| 61 | + if ($headers['To'][0] === $toLine) { |
| 62 | + echo "To header is as expected.\n"; |
| 63 | + } |
| 64 | + |
| 65 | + if ($headers['From'][0] === $fromLine) { |
| 66 | + echo "From header is as expected.\n"; |
| 67 | + } |
| 68 | + |
| 69 | + if ($headers['Cc'][0] === $ccLine) { |
| 70 | + echo "Cc header is as expected."; |
| 71 | + } |
| 72 | + |
| 73 | + deleteEmail($res); |
79 | 74 | }
|
80 | 75 | ?>
|
81 | 76 | --EXPECT--
|
82 |
| -Message sent OK |
83 |
| -Return-Path header found: bool(true) |
84 |
| -To header found: bool(true) |
85 |
| -From header found: bool(true) |
86 |
| -Cc header found: bool(true) |
87 |
| -TEST PASSED: Message sent and deleted OK |
88 |
| -Return-Path header found: bool(true) |
89 |
| -To header found: bool(true) |
90 |
| -From header found: bool(true) |
91 |
| -Cc header found: bool(true) |
92 |
| -TEST PASSED: Message sent and deleted OK |
93 |
| -Return-Path header found: bool(true) |
94 |
| -To header found: bool(true) |
95 |
| -From header found: bool(true) |
96 |
| -Cc header found: bool(true) |
97 |
| -TEST PASSED: Message sent and deleted OK |
| 77 | +Sent the email. |
| 78 | +Received the email. |
| 79 | +cc Received the email. |
| 80 | +bcc Receive the email. |
| 81 | +Return-Path is as expected. |
| 82 | +To header is as expected. |
| 83 | +From header is as expected. |
| 84 | +Cc header is as expected. |
0 commit comments