]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/Address.pm
ds: inline set_cloexec
[public-inbox.git] / lib / PublicInbox / Address.pm
1 # Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 package PublicInbox::Address;
4 use strict;
5 use v5.10.1;
6 use parent 'Exporter';
7 our @EXPORT_OK = qw(pairs);
8
9 sub xs_emails {
10         grep { defined } map { $_->address() } parse_email_addresses($_[0])
11 }
12
13 sub xs_names {
14         grep { defined } map {
15                 my $n = $_->name;
16                 my $addr = $_->address;
17                 $n = $_->user if defined($addr) && $n eq $addr;
18                 $n;
19         } parse_email_addresses($_[0]);
20 }
21
22 sub xs_pairs { # for JMAP, RFC 8621 section 4.1.2.3
23         [ map { # LHS (name) may be undef
24                 [ $_->phrase // $_->comment, $_->address ]
25         } parse_email_addresses($_[0]) ];
26 }
27
28 eval {
29         require Email::Address::XS;
30         Email::Address::XS->import(qw(parse_email_addresses));
31         *emails = \&xs_emails;
32         *names = \&xs_names;
33         *pairs = \&xs_pairs;
34 };
35
36 if ($@) {
37         require PublicInbox::AddressPP;
38         *emails = \&PublicInbox::AddressPP::emails;
39         *names = \&PublicInbox::AddressPP::names;
40         *pairs = \&PublicInbox::AddressPP::pairs;
41 }
42
43 1;