]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Mbox.pm
nntp: get_range: return scalarref for $beg
[public-inbox.git] / lib / PublicInbox / Mbox.pm
index 9e808c09502064e57642cf2f1c7e7e401d387a4e..c50a118b2b6367200767ea929ba97596bd1713c5 100644 (file)
@@ -18,7 +18,7 @@ use Email::MIME::Encode;
 sub subject_fn ($) {
        my ($hdr) = @_;
        my $fn = $hdr->header('Subject');
-       return 'no-subject' unless defined($fn);
+       return 'no-subject' if (!defined($fn) || $fn eq '');
 
        # no need for full Email::MIME, here
        if ($fn =~ /=\?/) {
@@ -136,7 +136,7 @@ sub msg_body ($) {
 
 sub thread_mbox {
        my ($ctx, $over, $sfx) = @_;
-       eval { require IO::Compress::Gzip };
+       eval { require PublicInbox::MboxGz };
        return sub { need_gzip(@_) } if $@;
        my $mid = $ctx->{mid};
        my $msgs = $over->get_thread($mid, {});
@@ -196,7 +196,7 @@ sub mbox_all_ids {
 sub mbox_all {
        my ($ctx, $query) = @_;
 
-       eval { require IO::Compress::Gzip };
+       eval { require PublicInbox::MboxGz };
        return sub { need_gzip(@_) } if $@;
        return mbox_all_ids($ctx) if $query eq '';
        my $opts = { mset => 2 };
@@ -231,7 +231,7 @@ sub need_gzip {
        my $title = 'gzipped mbox not available';
        $fh->write(<<EOF);
 <html><head><title>$title</title><body><pre>$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.
 <a href="../">Return to index</a></pre></body></html>
 EOF
@@ -239,63 +239,3 @@ EOF
 }
 
 1;
-
-package PublicInbox::MboxGz;
-use strict;
-use warnings;
-use PublicInbox::Hval qw/to_filename/;
-
-sub new {
-       my ($class, $ctx, $cb) = @_;
-       my $buf = '';
-       $ctx->{base_url} = $ctx->{-inbox}->base_url($ctx->{env});
-       bless {
-               buf => \$buf,
-               gz => IO::Compress::Gzip->new(\$buf, Time => 0),
-               cb => $cb,
-               ctx => $ctx,
-       }, $class;
-}
-
-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 ];
-}
-
-# called by Plack::Util::foreach or similar
-sub getline {
-       my ($self) = @_;
-       my $ctx = $self->{ctx} or return;
-       my $gz = $self->{gz};
-       while (my $smsg = $self->{cb}->()) {
-               my $mref = $ctx->{-inbox}->msg_by_smsg($smsg) or next;
-               my $h = Email::Simple->new($mref)->header_obj;
-               $gz->write(PublicInbox::Mbox::msg_hdr($ctx, $h, $smsg->{mid}));
-               $gz->write(PublicInbox::Mbox::msg_body($$mref));
-
-               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 '';
-       }
-       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;