From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-3.1 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, URIBL_BLOCKED shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: meta@public-inbox.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id EA2261FAE9 for ; Sat, 22 Aug 2015 11:41:24 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 5/6] mbox: support uncompressed mbox Date: Sat, 22 Aug 2015 11:41:23 +0000 Message-Id: <1440243684-2205-5-git-send-email-e@80x24.org> In-Reply-To: <1440243684-2205-1-git-send-email-e@80x24.org> References: <1440243684-2205-1-git-send-email-e@80x24.org> List-Id: 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 | 18 +++++++++++------- lib/PublicInbox/WWW.pm | 12 +++++++----- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm index 5f5612a..d49e9b3 100644 --- a/lib/PublicInbox/Mbox.pm +++ b/lib/PublicInbox/Mbox.pm @@ -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; diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index 30a7a43..33c7110 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -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; -- EW