# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
#
# We focus on the lowest common denominators here:
-# - targeted at text-only console browsers (lynx, w3m, etc..)
+# - targeted at text-only console browsers (w3m, links, etc..)
# - Only basic HTML, CSS only for line-wrapping <pre> text content for GUIs
# - No JavaScript, graphics or icons allowed.
# - Must not rely on static content
} elsif ($path_info =~ m!$LISTNAME_RE\z!o) {
invalid_list(\%ctx, $1) || redirect_list_index(\%ctx, $cgi);
} elsif ($path_info =~ m!$LISTNAME_RE(?:/|/index\.html)?\z!o) {
- invalid_list(\%ctx, $1) || get_index(\%ctx, $cgi, 0);
+ invalid_list(\%ctx, $1) || get_index(\%ctx, $cgi);
} elsif ($path_info =~ m!$LISTNAME_RE/atom\.xml\z!o) {
- invalid_list(\%ctx, $1) || get_atom(\%ctx, $cgi, 0);
+ invalid_list(\%ctx, $1) || get_atom(\%ctx, $cgi);
# single-message pages
} elsif ($path_info =~ m!$LISTNAME_RE/m/(\S+)\.txt\z!o) {
} elsif ($path_info =~ m!$LISTNAME_RE/f/(\S+)\.html\z!o) {
invalid_list_mid(\%ctx, $1, $2) || get_full_html(\%ctx, $cgi);
+ # thread display
+ } elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)\.html\z!o) {
+ invalid_list_mid(\%ctx, $1, $2) || get_thread(\%ctx, $cgi);
+
+ } elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)\.mbox\.gz!o) {
+ my $sfx = $3;
+ invalid_list_mid(\%ctx, $1, $2) || get_thread_mbox(\%ctx, $cgi);
+
+ } elsif ($path_info =~ m!$LISTNAME_RE/f/\S+\.txt\z!o) {
+ invalid_list_mid(\%ctx, $1, $2) ||
+ redirect_mid_txt(\%ctx, $cgi);
+
# convenience redirects, order matters
- } elsif ($path_info =~ m!$LISTNAME_RE/(?:m|f)/(\S+)\z!o) {
- invalid_list_mid(\%ctx, $1, $2) || redirect_mid(\%ctx, $cgi);
+ } 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, $cgi, $2);
} else {
r404();
# /$LISTNAME/atom.xml -> Atom feed, includes replies
sub get_atom {
- my ($ctx, $cgi, $top) = @_;
+ my ($ctx, $cgi) = @_;
require PublicInbox::Feed;
+ $ctx->{pi_config} = $pi_config;
+ $ctx->{cgi} = $cgi;
[ 200, [ 'Content-Type' => 'application/xml' ],
- [ PublicInbox::Feed->generate({
- git_dir => $ctx->{git_dir},
- listname => $ctx->{listname},
- pi_config => $pi_config,
- cgi => $cgi,
- top => $top,
- }) ]
- ];
+ [ PublicInbox::Feed->generate($ctx) ] ]
}
# /$LISTNAME/?r=$GIT_COMMIT -> HTML only
sub get_index {
- my ($ctx, $cgi, $top) = @_;
+ my ($ctx, $cgi) = @_;
require PublicInbox::Feed;
+ my $srch = searcher($ctx);
+ $ctx->{pi_config} = $pi_config;
+ $ctx->{cgi} = $cgi;
+ footer($ctx);
[ 200, [ 'Content-Type' => 'text/html; charset=UTF-8' ],
- [ PublicInbox::Feed->generate_html_index({
- git_dir => $ctx->{git_dir},
- listname => $ctx->{listname},
- pi_config => $pi_config,
- cgi => $cgi,
- footer => footer($ctx),
- top => $top,
- }) ]
- ];
+ [ PublicInbox::Feed->generate_html_index($ctx) ] ]
}
# just returns a string ref for the blob in the current ctx
sub mid2blob {
my ($ctx) = @_;
- require Digest::SHA;
- my $hex = Digest::SHA::sha1_hex($ctx->{mid});
- $hex =~ /\A([a-f0-9]{2})([a-f0-9]{38})\z/i or
- die "BUG: not a SHA-1 hex: $hex";
-
+ require PublicInbox::MID;
+ my $path = PublicInbox::MID::mid2path($ctx->{mid});
my @cmd = ('git', "--git-dir=$ctx->{git_dir}",
- qw(cat-file blob), "HEAD:$1/$2");
+ qw(cat-file blob), "HEAD:$path");
my $cmd = join(' ', @cmd);
my $pid = open my $fh, '-|';
defined $pid or die "fork failed: $!\n";
return r404() unless $x;
require PublicInbox::View;
- my $mid_href = PublicInbox::Hval::ascii_html(
- uri_escape_utf8($ctx->{mid}));
- my $pfx = "../f/$mid_href.html";
+ my $pfx = msg_pfx($ctx);
my $foot = footer($ctx);
require Email::MIME;
+ my $mime = Email::MIME->new($x);
+ my $srch = searcher($ctx);
[ 200, [ 'Content-Type' => 'text/html; charset=UTF-8' ],
- [ PublicInbox::View->msg_html(Email::MIME->new($x), $pfx, $foot) ] ];
+ [ PublicInbox::View->msg_html($mime, $pfx, $foot, $srch) ] ];
}
# /$LISTNAME/f/$MESSAGE_ID.html -> HTML content (fullquotes)
my $x = mid2blob($ctx);
return r404() unless $x;
require PublicInbox::View;
+ my $foot = footer($ctx);
require Email::MIME;
+ my $mime = Email::MIME->new($x);
+ my $srch = searcher($ctx);
+ [ 200, [ 'Content-Type' => 'text/html; charset=UTF-8' ],
+ [ PublicInbox::View->msg_html($mime, undef, $foot, $srch)] ];
+}
+
+# /$LISTNAME/t/$MESSAGE_ID.html
+sub get_thread {
+ my ($ctx, $cgi) = @_;
+ my $srch = searcher($ctx) or return need_search($ctx);
+ require PublicInbox::View;
my $foot = footer($ctx);
- [ 200, [ 'Content-Type' => 'text/html' ],
- [ PublicInbox::View->msg_html(Email::MIME->new($x), undef, $foot)] ];
+ my $body = PublicInbox::View->thread_html($ctx, $foot, $srch) or
+ return r404();
+ [ 200, [ 'Content-Type' => 'text/html; charset=UTF-8' ],
+ [ $body ] ];
}
sub self_url {
}
sub redirect_mid {
- my ($ctx, $cgi) = @_;
+ my ($ctx, $cgi, $pfx) = @_;
+ my $url = self_url($cgi);
+ my $anchor = '';
+ if (lc($pfx) eq 't') {
+ $anchor = '#u'; # <u id='#u'> is used to highlight in View.pm
+ }
+ do_redirect($url . ".html$anchor");
+}
+
+# only hit when somebody tries to guess URLs manually:
+sub redirect_mid_txt {
+ my ($ctx, $cgi, $pfx) = @_;
+ my $listname = $ctx->{listname};
my $url = self_url($cgi);
- $url =~ s!/f/!/m/!;
- do_redirect($url . '.html');
+ $url =~ s!/$listname/f/(\S+\.txt)\z!/$listname/m/$1!;
+ do_redirect($url);
}
sub do_redirect {
my $footer = try_cat("$git_dir/public-inbox/footer.html");
if (defined $footer) {
chomp $footer;
+ $ctx->{footer} = $footer;
return $footer;
}
if ($nurls == 0) {
$urls = '($GIT_DIR/cloneurl missing)';
} elsif ($nurls == 1) {
- $urls = 'git archive URL for <a href="' . SSOMA_URL .
+ $urls = "git URL for <a\nhref=\"" . SSOMA_URL .
'">ssoma</a>: ' . $urls[0];
} else {
- $urls = 'git archive URLs for <a href="' . SSOMA_URL .
- "\">ssoma</a>:\n" . join('', map { "\t" . $_ } @urls);
+ $urls = "git URLs for <a\nhref=\"" . SSOMA_URL .
+ "\">ssoma</a>:\n" . join("\n", map { "\t$_" } @urls);
}
my $addr = $pi_config->get($listname, 'address');
$addr = $addr->[0]; # first address is primary
}
- $addr = "<a href=\"mailto:$addr\">$addr</a>";
- $desc = $desc;
- join("\n",
+ $addr = "<a\nhref=\"mailto:$addr\">$addr</a>";
+
+ $ctx->{footer} = join("\n",
'- ' . $desc,
- 'This is a <a href="' . PI_URL . '">public-inbox</a>, '.
- "anybody may post:",
- "\t$addr (text-only, no HTML please)",
+ "A <a\nhref=\"" . PI_URL . '">public-inbox</a>, ' .
+ 'anybody may post in plain-text (not HTML):',
+ $addr,
$urls
);
}
+# search support is optional, returns undef if Xapian is not installed
+# or not configured for the given GIT_DIR
+sub searcher {
+ my ($ctx) = @_;
+ eval {
+ require PublicInbox::Search;
+ $ctx->{srch} = PublicInbox::Search->new($ctx->{git_dir});
+ };
+}
+
+sub need_search {
+ my ($ctx) = @_;
+ my $msg = <<EOF;
+<html><head><title>Search not available for this
+public-inbox</title><body><pre>Search is not available for this public-inbox
+<a href="../">Return to index</a></pre></body></html>
+EOF
+ [ 501, [ 'Content-Type' => 'text/html; charset=UTF-8' ], [ $msg ] ];
+}
+
+sub msg_pfx {
+ my ($ctx) = @_;
+ my $href = PublicInbox::Hval::ascii_html(uri_escape_utf8($ctx->{mid}));
+ "../f/$href.html";
+}
+
+# /$LISTNAME/t/$MESSAGE_ID.mbox.gz -> search results 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.
+sub get_thread_mbox {
+ my ($ctx, $cgi) = @_;
+ my $srch = searcher($ctx) or return need_search($ctx);
+ require PublicInbox::Mbox;
+ PublicInbox::Mbox::thread_mbox($ctx, $srch);
+}
+
1;