From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 78D521F451 for ; Tue, 9 Jan 2024 12:49:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1704804553; bh=JeIbm6p/ib+91QZJYXIZ3oh7BaYA8T4ASneN0LzDaQo=; h=Date:From:To:Subject:References:In-Reply-To:From; b=dvQsfEsdOKc3r7X2PmR1c1NqnD1y+8xVtPyRm+cZX8XKC9WA0SRYHlV++OpifduKc bsAHpDpPaDSxukY5OtFnqpqWvE3qtUW4LkWc9jOPft1EskHZq3k60YIzyTR+O8mgeM REpe90KC4LhnkrrOCDxBajKfGqgBSDIZ8+gDP4nY= Date: Tue, 9 Jan 2024 12:49:13 +0000 From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 7/6] address: avoid [ undef, undef ] address pairs Message-ID: <20240109124913.M325049@dcvr> References: <20240109113928.992464-1-e@80x24.org> <20240109113928.992464-6-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240109113928.992464-6-e@80x24.org> List-Id: 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($n) : $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 '); 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');