From 6b51c6e762de67636c90b678b4bb28f970379b3c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 22 Aug 2015 11:41:23 +0000 Subject: mbox: support uncompressed mbox 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 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'lib/PublicInbox/Mbox.pm') diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm index 5f5612a4..d49e9b39 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; -- cgit v1.2.3-24-ge0c7