user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
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	[thread overview]
Message-ID: <1441177179-16628-4-git-send-email-e@80x24.org> (raw)
In-Reply-To: <1441177179-16628-1-git-send-email-e@80x24.org>

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) . '</pre>';
 }
 
+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 <pre>
 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 ? " <a\nhref=\"$upfx\">index</a>" : '';
 	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


  parent reply	other threads:[~2015-09-02  6:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-02  6:59 [PATCH 0/7] improved thread views and 404 reductions Eric Wong
2015-09-02  6:59 ` [PATCH 1/7] view: close possible race condition in thread view Eric Wong
2015-09-02  6:59 ` [PATCH 2/7] view: optional flat view for recent messages Eric Wong
2015-09-02  6:59 ` Eric Wong [this message]
2015-09-02  6:59 ` [PATCH 4/7] view: simplify parent anchoring code Eric Wong
2015-09-02  6:59 ` [PATCH 5/7] view: pre-anchor entries for flat view Eric Wong
2015-09-02  6:59 ` [PATCH 6/7] view: avoid links to unknown compressed Message-IDs Eric Wong
2015-09-02  6:59 ` [PATCH 7/7] implement external Message-ID finder Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1441177179-16628-4-git-send-email-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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).