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/;
11 my ($class, $ctx, $cb) = @_;
12 $ctx->{base_url} = $ctx->{-inbox}->base_url($ctx->{env});
14 gz => PublicInbox::GzipFilter::gzip_or_die(),
21 my ($class, $ctx, $cb, $fn) = @_;
22 my $body = $class->new($ctx, $cb);
23 # http://www.iana.org/assignments/media-types/application/gzip
24 $fn = defined($fn) && $fn ne '' ? to_filename($fn) : 'no-subject';
25 my $h = [ qw(Content-Type application/gzip),
26 'Content-Disposition', "inline; filename=$fn.mbox.gz" ];
30 # called by Plack::Util::foreach or similar
33 my $ctx = $self->{ctx} or return;
34 while (my $smsg = $self->{cb}->($ctx)) {
35 my $mref = $ctx->{-inbox}->msg_by_smsg($smsg) or next;
36 my $h = PublicInbox::Eml->new($mref)->header_obj;
38 PublicInbox::Mbox::msg_hdr($ctx, $h, $smsg->{mid})
40 return $self->translate(PublicInbox::Mbox::msg_body($$mref));
42 # signal that we're done and can return undef next call: