$title$title
-The administrator needs to install the IO::Compress::Gzip Perl module
-to support gzipped mboxes.
-Return to index
-EOF
- $fh->close;
+sub all_ids_cb {
+ my ($ctx) = @_;
+ my $ids = $ctx->{ids};
+ do {
+ while ((my $num = shift @$ids)) {
+ my $smsg = $ctx->{over}->get_art($num) or next;
+ return $smsg;
+ }
+ $ctx->{ids} = $ids = $ctx->{mm}->ids_after(\($ctx->{prev}));
+ } while (@$ids);
}
-1;
-
-package PublicInbox::MboxGz;
-use strict;
-use warnings;
-
-sub new {
- my ($class, $ctx, $cb) = @_;
- my $buf = '';
- bless {
- buf => \$buf,
- gz => IO::Compress::Gzip->new(\$buf, Time => 0),
- cb => $cb,
- ctx => $ctx,
- msgs => [],
- opts => { asc => 1, offset => 0 },
- }, $class;
+sub mbox_all_ids {
+ my ($ctx) = @_;
+ my $ibx = $ctx->{-inbox};
+ my $prev = 0;
+ my $mm = $ctx->{mm} = $ibx->mm;
+ my $ids = $mm->ids_after(\$prev) or return
+ [404, [qw(Content-Type text/plain)], ["No results found\n"]];
+ $ctx->{over} = $ibx->over or
+ return PublicInbox::WWW::need($ctx, 'Overview');
+ $ctx->{ids} = $ids;
+ $ctx->{prev} = $prev;
+ return PublicInbox::MboxGz->response($ctx, \&all_ids_cb, 'all');
}
-# called by Plack::Util::foreach or similar
-sub getline {
- my ($self) = @_;
- my $ctx = $self->{ctx} or return;
- my $res;
- my $ibx = $ctx->{-inbox};
- my $gz = $self->{gz};
- do {
- while (defined(my $smsg = shift @{$self->{msgs}})) {
- my $msg = eval { $ibx->msg_by_mid($smsg->mid) } or next;
- $msg = Email::Simple->new($msg);
- $gz->write(PublicInbox::Mbox::msg_str($ctx, $msg));
- my $bref = $self->{buf};
- if (length($$bref) >= 8192) {
- my $ret = $$bref; # copy :<
- ${$self->{buf}} = '';
- return $ret;
- }
+sub results_cb {
+ my ($ctx) = @_;
+ my $mset = $ctx->{mset};
+ my $srch = $ctx->{srch};
+ while (1) {
+ while (my $mi = (($mset->items)[$ctx->{iter}++])) {
+ my $smsg = PublicInbox::Smsg::from_mitem($mi,
+ $srch) or next;
+ return $smsg;
}
- $res = $self->{cb}->($self->{opts});
- $self->{msgs} = $res->{msgs};
- $res = scalar @{$self->{msgs}};
- $self->{opts}->{offset} += $res;
- } while ($res);
- $gz->close;
- delete $self->{ctx};
- ${delete $self->{buf}};
+ # refill result set
+ $mset = $ctx->{mset} = $srch->query($ctx->{query},
+ $ctx->{qopts});
+ my $size = $mset->size or return;
+ $ctx->{qopts}->{offset} += $size;
+ $ctx->{iter} = 0;
+ }
}
-sub close {} # noop
+sub mbox_all {
+ my ($ctx, $query) = @_;
+
+ eval { require PublicInbox::MboxGz };
+ return need_gzip($ctx) if $@;
+ return mbox_all_ids($ctx) if $query eq '';
+ my $qopts = $ctx->{qopts} = { mset => 2 };
+ my $srch = $ctx->{srch} = $ctx->{-inbox}->search or
+ return PublicInbox::WWW::need($ctx, 'Search');;
+ my $mset = $ctx->{mset} = $srch->query($query, $qopts);
+ $qopts->{offset} = $mset->size or
+ return [404, [qw(Content-Type text/plain)],
+ ["No results found\n"]];
+ $ctx->{iter} = 0;
+ $ctx->{query} = $query;
+ PublicInbox::MboxGz->response($ctx, \&results_cb, 'results-'.$query);
+}
+
+sub need_gzip {
+ PublicInbox::WwwStream::oneshot($_[0], 501, \<gzipped mbox not available
+
+The administrator needs to install the Compress::Raw::Zlib Perl module
+to support gzipped mboxes.
+
+Return to index
+EOF
+}
1;