user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH] view: extra check to for redundant messages in HTML view
@ 2021-06-19  3:22 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2021-06-19  3:22 UTC (permalink / raw)
  To: meta

There appears to be some cases of duplicates appearing due to
-extindex.  I haven't nailed down the cause of it, yet, but
this should make things easier for readers using the PSGI
HTML interface in the meantime.

The raw mboxrd remains undeduplicated for now, and the
correct fix/workaround would be some fsck-like mode for
public-inbox-extindex.
---
 lib/PublicInbox/View.pm | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 530c878f..fc0cd77e 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -22,6 +22,7 @@ use PublicInbox::ViewDiff qw(flush_diff);
 use PublicInbox::Eml;
 use Time::Local qw(timegm);
 use PublicInbox::Smsg qw(subject_normalized);
+use PublicInbox::ContentHash qw(content_hash);
 use constant COLS => 72;
 use constant INDENT => '  ';
 use constant TCHILD => '` ';
@@ -35,9 +36,11 @@ sub msg_page_i {
 		$ctx->{mhref} = ($ctx->{nr} || $ctx->{smsg}) ?
 				"../${\mid_href($smsg->{mid})}/" : '';
 		my $obuf = $ctx->{obuf} = _msg_page_prepare_obuf($eml, $ctx);
-		multipart_text_as_html($eml, $ctx);
+		if (length($$obuf)) {
+			multipart_text_as_html($eml, $ctx);
+			$$obuf .= '</pre><hr>';
+		}
 		delete $ctx->{obuf};
-		$$obuf .= '</pre><hr>';
 		$$obuf .= html_footer($ctx, $ctx->{first_hdr}) if !$ctx->{smsg};
 		$$obuf;
 	} else { # called by WwwStream::async_next or getline
@@ -53,9 +56,11 @@ sub no_over_html ($) {
 	$ctx->{mhref} = '';
 	PublicInbox::WwwStream::init($ctx);
 	my $obuf = $ctx->{obuf} = _msg_page_prepare_obuf($eml, $ctx);
-	multipart_text_as_html($eml, $ctx);
+	if (length($$obuf)) {
+		multipart_text_as_html($eml, $ctx);
+		$$obuf .= '</pre><hr>';
+	}
 	delete $ctx->{obuf};
-	$$obuf .= '</pre><hr>';
 	eval { $$obuf .= html_footer($ctx, $eml) };
 	html_oneshot($ctx, 200, $obuf);
 }
@@ -646,13 +651,16 @@ sub _msg_page_prepare_obuf {
 	my $mids = mids_for_index($eml);
 	my $nr = $ctx->{nr}++;
 	if ($nr) { # unlikely
+		if ($ctx->{chash} eq content_hash($eml)) {
+			warn "W: BUG? @$mids not deduplicated properly\n";
+			return \$rv;
+		}
+		$rv .=
+"<pre>WARNING: multiple messages have this Message-ID\n</pre>";
 		$rv .= '<pre>';
 	} else {
 		$ctx->{first_hdr} = $eml->header_obj;
-		if ($ctx->{smsg}) {
-			$rv .=
-"<pre>WARNING: multiple messages have this Message-ID\n</pre>";
-		}
+		$ctx->{chash} = content_hash($eml) if $ctx->{smsg}; # reused MID
 		$rv .= "<pre\nid=b>"; # anchor for body start
 	}
 	$ctx->{-upfx} = '../' if $over;

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

only message in thread, other threads:[~2021-06-19  3:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-19  3:22 [PATCH] view: extra check to for redundant messages in HTML view Eric Wong

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.mail.public-inbox.meta
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.mail.public-inbox.meta
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

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

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git