$title$title
+The administrator needs to install the IO::Compress::Gzip 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/;
- $buf = $simple->body;
- $simple->body_set('');
- $buf =~ s/^(From )/>$1/gm;
- $buf .= "\n" unless $buf =~ /\n\z/s;
+sub new {
+ my ($class, $ctx, $cb) = @_;
+ my $buf = '';
+ bless {
+ buf => \$buf,
+ gz => IO::Compress::Gzip->new(\$buf, Time => 0),
+ cb => $cb,
+ ctx => $ctx,
+ }, $class;
+}
- $fh->write($buf);
+sub response {
+ my ($class, $ctx, $cb, $fn) = @_;
+ my $body = $class->new($ctx, $cb);
+ # http://www.iana.org/assignments/media-types/application/gzip
+ my @h = qw(Content-Type application/gzip);
+ if ($fn) {
+ $fn = to_filename($fn);
+ push @h, 'Content-Disposition', "inline; filename=$fn.mbox.gz";
+ }
+ [ 200, \@h, $body ];
}
-sub emit_mbox {
- my ($fh, $ctx, $srch) = @_;
-
- require PublicInbox::GitCatFile;
- require Email::Simple;
- my $mid = mid_compressed($ctx->{mid});
- my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
- my %opts = (offset => 0);
- my $nr;
- do {
- my $res = $srch->get_thread($mid, \%opts);
- my $msgs = $res->{msgs};
- $nr = scalar @$msgs;
- while (defined(my $smsg = shift @$msgs)) {
- my $msg = eval {
- my $p = 'HEAD:'.mid2path($smsg->mid);
- Email::Simple->new($git->cat_file($p));
- };
- emit_msg($fh, $msg) if $msg;
+# called by Plack::Util::foreach or similar
+sub getline {
+ my ($self) = @_;
+ my $ctx = $self->{ctx} or return;
+ while (my $smsg = $self->{cb}->()) {
+ my $msg = $ctx->{-inbox}->msg_by_smsg($smsg) or next;
+ $msg = Email::Simple->new($msg);
+ $self->{gz}->write(PublicInbox::Mbox::msg_str($ctx, $msg,
+ $smsg->{mid}));
+ my $bref = $self->{buf};
+ if (length($$bref) >= 8192) {
+ my $ret = $$bref; # copy :<
+ ${$self->{buf}} = '';
+ return $ret;
}
- $opts{offset} += $nr;
- } while ($nr > 0);
+ # be fair to other clients on public-inbox-httpd:
+ return '';
+ }
+ delete($self->{gz})->close;
+ # signal that we're done and can return undef next call:
+ delete $self->{ctx};
+ ${delete $self->{buf}};
}
+sub close {} # noop
+
1;