]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/WWW.pm
.txt links return an mbox instead
[public-inbox.git] / lib / PublicInbox / WWW.pm
index cd8a57055cc2410835c52e87d74ca7b0a1fd9607..86c64fb665746815a1839a9584665126a988589d 100644 (file)
@@ -53,8 +53,10 @@ sub run {
        } 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\z!o) {
-               invalid_list_mid(\%ctx, $1, $2) || get_thread_mbox(\%ctx, $cgi);
+       } 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, $cgi, $sfx);
 
        } elsif ($path_info =~ m!$LISTNAME_RE/f/\S+\.txt\z!o) {
                invalid_list_mid(\%ctx, $1, $2) ||
@@ -76,10 +78,16 @@ sub preload {
        require PublicInbox::Feed;
        require PublicInbox::View;
        require PublicInbox::Thread;
+       require PublicInbox::GitCatFile;
        require Email::MIME;
        require Digest::SHA;
        require POSIX;
-       require XML::Atom::SimpleFeed;
+
+       eval {
+               require PublicInbox::Search;
+               require PublicInbox::Mbox;
+               require IO::Compress::Gzip;
+       };
 }
 
 # private functions below
@@ -112,11 +120,10 @@ sub invalid_list_mid {
 # /$LISTNAME/atom.xml                       -> Atom feed, includes replies
 sub get_atom {
        my ($ctx, $cgi) = @_;
-       require PublicInbox::Feed;
        $ctx->{pi_config} = $pi_config;
        $ctx->{cgi} = $cgi;
-       [ 200, [ 'Content-Type' => 'application/xml' ],
-         [ PublicInbox::Feed->generate($ctx) ] ]
+       require PublicInbox::Feed;
+       PublicInbox::Feed::generate($ctx);
 }
 
 # /$LISTNAME/?r=$GIT_COMMIT                 -> HTML only
@@ -127,8 +134,7 @@ sub get_index {
        $ctx->{pi_config} = $pi_config;
        $ctx->{cgi} = $cgi;
        footer($ctx);
-       [ 200, [ 'Content-Type' => 'text/html; charset=UTF-8' ],
-         [ PublicInbox::Feed->generate_html_index($ctx) ] ]
+       PublicInbox::Feed::generate_html_index($ctx);
 }
 
 # just returns a string ref for the blob in the current ctx
@@ -151,11 +157,12 @@ sub mid2blob {
        }
 }
 
-# /$LISTNAME/m/$MESSAGE_ID.txt                    -> raw original
+# /$LISTNAME/m/$MESSAGE_ID.txt                    -> raw mbox
 sub get_mid_txt {
        my ($ctx, $cgi) = @_;
-       my $x = mid2blob($ctx);
-       $x ? [ 200, [ 'Content-Type' => 'text/plain' ], [ $$x ] ] : r404();
+       my $x = mid2blob($ctx) or return r404();
+       require PublicInbox::Mbox;
+       PublicInbox::Mbox::emit1($x);
 }
 
 # /$LISTNAME/m/$MESSAGE_ID.html                   -> HTML content (short quotes)
@@ -194,10 +201,7 @@ sub get_thread {
        my $srch = searcher($ctx) or return need_search($ctx);
        require PublicInbox::View;
        my $foot = footer($ctx);
-       my $body = PublicInbox::View->thread_html($ctx, $foot, $srch) or
-               return r404();
-       [ 200, [ 'Content-Type' => 'text/html; charset=UTF-8' ],
-         [ $body ] ];
+       PublicInbox::View::thread_html($ctx, $foot, $srch);
 }
 
 sub self_url {
@@ -329,12 +333,16 @@ sub msg_pfx {
        "../f/$href.html";
 }
 
-# /$LISTNAME/t/$MESSAGE_ID.mbox                    -> search results as 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.
 sub get_thread_mbox {
-       my ($ctx, $cgi) = @_;
+       my ($ctx, $cgi, $sfx) = @_;
        my $srch = searcher($ctx) or return need_search($ctx);
        require PublicInbox::Mbox;
-       PublicInbox::Mbox::thread_mbox($ctx, $srch);
+       PublicInbox::Mbox::thread_mbox($ctx, $srch, $sfx);
 }
 
 1;