-sub mbox_all {
- my ($ctx, $query) = @_;
-
- eval { require IO::Compress::Gzip };
- return sub { need_gzip(@_) } if $@;
- if ($query eq '') {
- my $prev = 0;
- my $cb = sub { $ctx->{-inbox}->mm->ids_after(\$prev) };
- return PublicInbox::MboxGz->response($ctx, $cb, 'all');
- }
- my $opts = { offset => 0 };
- my $srch = $ctx->{srch};
- my $cb = sub { # called by MboxGz->getline
- my $msgs = $srch->query($query, $opts);
- $opts->{offset} += scalar @$msgs;
- $msgs;
- };
- 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 => [],
- }, $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;
- my $hdr = $body->getline; # fill in Content-Disposition filename
- [ 200, $hdr, $body ];
-}
-
-sub set_filename ($$) {
- my ($fn, $msg) = @_;
- return to_filename($fn) if defined($fn);
-
- PublicInbox::Mbox::subject_fn($msg);