1 # Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use_ok 'PublicInbox::Address';
10 my $emails = \&{"${pkg}::emails"};
11 my $names = \&{"${pkg}::names"};
13 is_deeply([qw(e@example.com e@example.org)],
14 [$emails->('User <e@example.com>, e@example.org')],
15 'address extraction works as expected');
17 is_deeply(['user@example.com'],
18 [$emails->('<user@example.com (Comment)>')],
19 'comment after domain accepted before >');
22 'User <e@e>, e@e, "John A. Doe" <j@d>, <x@x>, <y@x> (xyz), '.
23 'U Ser <u@x> (do not use)');
24 is_deeply(\@names, ['User', 'e', 'John A. Doe', 'x', 'xyz', 'U Ser'],
25 'name extraction works as expected');
27 @names = $names->('"user@example.com" <user@example.com>');
28 is_deeply(['user'], \@names,
29 'address-as-name extraction works as expected');
32 my $backwards = 'u@example.com (John Q. Public)';
33 @names = $names->($backwards);
34 is_deeply(\@names, ['John Q. Public'], 'backwards name OK');
35 my @emails = $emails->($backwards);
36 is_deeply(\@emails, ['u@example.com'], 'backwards emails OK');
39 @names = $names->('"Quote Unneeded" <user@example.com>');
40 is_deeply(['Quote Unneeded'], \@names, 'extra quotes dropped');
43 test_pkg('PublicInbox::Address');
46 if ($INC{'PublicInbox/AddressPP.pm'}) {
47 skip 'Email::Address::XS missing', 8;
49 use_ok 'PublicInbox::AddressPP';
50 test_pkg('PublicInbox::AddressPP');