user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 7/6] address: avoid [ undef, undef ] address pairs
  @ 2024-01-09 12:49  7%   ` Eric Wong
  0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2024-01-09 12:49 UTC (permalink / raw)
  To: meta

For totally bogus things in address fields, we'll fall back to
showing the original entry in the name column when using
Email::Address::XS.

The pure Perl version differs here, but we'll just let them be
different when it comes to handling bogus data.
---
 This fixes some warning spew I noticed in syslog while letting
 crawlers run on https://yhbt.net/lore/

 lib/PublicInbox/Address.pm | 7 +++++--
 lib/PublicInbox/View.pm    | 2 +-
 t/address.t                | 4 ++++
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/Address.pm b/lib/PublicInbox/Address.pm
index a5902cfd..3a59945c 100644
--- a/lib/PublicInbox/Address.pm
+++ b/lib/PublicInbox/Address.pm
@@ -19,8 +19,11 @@ sub xs_names {
 }
 
 sub xs_pairs { # for JMAP, RFC 8621 section 4.1.2.3
-	[ map { # LHS (name) may be undef
-		[ $_->phrase // $_->comment, $_->address ]
+	[ map { # LHS (name) may be undef if there's an address
+		my @p = ($_->phrase // $_->comment, $_->address);
+		# show original if totally bogus:
+		$p[0] = $_->original unless defined $p[1];
+		\@p;
 	} parse_email_addresses($_[0]) ];
 }
 
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 39ec35c3..9d4262c1 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -230,7 +230,7 @@ sub to_cc_html ($$$$) {
 			}
 		}
 		$line_len += length($n);
-		$url = $addr2url->{lc $pair->[1]};
+		$url = $addr2url->{lc($pair->[1] // '')};
 		$html .= $url ? qq(<a\nhref="$url$t">$n</a>) : $n;
 	}
 	($html, $len + $line_len);
diff --git a/t/address.t b/t/address.t
index 16000d2d..86f47395 100644
--- a/t/address.t
+++ b/t/address.t
@@ -77,6 +77,10 @@ sub test_pkg {
 	is_deeply([], \@emails , 'no address for local address');
 	@names = $emails->('Local User <user>');
 	is_deeply([], \@names, 'no address, no name');
+
+	my $p = $pairs->('NAME, a@example, wtf@');
+	is scalar(grep { defined($_->[0] // $_->[1]) } @$p),
+		scalar(@$p), 'something is always defined in bogus pairs';
 }
 
 test_pkg('PublicInbox::Address');

^ permalink raw reply related	[relevance 7%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2024-01-09 11:39     [PATCH 0/6] WWW updates Eric Wong
2024-01-09 11:39     ` [PATCH 5/6] www: linkify inbox addresses in To/Cc headers Eric Wong
2024-01-09 12:49  7%   ` [PATCH 7/6] address: avoid [ undef, undef ] address pairs Eric Wong

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