$title$title
-The administrator needs to install the IO::Compress::Gzip Perl module
-to support gzipped mboxes.
-Return to index
-EOF
- $fh->close;
+sub thread_mbox {
+ my ($ctx, $over, $sfx) = @_;
+ my $msgs = $ctx->{msgs} = $over->get_thread($ctx->{mid}, {});
+ return [404, [qw(Content-Type text/plain)], []] if !@$msgs;
+ $ctx->{prev} = $msgs->[-1];
+ $ctx->{over} = $over; # bump refcnt
+ require PublicInbox::MboxGz;
+ PublicInbox::MboxGz::mbox_gz($ctx, \&thread_cb, $msgs->[0]->{subject});
}
-1;
+sub emit_range {
+ my ($ctx, $range) = @_;
-# 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;
-use fields qw(gz fh buf);
-
-sub new {
- my ($class, $fh) = @_;
- my $self = fields::new($class);
- my $buf;
- $self->{buf} = \$buf;
- $self->{gz} = IO::Compress::Gzip->new(\$buf);
- $self->{fh} = $fh;
- $self;
+ my $query;
+ if ($range eq 'all') { # TODO: YYYY[-MM]
+ $query = '';
+ } else {
+ return [404, [qw(Content-Type text/plain)], []];
+ }
+ mbox_all($ctx, $query);
}
-sub _flush_buf {
- my ($self) = @_;
- if (defined ${$self->{buf}}) {
- $self->{fh}->write(${$self->{buf}});
- ${$self->{buf}} = undef;
- }
+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);
}
-sub write {
- $_[0]->{gz}->write($_[1]);
- _flush_buf($_[0]);
+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;
+ require PublicInbox::MboxGz;
+ PublicInbox::MboxGz::mbox_gz($ctx, \&all_ids_cb, 'all');
+}
+
+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 close {
- my ($self) = @_;
- $self->{gz}->close;
- _flush_buf($self);
- $self->{fh}->close;
+sub mbox_all {
+ my ($ctx, $query) = @_;
+
+ 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;
+ require PublicInbox::MboxGz;
+ PublicInbox::MboxGz::mbox_gz($ctx, \&results_cb, 'results-'.$query);
}
1;