From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,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.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id A14B81F624 for ; Sat, 10 Sep 2022 08:18:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1662797933; bh=AL3ZTfMdOx+fn9UUel73YX8cnGcClYOacLmA7cSL0Tc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fI2yFr2ORnmHrvHTjBN8uGw21claBtLX+Ki0t+80Nci0XhEYnehSBElEewjddpel5 0uLBL/JKFGd89Q6YnKZgBcmJiDJ3k4nON1LuFvbD6qhlw6ntF4Gvp+VYoS5fgvU1Qr 5aZ/+GBRPLO5NHdHhhDSsObVpdnyRqXISB0ISMAQ= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 11/38] view: simplify _parent_headers Date: Sat, 10 Sep 2022 08:17:02 +0000 Message-Id: <20220910081729.2011934-12-e@80x24.org> In-Reply-To: <20220910081729.2011934-1-e@80x24.org> References: <20220910081729.2011934-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Having References but lacking In-Reply-To is an uncommon case with email, nowadays. So just rely on ->linkify_mids to handle linkification and HTML escaping Furthermore, headers are short enough to return as-is (and rely on CoW improvements in Perl 5.1x) since linkify_mids needs to operate on an independent string, anyways. --- lib/PublicInbox/View.pm | 39 ++++++++++----------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index c6fd05cc..3980ed91 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -740,8 +740,7 @@ sub _msg_page_prepare_obuf { $ctx->{-linkify}->linkify_mids('..', \$s, 1); $rv .= $s; } - _parent_headers($ctx, $eml); - $rv .= "\n"; + $rv .= _parent_headers($ctx, $eml); 1; } @@ -795,32 +794,21 @@ sub _parent_headers { my ($ctx, $hdr) = @_; my @irt = $hdr->header_raw('In-Reply-To'); my $refs; - if (@irt) { - my $s = ''; - $s .= "In-Reply-To: $_\n" for @irt; - $ctx->{-linkify}->linkify_mids('..', \$s); - ${$ctx->{obuf}} .= $s; - } else { + my $s = ''; + if (!@irt) { $refs = references($hdr); - my $irt = pop @$refs; - if (defined $irt) { - my $html = ascii_html($irt); - my $href = mid_href($irt); - ${$ctx->{obuf}} .= <$html> -EOM - } + $irt[0] = pop(@$refs) if scalar @$refs; } + $s .= "In-Reply-To: $_\n" for @irt; # do not display References: if search is present, # we show the thread skeleton at the bottom, instead. - return if $ctx->{ibx}->over; - - $refs //= references($hdr); - if (@$refs) { - $_ = linkify_ref_no_over($_) for @$refs; - ${$ctx->{obuf}} .= 'References: '. join("\n\t", @$refs) . "\n"; + if (!$ctx->{ibx}->over) { + $refs //= references($hdr); + $s .= 'References: <'.join(">\n\t<", @$refs).">\n" if @$refs; } + $ctx->{-linkify}->linkify_mids('..', \$s); # escapes HTML + $s .= "\n"; } # appends to obuf @@ -901,13 +889,6 @@ EOF $ctx->zmore($skel .= msg_reply($ctx, $hdr)); # flushes obuf } -sub linkify_ref_no_over { - my ($mid) = @_; - my $href = mid_href($mid); - my $html = ascii_html($mid); - "<$html>"; -} - sub ghost_parent { my ($upfx, $mid) = @_;