]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/Address.pm
548f417cae91e25ff5ddc6d1ee031d290129ef73
[public-inbox.git] / lib / PublicInbox / Address.pm
1 # Copyright (C) 2016-2018 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 warnings;
6
7 # very loose regexes, here.  We don't need RFC-compliance,
8 # just enough to make thing sanely displayable and pass to git
9
10 sub emails {
11         ($_[0] =~ /([\w\.\+=\?"\(\)\-!#\$%&'\*\/\^\`\|\{\}~]+\@[\w\.\-\(\)]+)
12                 (?:\s[^>]*)?>?\s*(?:\(.*?\))?(?:,\s*|\z)/gx)
13 }
14
15 sub names {
16         map {
17                 tr/\r\n\t/ /;
18                 s/\s*<([^<]+)\z//;
19                 my $e = $1;
20                 s/\A['"\s]*//;
21                 s/['"\s]*\z//;
22                 $e = $_ =~ /\S/ ? $_ : $e;
23                 $e =~ s/\@\S+\z//;
24                 $e;
25         } split(/\@+[\w\.\-]+>?\s*(?:\(.*?\))?(?:,\s*|\z)/, $_[0]);
26 }
27
28 1;