-sub mbox_all {
- my ($ctx, $query) = @_;
-
- eval { require IO::Compress::Gzip };
- return sub { need_gzip(@_) } if $@;
- return mbox_all_ids($ctx) if $query eq '';
- my $opts = { mset => 2 };
- my $srch = $ctx->{-inbox}->search or
- return PublicInbox::WWW::need($ctx, 'Search');;
- my $mset = $srch->query($query, $opts);
- $opts->{offset} = $mset->size or
- return [404, [qw(Content-Type text/plain)],
- ["No results found\n"]];
- my $i = 0;
- my $cb = sub { # called by MboxGz->getline
- while (1) {
- while (my $mi = (($mset->items)[$i++])) {
- my $doc = $mi->get_document;
- my $smsg = $srch->retry_reopen(sub {
- PublicInbox::SearchMsg->load_doc($doc);
- }) or next;
- return $smsg;
- }
- # refill result set
- $mset = $srch->query($query, $opts);
- my $size = $mset->size or return;
- $opts->{offset} += $size;
- $i = 0;
- }
- };
- PublicInbox::MboxGz->response($ctx, $cb, 'results-'.$query);