From: Eric Wong Date: Tue, 9 Jan 2024 12:49:13 +0000 (+0000) Subject: address: avoid [ undef, undef ] address pairs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=61c44bbd8e57c719a1a4de75a1a11c412173e820;p=thirdparty%2Fpublic-inbox.git address: avoid [ undef, undef ] address pairs 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. --- diff --git a/lib/PublicInbox/Address.pm b/lib/PublicInbox/Address.pm index a5902cfd6..3a59945cb 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 39ec35c3e..9d4262c1c 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($n) : $n; } ($html, $len + $line_len); diff --git a/t/address.t b/t/address.t index 16000d2d5..86f47395f 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 '); 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');