* [PATCH] address: filter out domain from address-as-name idents
@ 2016-07-01 6:15 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-07-01 6:15 UTC (permalink / raw)
To: meta
It seems common for address entries to end up as:
"foo@example" <foo@example>
Avoid needlessly displaying the domain name in that case.
---
lib/PublicInbox/Address.pm | 4 +++-
t/address.t | 2 ++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/PublicInbox/Address.pm b/lib/PublicInbox/Address.pm
index cd5fbfb..e17d0b5 100644
--- a/lib/PublicInbox/Address.pm
+++ b/lib/PublicInbox/Address.pm
@@ -16,7 +16,9 @@ sub names {
my $e = $1;
s/\A['"\s]*//;
s/['"\s]*\z//;
- $_ =~ /\S/ ? $_ : $e;
+ $e = $_ =~ /\S/ ? $_ : $e;
+ $e =~ s/\@\S+\z//;
+ $e;
} split(/\@+[\w\.\-]+>?\s*(?:,\s*|\z)/, $_[0]);
}
diff --git a/t/address.t b/t/address.t
index c488a8e..3191fed 100644
--- a/t/address.t
+++ b/t/address.t
@@ -17,5 +17,7 @@ my @names = PublicInbox::Address::names(
is_deeply(['User', 'e', 'John A. Doe', 'x'], \@names,
'name extraction works as expected');
+@names = PublicInbox::Address::names('"user@example.com" <user@example.com>');
+is_deeply(['user'], \@names, 'address-as-name extraction works as expected');
done_testing;
--
EW
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2016-07-01 6:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-01 6:15 [PATCH] address: filter out domain from address-as-name idents Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).