-
Notifications
You must be signed in to change notification settings - Fork 7.8k
/
Copy pathmail_basic7.phpt
261 lines (217 loc) · 7.75 KB
/
mail_basic7.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
--TEST--
Test mail() function : array extra header basic functionality
--INI--
sendmail_path={MAIL:mailBasic7.out}
mail.add_x_header = Off
--FILE--
<?php
error_reporting(-1);
echo "*** Testing mail() : basic functionality ***\n";
echo "\n\n************* TEST ******************\n";
// Should pass
// Initialise all required variables
$to = 'user@example.com';
$subject = 'Test Subject';
$message = 'A Message';
$additional_headers = array(
'KHeaders' => 'aaaa',
'bcc'=>'foo@bar',
'foo'=>
array(
"bar\r\n hoge",
"bar\r\n\t fuga",
),
);
$outFile = "mailBasic7.out";
@unlink($outFile);
echo "-- All Mail Content Parameters --\n";
// Calling mail() with all additional headers
var_dump(mail($to, $subject, $message, $additional_headers));
echo file_get_contents($outFile);
unlink($outFile);
echo "\n\n************* TEST ******************\n";
// Should fail all
// Initialise all required variables
$to = 'user@example.com';
$subject = 'Test Subject';
$message = 'A Message';
try {
mail($to, $subject, $message, ['orig-date' => array('foo1')]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
try {
mail($to, $subject, $message, ['from' => array('foo2')]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
try {
mail($to, $subject, $message, ['sender' => array('foo3')]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
try {
mail($to, $subject, $message, ['reply-to' => array('foo4')]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
try {
mail($to, $subject, $message, ['to' => array('foo5')]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
try {
mail($to, $subject, $message, ['bcc' => array('foo6')]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
try {
mail($to, $subject, $message, ['message-id' => array('foo7')]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
try {
mail($to, $subject, $message, ['in-reply-to'=> array('foo8')]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
echo "\n\n************* TEST ******************\n";
// Should fail all
// Initialise all required variables
$to = 'user@example.com';
$subject = 'Test Subject';
$message = 'A Message';
try {
mail($to, $subject, $message, ['foo1' => array('foo2'=>'bar1')]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
try {
mail($to, $subject, $message, ['foo2' => array('foo2', array('foo3'))]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
try {
mail($to, $subject, $message, ['foo3' => array(123)]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
try {
mail($to, $subject, $message, ['foo4' => array(123.456)]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
try {
mail($to, $subject, $message, ['foo5' => array(FALSE)]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
try {
mail($to, $subject, $message, ['foo6' => array(NULL)]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
try {
mail($to, $subject, $message, ['foo7' => array(new StdClass)]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
echo "\n\n************* TEST ******************\n";
// Should fail most
// Initialise all required variables
$to = 'user@example.com';
$subject = 'Test Subject';
$message = 'A Message';
$outFile = "mailBasic7.out";
@unlink($outFile);
try {
mail($to, $subject, $message, ['*:foo1' => array('bar1')]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
try {
mail($to, $subject, $message, ['foo2:::' => array('bar1')]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
try {
mail($to, $subject, $message, ['foo3()' => array('bar1')]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
try {
mail($to, $subject, $message, ['foo4@' => array('bar1')]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
try {
mail($to, $subject, $message, ['foo5|' => array('bar1')]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
try {
mail($to, $subject, $message, ["\0foo6" => array('bar1')]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
try {
mail($to, $subject, $message, ["foo7\0" => array('bar1')]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
try {
mail($to, $subject, $message, ["foo8" => array()]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
var_dump(mail($to, $subject, $message, ["foo9" => '%&$#!']));
echo file_get_contents($outFile);
unlink($outFile);
try {
mail($to, $subject, $message, ["foo10" => "abc\0\tdef"]);
} catch (TypeError|ValueError $exception) {
echo get_class($exception) . ": " . $exception->getMessage() . "\n";
}
?>
--EXPECT--
*** Testing mail() : basic functionality ***
************* TEST ******************
-- All Mail Content Parameters --
bool(true)
To: user@example.com
Subject: Test Subject
KHeaders: aaaa
bcc: foo@bar
foo: bar
hoge
foo: bar
fuga
A Message
************* TEST ******************
TypeError: Header "orig-date" must be of type string, array given
TypeError: Header "from" must be of type string, array given
TypeError: Header "sender" must be of type string, array given
TypeError: Header "reply-to" must be of type string, array given
ValueError: The additional headers cannot contain the "To" header
TypeError: Header "bcc" must be of type string, array given
TypeError: Header "message-id" must be of type string, array given
TypeError: Header "in-reply-to" must be of type string, array given
************* TEST ******************
TypeError: Header "foo1" must only contain numeric keys, "foo2" found
TypeError: Header "foo2" must only contain values of type string, array found
TypeError: Header "foo3" must only contain values of type string, int found
TypeError: Header "foo4" must only contain values of type string, float found
TypeError: Header "foo5" must only contain values of type string, false found
TypeError: Header "foo6" must only contain values of type string, null found
TypeError: Header "foo7" must only contain values of type string, stdClass found
************* TEST ******************
ValueError: Header name "*:foo1" contains invalid characters
ValueError: Header name "foo2:::" contains invalid characters
ValueError: Header name "" contains invalid characters
ValueError: Header name "foo7" contains invalid characters
bool(true)
To: user@example.com
Subject: Test Subject
foo9: %&$#!
A Message
ValueError: Header "foo10" has invalid format, or contains invalid characters