]> Sergey Matveev's repositories - public-inbox.git/commitdiff
mbox: support uncompressed mbox
authorEric Wong <e@80x24.org>
Sat, 22 Aug 2015 11:41:23 +0000 (11:41 +0000)
committerEric Wong <e@80x24.org>
Sat, 22 Aug 2015 11:42:37 +0000 (11:42 +0000)
Some folks may want to view the mbox inline as a string of raw text,
when guessing URLs.  Let them do this...

lib/PublicInbox/Mbox.pm
lib/PublicInbox/WWW.pm

index 5f5612a4fc3c81a74bb7649a792c9d5420f6b2f7..d49e9b39da0e9d96864a4c4c8e04aa56a5537505 100644 (file)
@@ -7,10 +7,10 @@ use warnings;
 use PublicInbox::MID qw/mid_compressed mid2path/;
 
 sub thread_mbox {
-       my ($ctx, $srch) = @_;
+       my ($ctx, $srch, $sfx) = @_;
        sub {
                my ($response) = @_; # Plack callback
-               emit_mbox($response, $ctx, $srch);
+               emit_mbox($response, $ctx, $srch, $sfx);
        }
 }
 
@@ -38,14 +38,18 @@ sub emit_msg {
 }
 
 sub emit_mbox {
-       my ($response, $ctx, $srch) = @_;
-       eval { require IO::Compress::Gzip };
-       return need_gzip($response) if $@;
+       my ($response, $ctx, $srch, $sfx) = @_;
+       my $type = 'mbox';
+       if ($sfx) {
+               eval { require IO::Compress::Gzip };
+               return need_gzip($response) if $@;
+               $type = 'gzip';
+       }
 
        # http://www.iana.org/assignments/media-types/application/gzip
        # http://www.iana.org/assignments/media-types/application/mbox
-       my $fh = $response->([200, ['Content-Type' => 'application/gzip']]);
-       $fh = PublicInbox::MboxGz->new($fh);
+       my $fh = $response->([200, ['Content-Type' => "application/$type"]]);
+       $fh = PublicInbox::MboxGz->new($fh) if $sfx;
 
        require PublicInbox::GitCatFile;
        require Email::Simple;
index 30a7a436df3d12ecce2bb96c980b058e38132975..33c7110147bf451627eb6e5d7b0dac7c4d669cea 100644 (file)
@@ -53,9 +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\.gz!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, $cgi);
+               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) ||
@@ -331,15 +332,16 @@ sub msg_pfx {
        "../f/$href.html";
 }
 
-# /$LISTNAME/t/$MESSAGE_ID.mbox.gz        -> search results 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.
 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;