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
|
#!/www/server/bin/php -qC
<?php
$mail = new it_mail();
#
# header_escape tests
#
is(
$mail->addrlist_escape('éxample@example.com', true),
'éxample@example.com',
"Don't escape plain email addresses in email headers"
);
is(
$mail->header_escape('éxample@example.com'),
'=?utf-8?Q?=C3=A9xample@example.com?=',
"Escape plain email in non-email headers"
);
is(
$mail->header_escape('search.ch e-mail code d\'accès'),
version_compare(PHP_VERSION, '7.2.11') < 0
? '=?utf-8?B?c2VhcmNoLmNoIGUtbWFpbCBjb2RlIGQnYWNjw6hz?='
: '=?utf-8?Q?search.ch=20e-mail=20code=20d\'acc=C3=A8s?=',
"Use base64 encoding when php iconv fails with quoted-printable (workaround for php bug #53891)"
);
is(
$mail->addrlist_escape('Èxample User <èxample@example.com>', true),
'=?utf-8?Q?=C3=88xample=20User?= <èxample@example.com>',
"Escape name but not email in email headers"
);
is(
$mail->addrlist_escape('Example User <example@example.com>', true),
'Example User <example@example.com>',
"Don't escape characters that don't need escaping"
);
is(
$mail->addrlist_escape('example@example.com, éxample@example.com, Sömeone Ëlse <sömeone@example.com>', true),
'example@example.com, éxample@example.com, =?utf-8?Q?S=C3=B6meone=20=C3=8Blse?= <sömeone@example.com>',
"Don't escape email addresses but escape realnames"
);
is(
$mail->addrlist_escape('"Alfred E. Neuman" <neuman@example.com>', true),
'"Alfred E. Neuman" <neuman@example.com>',
"Don't remove quoting characters from realname"
);
is(
$mail->addrlist_escape('"Schmitt, Sören" <schmitt@example.com>', true),
'=?utf-8?Q?"Schmitt,=20S=C3=B6ren"?= <schmitt@example.com>',
"Don't remove quoting characters from realname when it contains a quotable character"
);
is(
$mail->addrlist_escape('"Alfred E. Neuman" <t€st@sör.ch>', true),
'"Alfred E. Neuman" <t€st@xn--sr-fka.ch>',
"Convert domain in email to idn version"
);
$mail = new it_mail([
'From' => 'Someone Ïmportant <ïmportant@search.ch>',
'To' => 'éxample@example.com, example@example.com, Sömeone Ëlse <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>, "Schmitt, Sören" <schmitt@example.com>',
'Cc' => 'éxample@example.com, example@example.com, Sömeone Ëlse <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>, "Schmitt, Sören" <schmitt@example.com>',
'Bcc' => 'éxample@example.com, example@example.com, Sömeone Ëlse <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>, "Schmitt, Sören" <schmitt@example.com>',
'Subject' => "§önÐë®z€ı¢ħèṇ"
]);
is(
$mail->to[0],
'éxample@example.com, example@example.com, =?utf-8?Q?S=C3=B6meone=20=C3=8Blse?= <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>, =?utf-8?Q?"Schmitt,=20S=C3=B6ren"?= <schmitt@example.com>',
'Escape To: field as addrlist'
);
is(
$mail->cc[0],
'éxample@example.com, example@example.com, =?utf-8?Q?S=C3=B6meone=20=C3=8Blse?= <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>, =?utf-8?Q?"Schmitt,=20S=C3=B6ren"?= <schmitt@example.com>',
'Escape Cc: field as addrlist'
);
is(
$mail->bcc[0],
'éxample@example.com, example@example.com, =?utf-8?Q?S=C3=B6meone=20=C3=8Blse?= <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>, =?utf-8?Q?"Schmitt,=20S=C3=B6ren"?= <schmitt@example.com>',
'Escape Bcc: field as addrlist'
);
is(
$mail->header_values[0],
'=?utf-8?Q?Someone=20=C3=8Fmportant?= <ïmportant@search.ch>',
'Escape From: field as addrlist'
);
is(
$mail->subject,
"§önÐë®z€ı¢ħèṇ",
"Don't escape Subject: field on instanziation"
);
is(
it_mail::address_error('neuman@example.com, <neuman@example.com>, "Neuman, Alfred E." <neuman@example.com>, aneuman, "<neuman@example>" <neuman@example.com>, " neumann@example.com", "www@search.ch".foo.bar@local.ch, test@sör.ch'),
null,
"Accept valid e-mail addresses"
);
foreach (['neuman@example', '"neuman@example.com" <neuman@example>', '<neuma@example.com', 'shaqroot.@yahoo.com'] as $email)
{
isnt(it_mail::address_error($email), null, "Reject invalid e-mail address $email");
foreach (it_mail::addrlist_split($email) as list($dummy, $email))
is(it_mail::check_email($email), IT_MAIL_CHECKEMAIL_INVALID, "check_email rejects invalid email address $email too");
}
is(it_mail::check_email('test@sör.ch'), IT_MAIL_CHECKEMAIL_OK, "check_email accepts valid email address with idn domain");
is(it_mail::email_split('test@sör.ch'), ['test', 'sör.ch'], 'email_split test@sör.ch');
is(it_mail::email_split('"test@local.ch".foo.bar@search.ch'), ['"test@local.ch".foo.bar', 'search.ch'], 'email_split "test@local.ch".foo.bar@search.ch');
is(it_mail::email_split('aneuman'), ['aneuman', ''], 'email_split aneuman');
is(it_mail::email_escape('test@sör.ch'), 'test@xn--sr-fka.ch', 'idn encode domain sör.ch');
is(it_mail::email_escape('أحمد@مثال.آزمایشی'), 'أحمد@xn--mgbh0fb.xn--hgbk6aj7f53bba', 'idn encode domain ﻢﺛﺎﻟ.ﺁﺰﻣﺎﯿﺸﯾ');
|