$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;
-
-# fh may not be a proper IO, so we wrap the write and close methods
-# to prevent IO::Compress::Gzip from complaining
-package PublicInbox::MboxGz;
-use strict;
-use warnings;
-
-sub new {
- my ($class, $fh) = @_;
- my $buf;
- bless {
- buf => \$buf,
- gz => IO::Compress::Gzip->new(\$buf),
- fh => $fh,
- }, $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');
}
-sub _flush_buf {
- my ($self) = @_;
- if (defined ${$self->{buf}}) {
- $self->{fh}->write(${$self->{buf}});
- ${$self->{buf}} = undef;
+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;
+ }
+ # 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 write {
- $_[0]->{gz}->write($_[1]);
- _flush_buf($_[0]);
+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 close {
- my ($self) = @_;
- $self->{gz}->close;
- _flush_buf($self);
- $self->{fh}->close;
+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;