From 18011be3dbfecb3abe4bea8cdf7f0ee7dfa2f8be Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 25 Jun 2016 07:19:10 +0000 Subject: address: beef up the module with name list extaction We may remove from_name in the future. ...And disallow quotes in email addresses. Technically I believe they're allowed, but they're definitely uncommon and unlikely to show up in legitimate mail. --- lib/PublicInbox/Address.pm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/PublicInbox/Address.pm') diff --git a/lib/PublicInbox/Address.pm b/lib/PublicInbox/Address.pm index 772adedb..abba43d1 100644 --- a/lib/PublicInbox/Address.pm +++ b/lib/PublicInbox/Address.pm @@ -7,7 +7,18 @@ use warnings; # very loose regexes, here. We don't need RFC-compliance, # just enough to make thing sanely displayable and pass to git -sub emails { ($_[0] =~ /([^<\s,]+\@[^>\s,]+)/g) } +sub emails { ($_[0] =~ /([\w\.\+=\-]+\@[\w\.\-]+)>?\s*(?:,\s*|\z)/g) } + +sub names { + map { + tr/\r\n\t/ /; + s/\s*<([^<]+)\z//; + my $e = $1; + s/\A['"\s]*//; + s/['"\s]*\z//; + $_ =~ /\S/ ? $_ : $e; + } split(/\@+[\w\.\-]+>?\s*(?:,\s*|\z)/, $_[0]); +} sub from_name { my ($val) = @_; -- cgit v1.2.3-24-ge0c7