From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-3.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, T_RP_MATCHES_RCVD shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: meta@public-inbox.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 1601E1FD28 for ; Wed, 2 Sep 2015 06:59:42 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 3/7] view: account for missing In-Reply-To header Date: Wed, 2 Sep 2015 06:59:35 +0000 Message-Id: <1441177179-16628-4-git-send-email-e@80x24.org> In-Reply-To: <1441177179-16628-1-git-send-email-e@80x24.org> References: <1441177179-16628-1-git-send-email-e@80x24.org> List-Id: Some mail clients do not generate In-Reply-To headers, but do generate a proper References header. This matches the behavior of Mail::Thread as well as our SearchIdx code to link threads in the Xapian DB. --- lib/PublicInbox/View.pm | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index a3df319..d213124 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -46,6 +46,19 @@ sub feed_entry { PRE_WRAP . multipart_text_as_html($mime, $full_pfx) . ''; } +sub in_reply_to { + my ($header_obj) = @_; + my $irt = $header_obj->header('In-Reply-To'); + + return mid_clean($irt) if (defined $irt); + + my $refs = $header_obj->header('References'); + if ($refs && $refs =~ /<([^>]+)>\s*\z/s) { + return $1; + } + undef; +} + # this is already inside a
 sub index_entry {
 	my ($fh, $mime, $level, $state) = @_;
@@ -74,7 +87,8 @@ sub index_entry {
 	my $root_anchor = $state->{root_anchor};
 	my $path = $root_anchor ? '../../' : '';
 	my $href = $mid->as_href;
-	my $irt = $header_obj->header('In-Reply-To');
+	my $irt = in_reply_to($header_obj);
+
 	my ($anchor_idx, $anchor);
 	if (defined $irt) {
 		$anchor_idx = anchor_for($irt);
@@ -463,7 +477,7 @@ sub _parent_headers_nosrch {
 	my ($header_obj) = @_;
 	my $rv = '';
 
-	my $irt = $header_obj->header('In-Reply-To');
+	my $irt = in_reply_to($header_obj);
 	if (defined $irt) {
 		my $v = PublicInbox::Hval->new_msgid($irt);
 		my $html = $v->as_html;
@@ -476,7 +490,7 @@ sub _parent_headers_nosrch {
 	if ($refs) {
 		# avoid redundant URLs wasting bandwidth
 		my %seen;
-		$seen{mid_clean($irt)} = 1 if defined $irt;
+		$seen{$irt} = 1 if defined $irt;
 		my @refs;
 		my @raw_refs = ($refs =~ /<([^>]+)>/g);
 		foreach my $ref (@raw_refs) {
@@ -526,7 +540,7 @@ sub html_footer {
 	my $idx = $standalone ? " index" : '';
 	if ($idx && $srch) {
 		my $next = thread_inline(\$idx, $ctx, $mime, $full_pfx);
-		$irt = $mime->header('In-Reply-To');
+		$irt = in_reply_to($mime->header_obj);
 		if (defined $irt) {
 			$irt = PublicInbox::Hval->new_msgid($irt);
 			$irt = $irt->as_href;
-- 
EW