$title$title
-The administrator needs to install the IO::Compress::Gzip Perl module
-to support gzipped mboxes.
-Return to index
-EOF
- $fh->close;
+sub mbox_all_ids {
+ my ($ctx) = @_;
+ my $prev = 0;
+ $ctx->{over} = $ctx->{ibx}->over or
+ return PublicInbox::WWW::need($ctx, 'Overview');
+ my $ids = $ctx->{over}->ids_after(\$prev) or return
+ [404, [qw(Content-Type text/plain)], ["No results found\n"]];
+ $ctx->{ids} = $ids;
+ $ctx->{prev} = $prev;
+ require PublicInbox::MboxGz;
+ PublicInbox::MboxGz::mbox_gz($ctx, \&all_ids_cb, 'all');
}
-1;
-
-package PublicInbox::MboxGz;
-use strict;
-use warnings;
-use PublicInbox::Hval qw/to_filename/;
-
-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 => { offset => 0 },
- }, $class;
+sub gone ($$) {
+ my ($ctx, $what) = @_;
+ warn "W: `$ctx->{ibx}->{inboxdir}' $what went away unexpectedly\n";
+ undef;
}
-sub response {
- my ($class, $ctx, $cb, $fn) = @_;
- my $body = $class->new($ctx, $cb);
- # http://www.iana.org/assignments/media-types/application/gzip
- $body->{hdr} = [ 'Content-Type', 'application/gzip' ];
- $body->{fn} = $fn;
- my $hdr = $body->getline; # fill in Content-Disposition filename
- [ 200, $hdr, $body ];
+sub results_cb {
+ my ($ctx) = @_;
+ my $over = $ctx->{ibx}->over or return gone($ctx, 'over');
+ while (1) {
+ while (defined(my $num = shift(@{$ctx->{ids}}))) {
+ my $smsg = $over->get_art($num) or next;
+ return $smsg;
+ }
+ # refill result set
+ my $srch = $ctx->{ibx}->isrch or return gone($ctx, 'search');
+ my $mset = $srch->mset($ctx->{query}, $ctx->{qopts});
+ my $size = $mset->size or return;
+ $ctx->{qopts}->{offset} += $size;
+ $ctx->{ids} = $srch->mset_to_artnums($mset, $ctx->{qopts});
+ }
}
-sub set_filename ($$) {
- my ($fn, $msg) = @_;
- return to_filename($fn) if defined($fn);
-
- PublicInbox::Mbox::subject_fn($msg);
-}
+sub results_thread_cb {
+ my ($ctx) = @_;
-# 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 {
- # work on existing result set
- while (defined(my $smsg = shift @{$self->{msgs}})) {
- my $msg = eval { $ibx->msg_by_smsg($smsg) } or next;
- $msg = Email::Simple->new($msg);
- $gz->write(PublicInbox::Mbox::msg_str($ctx, $msg));
-
- # use subject of first message as subject
- if (my $hdr = delete $self->{hdr}) {
- my $fn = set_filename($self->{fn}, $msg);
- push @$hdr, 'Content-Disposition',
- "inline; filename=$fn.mbox.gz";
- return $hdr;
- }
- 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 '';
+ my $over = $ctx->{ibx}->over or return gone($ctx, 'over');
+ while (1) {
+ while (defined(my $num = shift(@{$ctx->{xids}}))) {
+ my $smsg = $over->get_art($num) or next;
+ return $smsg;
}
+ # refills ctx->{xids}
+ next if $over->expand_thread($ctx);
+
# refill result set
- $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}};
+ my $srch = $ctx->{ibx}->isrch or return gone($ctx, 'search');
+ my $mset = $srch->mset($ctx->{query}, $ctx->{qopts});
+ my $size = $mset->size or return;
+ $ctx->{qopts}->{offset} += $size;
+ $ctx->{ids} = $srch->mset_to_artnums($mset, $ctx->{qopts});
+ }
+
}
-sub close {} # noop
+sub mbox_all {
+ my ($ctx, $q) = @_;
+ my $q_string = $q->{'q'};
+ return mbox_all_ids($ctx) if $q_string !~ /\S/;
+ my $srch = $ctx->{ibx}->isrch or
+ return PublicInbox::WWW::need($ctx, 'Search');
+ my $over = $ctx->{ibx}->over or
+ return PublicInbox::WWW::need($ctx, 'Overview');
+
+ my $qopts = $ctx->{qopts} = { relevance => -2 }; # ORDER BY docid DESC
+ $qopts->{threads} = 1 if $q->{t};
+ $srch->query_approxidate($ctx->{ibx}->git, $q_string);
+ my $mset = $srch->mset($q_string, $qopts);
+ $qopts->{offset} = $mset->size or
+ return [404, [qw(Content-Type text/plain)],
+ ["No results found\n"]];
+ $ctx->{query} = $q_string;
+ $ctx->{ids} = $srch->mset_to_artnums($mset, $qopts);
+ require PublicInbox::MboxGz;
+ my $fn;
+ if ($q->{t} && $srch->has_threadid) {
+ $fn = 'results-thread-'.$q_string;
+ PublicInbox::MboxGz::mbox_gz($ctx, \&results_thread_cb, $fn);
+ } else {
+ $fn = 'results-'.$q_string;
+ PublicInbox::MboxGz::mbox_gz($ctx, \&results_cb, $fn);
+ }
+}
1;