]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/WWW.pm
switch to gzipped mboxes
[public-inbox.git] / lib / PublicInbox / WWW.pm
index be34e1cd544d742de593859ab9b0a7c37ea68a22..68839d7cee3ef3af33717f48b5d3aacda1c20c94 100644 (file)
@@ -2,7 +2,7 @@
 # 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
@@ -53,10 +53,13 @@ sub run {
        } elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)\.html\z!o) {
                invalid_list_mid(\%ctx, $1, $2) || get_thread(\%ctx, $cgi);
 
-       # subject_path display
-       } elsif ($path_info =~ m!$LISTNAME_RE/s/(\S+)\.html\z!o) {
-               my $sp = $2;
-               invalid_list(\%ctx, $1) || get_subject_path(\%ctx, $cgi, $sp);
+       } 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|t|s)/(\S+)\z!o) {
@@ -198,19 +201,6 @@ sub get_thread {
          [ $body ] ];
 }
 
-# /$LISTNAME/s/$SUBJECT_PATH.html
-sub get_subject_path {
-       my ($ctx, $cgi, $sp) = @_;
-       $ctx->{subject_path} = $sp;
-       my $srch = searcher($ctx) or return need_search($ctx);
-       require PublicInbox::View;
-       my $foot = footer($ctx);
-       my $body = PublicInbox::View->subject_path_html($ctx, $foot, $srch) or
-               return r404();
-       [ 200, [ 'Content-Type' => 'text/html; charset=UTF-8' ],
-         [ $body ] ];
-}
-
 sub self_url {
        my ($cgi) = @_;
        ref($cgi) eq 'CGI' ? $cgi->self_url : $cgi->uri->as_string;
@@ -231,6 +221,15 @@ sub redirect_mid {
        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!/$listname/f/(\S+\.txt)\z!/$listname/m/$1!;
+       do_redirect($url);
+}
+
 sub do_redirect {
        my ($url) = @_;
        [ 301,
@@ -295,7 +294,6 @@ sub footer {
        }
 
        $addr = "<a\nhref=\"mailto:$addr\">$addr</a>";
-       $desc =  $desc;
 
        $ctx->{footer} = join("\n",
                '- ' . $desc,
@@ -332,4 +330,15 @@ sub msg_pfx {
        "../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;