use constant PI_URL => 'http://public-inbox.org/';
our $LISTNAME_RE = qr!\A/([\w\.\-]+)!;
our $pi_config;
-BEGIN {
- $pi_config = PublicInbox::Config->new;
-}
sub run {
my ($cgi, $method) = @_;
+ $pi_config ||= PublicInbox::Config->new;
my %ctx = (cgi => $cgi, pi_config => $pi_config);
if ($method !~ /\AGET|HEAD\z/) {
return r(405, 'Method Not Allowed');
invalid_list(\%ctx, $1) || redirect_list_index($cgi);
} elsif ($path_info =~ m!$LISTNAME_RE(?:/|/index\.html)?\z!o) {
invalid_list(\%ctx, $1) || get_index(\%ctx);
- } elsif ($path_info =~ m!$LISTNAME_RE/atom\.xml\z!o) {
+ } elsif ($path_info =~ m!$LISTNAME_RE/(?:atom\.xml|new\.atom)\z!o) {
invalid_list(\%ctx, $1) || get_atom(\%ctx);
# single-message pages
- } elsif ($path_info =~ m!$LISTNAME_RE/m/(\S+)\.txt\z!o) {
- invalid_list_mid(\%ctx, $1, $2) || get_mid_txt(\%ctx);
- } elsif ($path_info =~ m!$LISTNAME_RE/m/(\S+)\.html\z!o) {
+ } elsif ($path_info =~ m!$LISTNAME_RE/m/(\S+)/\z!o) {
invalid_list_mid(\%ctx, $1, $2) || get_mid_html(\%ctx);
+ } elsif ($path_info =~ m!$LISTNAME_RE/m/(\S+)/raw\z!o) {
+ invalid_list_mid(\%ctx, $1, $2) || get_mid_txt(\%ctx);
# full-message page
- } elsif ($path_info =~ m!$LISTNAME_RE/f/(\S+)\.html\z!o) {
+ } elsif ($path_info =~ m!$LISTNAME_RE/f/(\S+)/\z!o) {
invalid_list_mid(\%ctx, $1, $2) || get_full_html(\%ctx);
# thread display
- } elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)\.html\z!o) {
+ } elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)/\z!o) {
invalid_list_mid(\%ctx, $1, $2) || get_thread(\%ctx);
- } elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)\.mbox(\.gz)?\z!o) {
+ } elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)/mbox(\.gz)?\z!o) {
my $sfx = $3;
invalid_list_mid(\%ctx, $1, $2) ||
get_thread_mbox(\%ctx, $sfx);
- } elsif ($path_info =~ m!$LISTNAME_RE/f/\S+\.txt\z!o) {
- invalid_list_mid(\%ctx, $1, $2) || redirect_mid_txt(\%ctx);
+ } elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)/atom\z!o) {
+ invalid_list_mid(\%ctx, $1, $2) || get_thread_atom(\%ctx);
+
+ # legacy redirects
+ } elsif ($path_info =~ m!$LISTNAME_RE/(t|m|f)/(\S+)\.html\z!o) {
+ my $pfx = $2;
+ invalid_list_mid(\%ctx, $1, $3) ||
+ redirect_mid(\%ctx, $pfx, qr/\.html\z/, '/');
+ } elsif ($path_info =~ m!$LISTNAME_RE/(m|f)/(\S+)\.txt\z!o) {
+ my $pfx = $2;
+ invalid_list_mid(\%ctx, $1, $3) ||
+ redirect_mid(\%ctx, $pfx, qr/\.txt\z/, '/raw');
+ } elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)(\.mbox(?:\.gz)?)\z!o) {
+ my $end = $3;
+ invalid_list_mid(\%ctx, $1, $2) ||
+ redirect_mid(\%ctx, 't', $end, '/mbox.gz');
# convenience redirects, order matters
} elsif ($path_info =~ m!$LISTNAME_RE/(m|f|t|s)/(\S+)\z!o) {
my $pfx = $2;
- invalid_list_mid(\%ctx, $1, $3) || redirect_mid(\%ctx, $2);
+ invalid_list_mid(\%ctx, $1, $3) ||
+ redirect_mid(\%ctx, $pfx, qr/\z/, '/');
} else {
r404();
$ret;
}
-# /$LISTNAME/atom.xml -> Atom feed, includes replies
+# /$LISTNAME/new.atom -> Atom feed, includes replies
sub get_atom {
my ($ctx) = @_;
require PublicInbox::Feed;
my $path = PublicInbox::MID::mid2path($ctx->{mid});
my @cmd = ('git', "--git-dir=$ctx->{git_dir}",
qw(cat-file blob), "HEAD:$path");
- my $cmd = join(' ', @cmd);
my $pid = open my $fh, '-|';
defined $pid or die "fork failed: $!\n";
if ($pid == 0) {
# /$LISTNAME/m/$MESSAGE_ID.html -> HTML content (short quotes)
sub get_mid_html {
my ($ctx) = @_;
- my $x = mid2blob($ctx);
- return r404() unless $x;
+ my $x = mid2blob($ctx) or return r404();
require PublicInbox::View;
my $pfx = msg_pfx($ctx);
# /$LISTNAME/f/$MESSAGE_ID.html -> HTML content (fullquotes)
sub get_full_html {
my ($ctx) = @_;
- my $x = mid2blob($ctx);
- return r404() unless $x;
+ my $x = mid2blob($ctx) or return r404();
+
require PublicInbox::View;
my $foot = footer($ctx);
require Email::MIME;
}
sub redirect_mid {
- my ($ctx, $pfx) = @_;
+ my ($ctx, $pfx, $old, $sfx) = @_;
my $url = self_url($ctx->{cgi});
my $anchor = '';
- if (lc($pfx) eq 't') {
+ if (lc($pfx) eq 't' && $sfx eq '/') {
$anchor = '#u'; # <u id='#u'> is used to highlight in View.pm
}
- do_redirect($url . ".html$anchor");
+ $url =~ s/$old/$sfx/;
+ do_redirect($url . $anchor);
}
# only hit when somebody tries to guess URLs manually:
sub ctx_get {
my ($ctx, $key) = @_;
my $val = $ctx->{$key};
- (defined $val && length $val) or die "BUG: bad ctx, $key unusable\n";
+ (defined $val && $val ne '') or die "BUG: bad ctx, $key unusable\n";
$val;
}
sub msg_pfx {
my ($ctx) = @_;
my $href = PublicInbox::Hval::ascii_html(uri_escape_utf8($ctx->{mid}));
- "../f/$href.html";
+ "../../f/$href/";
}
-# /$LISTNAME/t/$MESSAGE_ID.mbox -> thread as mbox
-# /$LISTNAME/t/$MESSAGE_ID.mbox.gz -> thread as gzipped mbox
+# /$LISTNAME/t/$MESSAGE_ID/mbox -> thread as mbox
+# /$LISTNAME/t/$MESSAGE_ID/mbox.gz -> thread as gzipped mbox
# note: I'm not a big fan of other compression formats since they're
# significantly more expensive on CPU than gzip and less-widely available,
# especially on older systems. Stick to zlib since that's what git uses.
PublicInbox::Mbox::thread_mbox($ctx, $srch, $sfx);
}
+
+# /$LISTNAME/t/$MESSAGE_ID/atom -> thread as Atom feed
+sub get_thread_atom {
+ my ($ctx) = @_;
+ searcher($ctx) or return need_search($ctx);
+ $ctx->{self_url} = self_url($ctx->{cgi});
+ require PublicInbox::Feed;
+ PublicInbox::Feed::generate_thread_atom($ctx);
+}
+
1;