user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 2/7] view: display redundant headers in permalink
  2019-10-24  0:12  7% [PATCH 0/7] redundant header madness Eric Wong
@ 2019-10-24  0:12  5% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2019-10-24  0:12 UTC (permalink / raw)
  To: meta

Mail headers can contain multiple headers of any type, so ensure
we don't hide any information we're getting in the per-message
permalink views.

This means it's possible to have multiple From, Date, To, Cc,
Subject, and In-Reply-To headers displayed.

The thread indices are a special case, I guess, since we run
out of space on the line if the headers too long and tools like
mutt only show the first one.
---
 lib/PublicInbox/Linkify.pm | 29 +++++++++++++++
 lib/PublicInbox/View.pm    | 75 ++++++++++++++++++++++----------------
 2 files changed, 73 insertions(+), 31 deletions(-)

diff --git a/lib/PublicInbox/Linkify.pm b/lib/PublicInbox/Linkify.pm
index 175f8d72..5b83742c 100644
--- a/lib/PublicInbox/Linkify.pm
+++ b/lib/PublicInbox/Linkify.pm
@@ -89,4 +89,33 @@ sub linkify_2 {
 	$_[1];
 }
 
+# single pass linkification of <Message-ID@example.com> within $str
+# with $pfx being the URL prefix
+sub linkify_mids {
+	my ($self, $pfx, $str) = @_;
+	$$str =~ s!<([^>]+)>!
+		my $msgid = PublicInbox::Hval->new_msgid($1);
+		my $html = $msgid->as_html;
+		my $href = $msgid->{href};
+		$href = ascii_html($href); # for IDN
+
+		# salt this, as this could be exploited to show
+		# links in the HTML which don't show up in the raw mail.
+		my $key = sha1_hex($html . $SALT);
+		$self->{$key} = [ $href, $html ];
+		'<PI-LINK-'. $key . '>';
+		!ge;
+	$$str = ascii_html($$str);
+	$$str =~ s!\bPI-LINK-([a-f0-9]{40})\b!
+		my $key = $1;
+		my $repl = $_[0]->{$key};
+		if (defined $repl) {
+			"<a\nhref=\"$pfx/$repl->[0]/\">$repl->[1]</a>";
+		} else {
+			# false positive or somebody tried to mess with us
+			$key;
+		}
+	!ge;
+}
+
 1;
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index aeb32fc8..1aa014fd 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -190,8 +190,8 @@ sub fold_addresses ($) {
 
 sub _hdr_names_html ($$) {
 	my ($hdr, $field) = @_;
-	my $val = $hdr->header($field) or return '';
-	ascii_html(join(', ', PublicInbox::Address::names($val)));
+	my @vals = $hdr->header($field) or return '';
+	ascii_html(join(', ', PublicInbox::Address::names(join(',', @vals))));
 }
 
 sub nr_to_s ($$$) {
@@ -643,12 +643,11 @@ sub _msg_html_prepare {
 	if ($over) {
 		$ctx->{-upfx} = '../';
 	}
-	my @title;
-	my $v;
-	if (defined($v = $hdr->header('From'))) {
+	my @title; # (Subject[0], From[0])
+	for my $v ($hdr->header('From')) {
 		$v = PublicInbox::Hval->new($v);
 		my @n = PublicInbox::Address::names($v->raw);
-		$title[1] = ascii_html(join(', ', @n));
+		$title[1] //= ascii_html(join(', ', @n));
 		$v = $v->as_html;
 		if ($obfs_ibx) {
 			obfuscate_addrs($obfs_ibx, $v);
@@ -657,26 +656,31 @@ sub _msg_html_prepare {
 		$rv .= "From: $v\n" if $v ne '';
 	}
 	foreach my $h (qw(To Cc)) {
-		defined($v = $hdr->header($h)) or next;
-		fold_addresses($v);
-		$v = ascii_html($v);
-		obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx;
-		$rv .= "$h: $v\n" if $v ne '';
+		for my $v ($hdr->header($h)) {
+			fold_addresses($v);
+			$v = ascii_html($v);
+			obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx;
+			$rv .= "$h: $v\n" if $v ne '';
+		}
 	}
-	if (defined($v = $hdr->header('Subject')) && ($v ne '')) {
-		$v = ascii_html($v);
-		obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx;
-		if ($over) {
-			$rv .= qq(Subject: <a\nhref="#r"\nid=t>$v</a>\n);
-		} else {
-			$rv .= "Subject: $v\n";
+	my @subj = $hdr->header('Subject');
+	if (@subj) {
+		for my $v (@subj) {
+			$v = ascii_html($v);
+			obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx;
+			$rv .= 'Subject: ';
+			if ($over) {
+				$rv .= qq(<a\nhref="#r"\nid=t>$v</a>\n);
+			} else {
+				$rv .= "$v\n";
+			}
+			$title[0] //= $v;
 		}
-		$title[0] = $v;
 	} else { # dummy anchor for thread skeleton at bottom of page
 		$rv .= qq(<a\nhref="#r"\nid=t></a>) if $over;
 		$title[0] = '(no subject)';
 	}
-	if (defined($v = $hdr->header('Date'))) {
+	for my $v ($hdr->header('Date')) {
 		$v = ascii_html($v);
 		obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx; # possible :P
 		$rv .= "Date: $v\n";
@@ -727,8 +731,9 @@ sub thread_skel {
 	$$dst .= "$nr+ messages / $expand";
 	$$dst .= qq!  <a\nhref="#b">top</a>\n!;
 
-	my $subj = $hdr->header('Subject');
-	defined $subj or $subj = '';
+	# nb: mutt only shows the first Subject in the index pane
+	# when multiple Subject: headers are present, so we follow suit:
+	my $subj = $hdr->header('Subject') // '';
 	$subj = '(no subject)' if $subj eq '';
 	$ctx->{prev_subj} = [ split(/ /, subject_normalized($subj)) ];
 	$ctx->{cur} = $mid;
@@ -746,21 +751,29 @@ sub thread_skel {
 sub _parent_headers {
 	my ($hdr, $over) = @_;
 	my $rv = '';
-
-	my $refs = references($hdr);
-	my $irt = pop @$refs;
-	if (defined $irt) {
-		my $v = PublicInbox::Hval->new_msgid($irt);
-		my $html = $v->as_html;
-		my $href = $v->{href};
-		$rv .= "In-Reply-To: &lt;";
-		$rv .= "<a\nhref=\"../$href/\">$html</a>&gt;\n";
+	my @irt = $hdr->header_raw('In-Reply-To');
+	my $refs;
+	if (@irt) {
+		my $lnk = PublicInbox::Linkify->new;
+		$rv .= "In-Reply-To: $_\n" for @irt;
+		$lnk->linkify_mids('..', \$rv);
+	} else {
+		$refs = references($hdr);
+		my $irt = pop @$refs;
+		if (defined $irt) {
+			my $v = PublicInbox::Hval->new_msgid($irt);
+			my $html = $v->as_html;
+			my $href = $v->{href};
+			$rv .= "In-Reply-To: &lt;";
+			$rv .= "<a\nhref=\"../$href/\">$html</a>&gt;\n";
+		}
 	}
 
 	# do not display References: if search is present,
 	# we show the thread skeleton at the bottom, instead.
 	return $rv if $over;
 
+	$refs //= references($hdr);
 	if (@$refs) {
 		@$refs = map { linkify_ref_no_over($_) } @$refs;
 		$rv .= 'References: '. join("\n\t", @$refs) . "\n";

^ permalink raw reply related	[relevance 5%]

* [PATCH 0/7] redundant header madness
@ 2019-10-24  0:12  7% Eric Wong
  2019-10-24  0:12  5% ` [PATCH 2/7] view: display redundant headers in permalink Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2019-10-24  0:12 UTC (permalink / raw)
  To: meta

Garbage in, garbage out.  Since we try to never drop messages in
v2, we now better support horrible messages with redundant and
confusing headers in the HTML view and search indices.

I'm a little iffy on adding more support to X-Alt-Message-IDs
because it's a gross hack; but so was injecting new Message-IDs
to support different messages with different content.

And I very much want NNTP clients to be able to build partial
mirrors without relying on expensive git clones.  Those mirrors
should still be able to lookup messages by whatever Message-IDs
the message was known by.

Eric Wong (7):
  search: support multiple From/To/Cc/Subject headers
  view: display redundant headers in permalink
  view: move '<' and '>' outside <a>
  view: improve warning for multiple Message-IDs
  linkify: support adding "(raw)" link for Message-IDs

  # next two are RFCs but I'm leaning heavily on supporting them:
  index: allow search/lookups on X-Alt-Message-ID
  view: show X-Alt-Message-ID in permalink view, too

 lib/PublicInbox/Linkify.pm   |  31 ++++++++++
 lib/PublicInbox/MID.pm       |  27 +++++++--
 lib/PublicInbox/OverIdx.pm   |   4 +-
 lib/PublicInbox/SearchIdx.pm |   4 +-
 lib/PublicInbox/SearchMsg.pm |   4 +-
 lib/PublicInbox/View.pm      | 106 ++++++++++++++++++++---------------
 t/mid.t                      |   7 ++-
 t/psgi_v2.t                  |   2 +-
 t/v2reindex.t                |  16 ++++--
 t/v2writable.t               |  16 ++++++
 10 files changed, 153 insertions(+), 64 deletions(-)

^ permalink raw reply	[relevance 7%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2019-10-24  0:12  7% [PATCH 0/7] redundant header madness Eric Wong
2019-10-24  0:12  5% ` [PATCH 2/7] view: display redundant headers in permalink Eric Wong

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