1 # Copyright (C) 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->{gz} = PublicInbox::GzipFilter::gzip_or_die();
26 $fn = to_filename($fn // '') // 'no-subject';
27 # http://www.iana.org/assignments/media-types/application/gzip
28 bless $self, __PACKAGE__;
29 my $res_hdr = [ 'Content-Type' => 'application/gzip',
30 'Content-Disposition' => "inline; filename=$fn.mbox.gz" ];
31 $self->psgi_response(200, $res_hdr);
34 # called by Plack::Util::foreach or similar (generic PSGI)
37 my $cb = $self->{cb} or return;
38 while (my $smsg = $cb->($self)) {
39 my $eml = $self->{ibx}->smsg_eml($smsg) or next;
40 $self->zmore(msg_hdr($self, $eml));
41 return $self->translate(msg_body($eml));
43 # signal that we're done and can return undef next call:
49 *async_eml = \&PublicInbox::Mbox::async_eml;