From: Eric Wong Date: Mon, 2 Oct 2017 22:19:16 +0000 (+0000) Subject: threading: deal with improperly-terminated References headers X-Git-Tag: v1.0.0~24 X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=commitdiff_plain;h=2aa29ee6a35f5be2d76c39ccc50bf7a34075e2bd threading: deal with improperly-terminated References headers We should not blindly join References and In-Reply-To headers as a single string, because some messages can have an open angle brace '<' in References: without a corresponding '>'. --- diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index 0824db03..cfb9a088 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -414,9 +414,8 @@ sub link_message { # last References should be IRT, but some mail clients do things # out of order, so trust IRT over References iff IRT exists - my @refs = ($hdr->header_raw('References'), - $hdr->header_raw('In-Reply-To')); - @refs = ((join(' ', @refs)) =~ /<([^>]+)>/g); + my @refs = (($hdr->header_raw('References') || '') =~ /<([^>]+)>/g); + push(@refs, (($hdr->header_raw('In-Reply-To') || '') =~ /<([^>]+)>/g)); my $tid; if (@refs) { diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 7454acbb..b39c8203 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -104,9 +104,8 @@ EOF sub in_reply_to { my ($hdr) = @_; 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); + my @refs = (($hdr->header_raw('References') || '') =~ /<([^>]+)>/g); + push(@refs, (($hdr->header_raw('In-Reply-To') || '') =~ /<([^>]+)>/g)); while (defined(my $irt = pop @refs)) { next if $mid{"<$irt>"}; return $irt;