From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id A9A301F463; Sat, 14 Dec 2019 05:22:18 +0000 (UTC) Date: Sat, 14 Dec 2019 05:22:18 +0000 From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 3/2] address: explicitly reject local-only addresses Message-ID: <20191214052218.GA3890@dcvr> References: <20191214010256.19858-1-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20191214010256.19858-1-e@80x24.org> List-Id: Apparently, neither our previous address parsing code nor Email::Address::XS recognizes local, username-only addresses in the form of (without "@host"). Without this change, Email::Address::XS->address would return "undef", so we need to filter it out via "grep { defined }" It seems the cases where users email each other on the same machine is small and public-inbox won't be able to index addresses for those cases... Oh well :/ --- lib/PublicInbox/Address.pm | 9 ++++++--- t/address.t | 5 +++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/PublicInbox/Address.pm b/lib/PublicInbox/Address.pm index 433b36eb..c23a5d62 100644 --- a/lib/PublicInbox/Address.pm +++ b/lib/PublicInbox/Address.pm @@ -4,12 +4,15 @@ package PublicInbox::Address; use strict; use warnings; -sub xs_emails { map { $_->address() } parse_email_addresses($_[0]) } +sub xs_emails { + grep { defined } map { $_->address() } parse_email_addresses($_[0]) +} sub xs_names { - map { + grep { defined } map { my $n = $_->name; - $n = $_->user if $n eq $_->address; + my $addr = $_->address; + $n = $_->user if defined($addr) && $n eq $addr; $n; } parse_email_addresses($_[0]); } diff --git a/t/address.t b/t/address.t index e7c0d6a8..1f20702a 100644 --- a/t/address.t +++ b/t/address.t @@ -38,6 +38,11 @@ sub test_pkg { @names = $names->('"Quote Unneeded" '); is_deeply(['Quote Unneeded'], \@names, 'extra quotes dropped'); + + my @emails = $emails->('Local User '); + is_deeply([], \@emails , 'no address for local address'); + @names = $emails->('Local User '); + is_deeply([], \@names, 'no address, no name'); } test_pkg('PublicInbox::Address');