1 # Copyright (C) 2015-2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 package PublicInbox::MboxGz;
5 use parent 'PublicInbox::GzipFilter';
7 use PublicInbox::Hval qw/to_filename/;
9 *msg_hdr = \&PublicInbox::Mbox::msg_hdr;
10 *msg_body = \&PublicInbox::Mbox::msg_body;
13 my ($http) = @_; # PublicInbox::HTTP
14 my $ctx = $http->{forward} or return;
16 $ctx->{smsg} = $ctx->{cb}->($ctx) or return $ctx->close;
17 $ctx->smsg_blob($ctx->{smsg});
23 my ($self, $cb, $fn) = @_;
25 $self->{base_url} = $self->{ibx}->base_url($self->{env});
26 $self->{gz} = PublicInbox::GzipFilter::gzip_or_die();
27 $fn = to_filename($fn // '') // 'no-subject';
28 # http://www.iana.org/assignments/media-types/application/gzip
29 bless $self, __PACKAGE__;
30 my $res_hdr = [ 'Content-Type' => 'application/gzip',
31 'Content-Disposition' => "inline; filename=$fn.mbox.gz" ];
32 $self->psgi_response(200, $res_hdr);
35 # called by Plack::Util::foreach or similar (generic PSGI)
38 my $cb = $self->{cb} or return;
39 while (my $smsg = $cb->($self)) {
40 my $eml = $self->{ibx}->smsg_eml($smsg) or next;
41 $self->zmore(msg_hdr($self, $eml));
42 return $self->translate(msg_body($eml));
44 # signal that we're done and can return undef next call:
50 *async_eml = \&PublicInbox::Mbox::async_eml;