diff options
author | Eric Wong <e@80x24.org> | 2019-12-14 01:02:55 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2019-12-15 19:43:33 +0000 |
commit | 01d25810ec9baf643e2a278a0fefdf857bfd3883 (patch) | |
tree | 1bfcc07f7d52a7d12c70cc8f6ee81de2fcc697b5 /lib/PublicInbox/Address.pm | |
parent | 2ad19256bc285e40188a9058941883979ff45c86 (diff) | |
download | public-inbox-01d25810ec9baf643e2a278a0fefdf857bfd3883.tar.gz |
Some users will set their From: headers in the form of: "<user@example.com> (A U Thor)", where their name is in the parenthesized comment. Use that instead of the email address, if available.
Diffstat (limited to 'lib/PublicInbox/Address.pm')
-rw-r--r-- | lib/PublicInbox/Address.pm | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/lib/PublicInbox/Address.pm b/lib/PublicInbox/Address.pm index 46aa0da7..a58d1eff 100644 --- a/lib/PublicInbox/Address.pm +++ b/lib/PublicInbox/Address.pm @@ -13,16 +13,26 @@ sub emails { } sub names { - map { - tr/\r\n\t/ /; - s/\s*<([^<]+)\z//; - my $e = $1; - s/\A['"\s]*//; - s/['"\s]*\z//; - $e = $_ =~ /\S/ ? $_ : $e; - $e =~ s/\@\S+\z//; - $e; - } split(/\@+[\w\.\-]+>?\s*(?:\(.*?\))?(?:,\s*|\z)/, $_[0]); + my @p = split(/<?([^@<>]+)\@[\w\.\-]+>?\s*(\(.*?\))?(?:,\s*|\z)/, + $_[0]); + my @ret; + for (my $i = 0; $i <= $#p;) { + my $phrase = $p[$i++]; + $phrase =~ tr/\r\n\t / /s; + $phrase =~ s/\A['"\s]*//; + $phrase =~ s/['"\s]*\z//; + my $user = $p[$i++] // ''; + my $comment = $p[$i++] // ''; + if ($phrase =~ /\S/) { + $phrase =~ s/\@\S+\z//; + push @ret, $phrase; + } elsif ($comment =~ /\A\((.*?)\)\z/) { + push @ret, $1; + } else { + push @ret, $user; + } + } + @ret; } 1; |