xref: /PHP-8.2/ext/standard/tests/mail/bug72964.phpt (revision 8e2c08c5)
1--TEST--
2Bug #72964 (White space not unfolded for CC/Bcc headers)
3--EXTENSIONS--
4imap
5--CONFLICTS--
6imap
7--SKIPIF--
8<?php
9if (PHP_OS_FAMILY !== 'Windows') die('skip Windows only test');
10if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
11require_once __DIR__ . '/mail_skipif.inc';
12?>
13--INI--
14SMTP=localhost
15smtp_port=25
16--FILE--
17<?php
18require_once __DIR__ . '/mail_include.inc';
19
20function find_and_delete_message($username, $subject) {
21    global $default_mailbox, $password;
22
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";
51$subject = bin2hex(random_bytes(16));
52$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";
56
57$res = mail($to, $subject, $message, $headers);
58if ($res !== true) {
59	die("TEST FAILED : Unable to send test email\n");
60} else {
61	echo "Message sent OK\n";
62}
63
64foreach ($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";
69    }
70}
71?>
72--EXPECT--
73Message sent OK
74TEST PASSED: Message sent and deleted OK
75TEST PASSED: Message sent and deleted OK
76TEST PASSED: Message sent and deleted OK
77TEST PASSED: Message sent and deleted OK
78