user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: "Eric Wong (Contractor, The Linux Foundation)" <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] searchidx: ensure duplicated Message-IDs can be linked together
Date: Wed,  4 Apr 2018 21:11:47 +0000	[thread overview]
Message-ID: <20180404211147.29563-1-e@80x24.org> (raw)

This allows us to emulate the display of thread-aware MUAs when
multiple messages share the same Message-ID.  This also is a
place where "public-inbox-index --reindex" is useful to fix
existing messages and no schema version bump is necessary.
---
 lib/PublicInbox/SearchIdx.pm | 13 +++++++------
 t/psgi_v2.t                  |  3 +++
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 3412a61..06bce70 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -334,7 +334,7 @@ sub add_message {
 		});
 
 		# populates smsg->references for smsg->to_doc_data
-		my $refs = parse_references($smsg);
+		my $refs = parse_references($smsg, $mid0, $mids);
 		my $data = $smsg->to_doc_data($oid, $mid0);
 		foreach my $mid (@$mids) {
 			$tg->index_text($mid, 1, 'XM');
@@ -463,22 +463,23 @@ sub term_generator { # write-only
 	$self->{term_generator} = $tg;
 }
 
-sub parse_references ($) {
-	my ($smsg) = @_;
+sub parse_references ($$$) {
+	my ($smsg, $mid0, $mids) = @_;
 	my $mime = $smsg->{mime};
 	my $hdr = $mime->header_obj;
 	my $refs = references($hdr);
+	push(@$refs, @$mids) if scalar(@$mids) > 1;
 	return $refs if scalar(@$refs) == 0;
 
-	# prevent circular references via References here:
-	my %mids = map { $_ => 1 } @{mids($hdr)};
+	# prevent circular references here:
+	my %seen = ( $mid0 => 1 );
 	my @keep;
 	foreach my $ref (@$refs) {
 		if (length($ref) > PublicInbox::MID::MAX_MID_SIZE) {
 			warn "References: <$ref> too long, ignoring\n";
 			next;
 		}
-		next if $mids{$ref};
+		next if $seen{$ref}++;
 		push @keep, $ref;
 	}
 	$smsg->{references} = '<'.join('> <', @keep).'>' if @keep;
diff --git a/t/psgi_v2.t b/t/psgi_v2.t
index aa3279c..bdf23de 100644
--- a/t/psgi_v2.t
+++ b/t/psgi_v2.t
@@ -182,6 +182,9 @@ test_psgi(sub { $www->call(@_) }, sub {
 	$res = $cb->(GET('/v2test/reuse@mid/T/'));
 	$raw = $res->content;
 	like($raw, qr/\b4\+ messages\b/, 'thread overview shown with /T/');
+	my @over = ($raw =~ m/^\d{4}-\d+-\d+\s+\d+:\d+ (.+)$/gm);
+	is_deeply(\@over, [ '<a', '` <a', '` <a', '` <a' ],
+		'duplicate messages share the same root');
 
 	$res = $cb->(GET('/v2test/reuse@mid/t/'));
 	$raw = $res->content;
-- 
EW


                 reply	other threads:[~2018-04-04 21:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20180404211147.29563-1-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).