unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH] threading: deal with improperly-terminated References headers
@ 2017-10-02 22:19 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2017-10-02 22:19 UTC (permalink / raw)
  To: meta

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 '>'.
---
 lib/PublicInbox/SearchIdx.pm | 5 ++---
 lib/PublicInbox/View.pm      | 5 ++---
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 0824db0..cfb9a08 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 7454acb..b39c820 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;
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2017-10-02 22:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-02 22:19 [PATCH] threading: deal with improperly-terminated References headers Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).