user/dev discussion of public-inbox itself
 help / color / Atom feed
01e34d7b136b9d87e1931f4bac43b635c048de95 blob 1459 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 
# Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
#
# Plack app redirector for mapping /$NEWSGROUP requests to
# the appropriate /$INBOX in PublicInbox::WWW because some
# auto-linkifiers cannot handle nntp:// redirects properly.
# This is also used directly by PublicInbox::WWW
package PublicInbox::NewsWWW;
use strict;
use warnings;
use PublicInbox::Config;
use PublicInbox::MID qw(mid_escape);

sub new {
	my ($class, $pi_config) = @_;
	$pi_config ||= PublicInbox::Config->new;
	bless { pi_config => $pi_config }, $class;
}

sub call {
	my ($self, $env) = @_;
	my $path = $env->{PATH_INFO};
	$path =~ s!\A/+!!;
	$path =~ s!/+\z!!;

	# some links may have the article number in them:
	# /inbox.foo.bar/123456
	my ($ng, $article) = split(m!/+!, $path, 2);
	if (my $inbox = $self->{pi_config}->lookup_newsgroup($ng)) {
		my $url = PublicInbox::Hval::prurl($env, $inbox->{url});
		my $code = 301;
		if (defined $article && $article =~ /\A\d+\z/) {
			my $mid = eval { $inbox->mm->mid_for($article) };
			if (defined $mid) {
				# article IDs are not stable across clones,
				# do not encourage caching/bookmarking them
				$code = 302;
				$url .= mid_escape($mid) . '/';
			}
		}

		my $h = [ Location => $url, 'Content-Type' => 'text/plain' ];

		return [ $code, $h, [ "Redirecting to $url\n" ] ]
	}
	[ 404, [ 'Content-Type' => 'text/plain' ], [ "404 Not Found\n" ] ];
}

1;
debug log:

solving 01e34d7 ...
found 01e34d7 in https://80x24.org/public-inbox.git

user/dev discussion of public-inbox itself

Archives are clonable:
	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

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

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