+sub mbox_all_ids {
+ my ($ctx) = @_;
+ my $prev = 0;
+ my $ibx = $ctx->{-inbox};
+ my $ids = $ibx->mm->ids_after(\$prev) or return
+ [404, [qw(Content-Type text/plain)], ["No results found\n"]];
+ my $i = 0;
+ my $over = $ibx->over or
+ return PublicInbox::WWW::need($ctx, 'Overview');
+ my $cb = sub {
+ do {
+ while ((my $num = $ids->[$i++])) {
+ my $smsg = $over->get_art($num) or next;
+ return $smsg;
+ }
+ $ids = $ibx->mm->ids_after(\$prev);
+ $i = 0;
+ } while (@$ids);
+ undef;
+ };
+ return PublicInbox::MboxGz->response($ctx, $cb, 'all');
+}
+
+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);