+sub mbox_all {
+ my ($ctx, $query) = @_;
+
+ eval { require IO::Compress::Gzip };
+ return sub { need_gzip(@_) } if $@;
+ my $cb = sub { $ctx->{srch}->query($query, @_) };
+ PublicInbox::MboxGz->response($ctx, $cb, 'results-'.$query);
+}
+
+sub need_gzip {
+ my $fh = $_[0]->([501, ['Content-Type' => 'text/html']]);
+ my $title = 'gzipped mbox not available';
+ $fh->write(<<EOF);
+<html><head><title>$title</title><body><pre>$title
+The administrator needs to install the IO::Compress::Gzip Perl module
+to support gzipped mboxes.
+<a href="../">Return to index</a></pre></body></html>
+EOF
+ $fh->close;
+}
+
+1;
+
+package PublicInbox::MboxGz;
+use strict;
+use warnings;
+use PublicInbox::Hval qw/to_filename/;
+
+sub new {
+ my ($class, $ctx, $cb) = @_;
+ my $buf = '';
+ bless {
+ buf => \$buf,
+ gz => IO::Compress::Gzip->new(\$buf, Time => 0),
+ cb => $cb,
+ ctx => $ctx,
+ msgs => [],
+ opts => { offset => 0 },
+ }, $class;
+}
+
+sub response {
+ my ($class, $ctx, $cb, $fn) = @_;
+ my $body = $class->new($ctx, $cb);
+ # http://www.iana.org/assignments/media-types/application/gzip
+ $body->{hdr} = [ 'Content-Type', 'application/gzip' ];
+ $body->{fn} = $fn;
+ # fill in Content-Disposition filename
+ my $hdr = $body->getline;
+ if ($body->{hdr}) {
+ return [ 404, ['Content-Type','text/plain'],
+ [ "No results found\n" ] ];