]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
address: avoid [ undef, undef ] address pairs
authorEric Wong <e@80x24.org>
Tue, 9 Jan 2024 12:49:13 +0000 (12:49 +0000)
committerEric Wong <e@80x24.org>
Wed, 10 Jan 2024 10:27:01 +0000 (10:27 +0000)
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.

lib/PublicInbox/Address.pm
lib/PublicInbox/View.pm
t/address.t

index a5902cfd63849634778d6425e41c0cbfc0a238f1..3a59945cbcca8886e0db78c53499a6a97f72213e 100644 (file)
@@ -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]) ];
 }
 
index 39ec35c3ee446c77a42632165e9b94279208f779..9d4262c1ca9e7f58cfc07b85728fde90693d1627 100644 (file)
@@ -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);
index 16000d2d55a5af69c04f4351c465ff54ccbecd17..86f47395f4f709005b8ccf6e684273a4e0bf92a3 100644 (file)
@@ -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');