user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/2] address: explicitly reject local-only addresses
Date: Sat, 14 Dec 2019 05:22:18 +0000	[thread overview]
Message-ID: <20191214052218.GA3890@dcvr> (raw)
In-Reply-To: <20191214010256.19858-1-e@80x24.org>

Apparently, neither our previous address parsing code nor
Email::Address::XS recognizes local, username-only addresses
in the form of <username> (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" <user@example.com>');
 	is_deeply(['Quote Unneeded'], \@names, 'extra quotes dropped');
+
+	my @emails = $emails->('Local User <user>');
+	is_deeply([], \@emails , 'no address for local address');
+	@names = $emails->('Local User <user>');
+	is_deeply([], \@names, 'no address, no name');
 }
 
 test_pkg('PublicInbox::Address');

      parent reply	other threads:[~2019-12-14  5:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-14  1:02 [PATCH 0/2] use Email::Address::XS if available Eric Wong
2019-12-14  1:02 ` [PATCH 1/2] address: use comment as name if no phrase available Eric Wong
2019-12-14  1:02 ` [PATCH 2/2] address: use Email::Address::XS if available Eric Wong
2019-12-14  5:22 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191214052218.GA3890@dcvr \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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).