$title$title
-The administrator needs to install the IO::Compress::Gzip Perl module
+The administrator needs to install the Compress::Raw::Zlib Perl module
to support gzipped mboxes.
Return to index
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;
- 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);
-}
-# called by Plack::Util::foreach or similar
-sub getline {
- my ($self) = @_;
- my $ctx = $self->{ctx} or return;
- my $res;
- my $ibx = $ctx->{-inbox};
- my $gz = $self->{gz};
- do {
- # work on existing result set
- while (defined(my $smsg = shift @{$self->{msgs}})) {
- my $msg = eval { $ibx->msg_by_smsg($smsg) } or next;
- $msg = Email::Simple->new($msg);
- $gz->write(PublicInbox::Mbox::msg_str($ctx, $msg));
-
- # use subject of first message as subject
- if (my $hdr = delete $self->{hdr}) {
- my $fn = set_filename($self->{fn}, $msg);
- push @$hdr, 'Content-Disposition',
- "inline; filename=$fn.mbox.gz";
- return $hdr;
- }
- my $bref = $self->{buf};
- if (length($$bref) >= 8192) {
- my $ret = $$bref; # copy :<
- ${$self->{buf}} = '';
- return $ret;
- }
-
- # be fair to other clients on public-inbox-httpd:
- return '';
- }
-
- # refill result set
- $res = $self->{cb}->($self->{opts});
- $self->{msgs} = $res->{msgs};
- $res = scalar @{$self->{msgs}};
- $self->{opts}->{offset} += $res;
- } while ($res);
- $gz->close;
- delete $self->{ctx};
- ${delete $self->{buf}};
+ [501,[qw(Content-Type text/html Content-Length), bytes::length($body)],
+ [ $body ] ];
}
-sub close {} # noop
-
1;