From 59d0535223c60cfa2697a2af60393d302dde4493 Mon Sep 17 00:00:00 2001
From: Eric Wong <e@80x24.org>
Date: Fri, 4 Sep 2015 02:18:11 +0000
Subject: [PATCH] view: do not generate anchors in thread views

They're unused, and they can have namespace conflicts if
there's multiple full messages in the thread view.
---
 lib/PublicInbox/View.pm | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 65ef1e78..bd174b1f 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -256,7 +256,7 @@ sub multipart_text_as_html {
 	# scan through all parts, looking for displayable text
 	$mime->walk_parts(sub {
 		my ($part) = @_;
-		$rv .= add_text_body($enc, $part, \$part_nr, $full_pfx);
+		$rv .= add_text_body($enc, $part, \$part_nr, $full_pfx, 1);
 	});
 	$mime->body_set('');
 	$rv;
@@ -308,7 +308,7 @@ sub linkify_2 {
 }
 
 sub flush_quote {
-	my ($quot, $n, $part_nr, $full_pfx, $final) = @_;
+	my ($quot, $n, $part_nr, $full_pfx, $final, $do_anchor) = @_;
 
 	if ($full_pfx) {
 		if (!$final && scalar(@$quot) <= MAX_INLINE_QUOTED) {
@@ -342,18 +342,18 @@ sub flush_quote {
 	} else {
 		# show everything in the full version with anchor from
 		# short version (see above)
-		my $nr = ++$$n;
-		my $rv = "";
 		my %l;
-		$rv .= join('', map { linkify_1(\%l, $_) } @$quot);
+		my $rv .= join('', map { linkify_1(\%l, $_) } @$quot);
 		@$quot = ();
 		$rv = ascii_html($rv);
+		return linkify_2(\%l, $rv) unless $do_anchor;
+		my $nr = ++$$n;
 		"<a\nid=q${part_nr}_$nr></a>" . linkify_2(\%l, $rv);
 	}
 }
 
 sub add_text_body {
-	my ($enc_msg, $part, $part_nr, $full_pfx) = @_;
+	my ($enc_msg, $part, $part_nr, $full_pfx, $do_anchor) = @_;
 	return '' if $part->subparts;
 
 	my $ct = $part->content_type;
@@ -383,7 +383,7 @@ sub add_text_body {
 			# show the previously buffered quote inline
 			if (scalar @quot) {
 				$s .= flush_quote(\@quot, \$n, $$part_nr,
-						  $full_pfx, 0);
+						  $full_pfx, 0, $do_anchor);
 			}
 
 			# regular line, OK
@@ -395,7 +395,10 @@ sub add_text_body {
 			push @quot, $cur;
 		}
 	}
-	$s .= flush_quote(\@quot, \$n, $$part_nr, $full_pfx, 1) if scalar @quot;
+	if (scalar @quot) {
+		$s .= flush_quote(\@quot, \$n, $$part_nr, $full_pfx, 1,
+				  $do_anchor);
+	}
 	$s .= "\n" unless $s =~ /\n\z/s;
 	++$$part_nr;
 	$s;
-- 
2.51.0