diff options
author | David Flatz | 2022-07-29 14:18:56 +0200 |
---|---|---|
committer | David Flatz | 2022-07-29 14:51:07 +0200 |
commit | 744db7c9e5fc89d227c1beb981d01898ce478e41 (patch) | |
tree | 64f1fcb4fb2a355e6fa3194008118301383bb7f1 /test/it_mail.t | |
parent | 4640a1e8b286c3ff2785abaddb9e449b023c88a7 (diff) | |
download | itools-744db7c9e5fc89d227c1beb981d01898ce478e41.tar.gz itools-744db7c9e5fc89d227c1beb981d01898ce478e41.tar.bz2 itools-744db7c9e5fc89d227c1beb981d01898ce478e41.zip |
improve validation and escaping of e-mail addresses: use same method for validation in check_email and address_error; encode and validate IDNs; make (more) robust functions to split address lists and emails
Diffstat (limited to 'test/it_mail.t')
-rwxr-xr-x | test/it_mail.t | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/test/it_mail.t b/test/it_mail.t index 7e892c2..6aefd84 100755 --- a/test/it_mail.t +++ b/test/it_mail.t @@ -56,6 +56,12 @@ is( "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>', @@ -95,10 +101,23 @@ is( ); 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"), + 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'] as $email) +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 ﻢﺛﺎﻟ.ﺁﺰﻣﺎﯿﺸﯾ'); |