From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 922931FE4E for ; Fri, 1 Jul 2016 06:15:12 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] address: filter out domain from address-as-name idents Date: Fri, 1 Jul 2016 06:15:12 +0000 Message-Id: <20160701061512.30061-1-e@80x24.org> List-Id: It seems common for address entries to end up as: "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" '); +is_deeply(['user'], \@names, 'address-as-name extraction works as expected'); done_testing; -- EW