about summary refs log tree commit homepage
path: root/lib/PublicInbox/View.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-02-11 23:54:48 +0000
committerEric Wong <e@80x24.org>2017-02-11 23:54:48 +0000
commitccb66f35d293d3d0e3f9b119f7bd1fa019b93c75 (patch)
treef3994394c6c0b16f545b855e731d82cf787f7521 /lib/PublicInbox/View.pm
parentba4c50c20b95679580beba1ef290a4281d5285b7 (diff)
downloadpublic-inbox-ccb66f35d293d3d0e3f9b119f7bd1fa019b93c75.tar.gz
It seems possible for git-send-email(1) to generate repeated
repeated instances of References and In-Reply-To headers,
as evidenced in:

https://public-inbox.org/git/20161111124541.8216-17-vascomalmeida@sapo.pt/raw

This causes a mismatch between how our search indexer threads
and how our HTML view handles threading.  In the future, View.pm
will use the smsg-parsed {references} field and avoid redoing
Email::MIME header parsing.

We will still need to figure out a way to deal with messages
with repeated Message-IDs, at some point, too.
Diffstat (limited to 'lib/PublicInbox/View.pm')
-rw-r--r--lib/PublicInbox/View.pm19
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 2c37cd42..0b1ec75b 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -92,13 +92,13 @@ EOF
 
 sub in_reply_to {
         my ($hdr) = @_;
-        my $irt = $hdr->header_raw('In-Reply-To');
-
-        return mid_clean($irt) if defined $irt && $irt ne '';
-
-        my $refs = $hdr->header_raw('References');
-        if ($refs && $refs =~ /<([^>]+)>\s*\z/s) {
-                return $1;
+        my %mid = map { $_ => 1 } $hdr->header_raw('Message-ID');
+        my @refs = ($hdr->header_raw('References'),
+                        $hdr->header_raw('In-Reply-To'));
+        @refs = ((join(' ', @refs)) =~ /<([^>]+)>/g);
+        while (defined(my $irt = pop @refs)) {
+                next if $mid{"<$irt>"};
+                return $irt;
         }
         undef;
 }
@@ -201,7 +201,10 @@ sub _th_index_lite {
         my $rv = '';
         my $mapping = $ctx->{mapping} or return $rv;
         my $pad = '  ';
-        my ($attr, $node, $idx, $level) = @{$mapping->{$mid_raw}};
+        my $mid_map = $mapping->{$mid_raw};
+        defined $mid_map or
+                return 'public-inbox BUG: '.ascii_html($mid_raw).' not mapped';
+        my ($attr, $node, $idx, $level) = @$mid_map;
         my $children = $node->{children};
         my $nr_c = scalar @$children;
         my $nr_s = 0;