unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 06/10] extmsg: disable automatic inbox switching
Date: Wed,  6 Jul 2016 07:14:31 +0000	[thread overview]
Message-ID: <20160706071435.18143-7-e@80x24.org> (raw)
In-Reply-To: <20160706071435.18143-1-e@80x24.org>

Automatic inbox switching was a potentially deceptive pattern
and surprises readers who do not check the URL bar closely.
Furthermore, a message could be cross-posted to multiple lists,
too.
---
 lib/PublicInbox/ExtMsg.pm | 57 ++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 44 insertions(+), 13 deletions(-)

diff --git a/lib/PublicInbox/ExtMsg.pm b/lib/PublicInbox/ExtMsg.pm
index 62381e9..4925a59 100644
--- a/lib/PublicInbox/ExtMsg.pm
+++ b/lib/PublicInbox/ExtMsg.pm
@@ -8,9 +8,9 @@
 package PublicInbox::ExtMsg;
 use strict;
 use warnings;
-use URI::Escape qw(uri_escape_utf8);
 use PublicInbox::Hval;
 use PublicInbox::MID qw/mid2path/;
+use PublicInbox::WwwStream;
 
 # TODO: user-configurable
 our @EXT_URL = (
@@ -61,19 +61,21 @@ sub ext_msg {
 		}
 	});
 
-	# TODO: multiple hits
-	return r302($found[0], $mid) if @found;
+	return exact($ctx, \@found, $mid) if @found;
 
 	# Xapian not installed or configured for some repos,
-	# do a full MID check:
+	# do a full MID check (this is expensive...):
 	if (@nox) {
 		my $path = mid2path($mid);
 		foreach my $other (@nox) {
 			my (undef, $type, undef) = $other->path_check($path);
 
-			return r302($other, $mid) if $type && $type eq 'blob';
+			if ($type && $type eq 'blob') {
+				push @found, $other;
+			}
 		}
 	}
+	return exact($ctx, \@found, $mid) if @found;
 
 	# fall back to partial MID matching
 	my $n_partial = 0;
@@ -138,14 +140,43 @@ again:
 	[$code, ['Content-Type'=>'text/html; charset=UTF-8'], [$s]];
 }
 
-# Redirect to another public-inbox which is mapped by $pi_config
-# TODO: prompt for inbox-switching
-sub r302 {
-	my ($inbox, $mid) = @_;
-	my $url = $inbox->base_url . uri_escape_utf8($mid) . '/';
-	[ 302,
-	  [ 'Location' => $url, 'Content-Type' => 'text/plain' ],
-	  [ "Redirecting to\n$url\n" ] ]
+sub ext_urls {
+	my ($ctx, $mid, $href, $html) = @_;
+
+	# Fall back to external repos if configured
+	if (@EXT_URL && index($mid, '@') >= 0) {
+		my $env = $ctx->{env};
+		my $e = "\nPerhaps try an external site:\n\n";
+		foreach my $url (@EXT_URL) {
+			my $u = PublicInbox::Hval::prurl($env, $url);
+			my $r = sprintf($u, $href);
+			my $t = sprintf($u, $html);
+			$e .= qq{<a\nhref="$r">$t</a>\n};
+		}
+		return $e;
+	}
+	''
+}
+
+sub exact {
+	my ($ctx, $found, $mid) = @_;
+	my $h = PublicInbox::Hval->new_msgid($mid);
+	my $href = $h->as_href;
+	my $html = $h->as_html;
+	my $title = "&lt;$html&gt; found in ";
+	my $end = @$found == 1 ? 'another inbox' : 'other inboxes';
+	$ctx->{-title_html} = $title . $end;
+	$ctx->{-upfx} = '../';
+	my $ext_urls = ext_urls($ctx, $mid, $href, $html);
+	my $code = (@$found == 1 && $ext_urls eq '') ? 200 : 300;
+	$ctx->{-html_tip} = join('',
+			"<pre>Message-ID: &lt;$html&gt;\nfound in $end:\n\n",
+				(map {
+					my $u = $_->base_url;
+					qq(<a\nhref="$u$href/">$u$html/</a>\n)
+				} @$found),
+			$ext_urls, '</pre>');
+	PublicInbox::WwwStream->response($ctx, $code);
 }
 
 1;
-- 
EW


  parent reply	other threads:[~2016-07-06  7:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-06  7:14 [PATCH 0/10] various misc fixes and updates Eric Wong
2016-07-06  7:14 ` [PATCH 01/10] scripts/dc-dlvr: ensure temporary files are removed Eric Wong
2016-07-06  7:14 ` [PATCH 02/10] daemon: disable USR2/TTIN/TTOU/WINCH in workers Eric Wong
2016-07-06  7:14 ` [PATCH 03/10] hval: get rid of unused parameter for new_msgid Eric Wong
2016-07-06  7:14 ` [PATCH 04/10] address: attempt to handle comments somewhat Eric Wong
2016-07-06  7:14 ` [PATCH 05/10] wwwstream: allow undef noop callback Eric Wong
2016-07-06  7:14 ` Eric Wong [this message]
2016-07-06  7:14 ` [PATCH 07/10] extmsg: switch to wwwstream for partial match, too Eric Wong
2016-07-06  7:14 ` [PATCH 08/10] view: fix double-escaping of ghost links Eric Wong
2016-07-06  7:14 ` [PATCH 09/10] www: use HTML <hr> instead of XHTML <hr /> Eric Wong
2016-07-06  7:14 ` [PATCH 10/10] feed: fix links to attachments in Atom feed 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=20160706071435.18143-7-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.
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).