1 # Copyright (C) 2014-2015 all contributors <meta@public-inbox.org>
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
4 # Used for displaying the HTML web interface.
5 # See Documentation/design_www.txt for this.
6 package PublicInbox::View;
9 use URI::Escape qw/uri_escape_utf8/;
10 use Date::Parse qw/str2time/;
11 use Encode::MIME::Header;
13 use PublicInbox::Hval qw/ascii_html/;
14 use PublicInbox::Linkify;
15 use PublicInbox::MID qw/mid_clean id_compress mid_mime/;
16 use PublicInbox::MsgIter;
17 use PublicInbox::Address;
18 use PublicInbox::WwwStream;
21 use constant INDENT => ' ';
22 use constant TCHILD => '` ';
23 sub th_pfx ($) { $_[0] == 0 ? '' : TCHILD };
25 # public functions: (unstable)
27 my ($ctx, $mime, $footer) = @_;
28 my $hdr = $mime->header_obj;
29 my $tip = _msg_html_prepare($hdr, $ctx);
30 PublicInbox::WwwStream->new($ctx, sub {
33 $tip . multipart_text_as_html($mime, '') .
36 # fake an EOF if generating the footer fails;
37 # we want to at least show the message if something
40 '<pre>' . html_footer($hdr, 1, $ctx) .
41 '</pre>' . msg_reply($ctx, $hdr)
49 # /$INBOX/$MESSAGE_ID/#R
52 my $se_url = 'https://git-htmldocs.bogomips.org/git-send-email.html';
54 my ($arg, $link) = mailto_arg_link($hdr);
55 push @$arg, '/path/to/YOUR_REPLY';
58 "You may reply publically to <a\nhref=#t>this message</a> via\n".
59 "plain-text email using any one of the following methods:\n\n" .
60 "* Save the following mbox file, import it into your mail client,\n" .
61 " and reply-to-all from there: <a\nhref=raw>mbox</a>\n\n" .
62 "* Reply to all the recipients using the <b>--to</b>, <b>--cc</b>,\n" .
63 " and <b>--in-reply-to</b> switches of git-send-email(1):\n\n" .
64 " git send-email \\\n " .
65 join(" \\\n ", @$arg ). "\n\n" .
66 qq( <a\nhref="$se_url">$se_url</a>\n\n) .
67 "* If your mail client supports setting the <b>In-Reply-To</b>" .
68 " header\n via mailto: links, try the " .
69 qq(<a\nhref="$link">mailto: link</a>\n) .
75 my $irt = $hdr->header_raw('In-Reply-To');
77 return mid_clean($irt) if (defined $irt);
79 my $refs = $hdr->header_raw('References');
80 if ($refs && $refs =~ /<([^>]+)>\s*\z/s) {
87 my ($hdr, $field) = @_;
88 my $val = $hdr->header($field) or return '';
89 ascii_html(join(', ', PublicInbox::Address::names($val)));
93 my ($nr, $singular, $plural) = @_;
94 return "0 $plural" if $nr == 0;
95 $nr == 1 ? "$nr $singular" : "$nr $plural";
98 # this is already inside a <pre>
100 my ($mime, $ctx, $more) = @_;
101 my $srch = $ctx->{srch};
102 my $hdr = $mime->header_obj;
103 my $subj = $hdr->header('Subject');
105 my $mid_raw = mid_clean(mid_mime($mime));
106 my $id = id_compress($mid_raw);
108 my $mid = PublicInbox::Hval->new_msgid($mid_raw);
110 my $root_anchor = $ctx->{root_anchor} || '';
111 my $irt = in_reply_to($hdr);
113 my $rv = '<b>'.ascii_html($subj).'</b>';
114 $rv = "<u\nid=u>$rv</u>" if $root_anchor eq $id_m;
116 $rv .= _th_index_lite($mid_raw, $irt, $id, $ctx);
118 foreach my $f (qw(To Cc)) {
119 my $dst = _hdr_names($hdr, $f);
120 push @tocc, "$f: $dst" if $dst ne '';
122 $rv .= "From: "._hdr_names($hdr, 'From').' @ '._msg_date($hdr)." UTC\n";
123 $rv .= ' '.join('; +', @tocc) . "\n" if @tocc;
126 # scan through all parts, looking for displayable text
127 my $href = $mid->as_href;
128 my $mhref = $ctx->{-upfx}.$href.'/';
129 msg_iter($mime, sub { $rv .= add_text_body($mhref, $_[0]) });
132 $rv .= "\n<a\nhref=#$id_m\nid=e$id>^</a> ".
133 "<a\nhref=\"$mhref\">permalink</a>" .
134 " / <a\nhref=\"${mhref}raw\">raw</a>" .
135 " / <a\nhref=\"${mhref}#R\">reply</a>";
136 if (my $pct = $ctx->{pct}) { # used by SearchView.pm
137 $rv .= " [relevance $pct->{$mid_raw}%]";
139 $rv .= $more ? "\n\n" : "\n";
143 my ($mid_raw, $irt, $id, $ctx) = @_;
145 my $mapping = $ctx->{mapping} or return $rv;
147 # map = [children, attr, node, idx, level]
148 my $map = $mapping->{$mid_raw};
149 my $nr_c = scalar @{$map->[0]};
152 my $irt_map = $mapping->{$irt};
153 my $siblings = $irt_map->[0];
154 $nr_s = scalar(@$siblings) - 1;
155 $nr_s = 0 if $nr_s < 0;
156 $rv .= $pad . $irt_map->[1];
159 my $prev = $siblings->[$idx - 1];
160 $rv .= $pad . $mapping->{$prev->messageid}->[1];
163 my $s_s = nr_to_s($nr_s, 'sibling', 'siblings');
164 my $s_c = nr_to_s($nr_c, 'reply', 'replies');
165 my $this = $map->[1];
166 $this =~ s!\n\z!</b>\n!s;
167 $this =~ s!<a\nhref.*a> !!s; # no point in duplicating subject
169 my $node = $map->[2];
170 if (my $child = $node->child) {
171 $rv .= $pad . $mapping->{$child->messageid}->[1];
173 if (my $next = $node->next) {
174 $rv .= $pad . $mapping->{$next->messageid}->[1];
176 $rv .= "<a\nhref=#e$id\nid=m$id>.<a>\t\t\t";
177 $rv .= "(<a\nhref=#r$id\n>$s_s, $s_c</a> / ";
178 my $upfx = $ctx->{-upfx};
179 $rv .= qq{<a\nhref="$upfx$mid_raw/">permalink</a> / };
180 $rv .= qq{<a\nhref="$upfx$mid_raw/raw">raw</a>)\n};
184 my ($th, $ctx, $cb) = @_;
185 my @q = map { (0, $_) } $th->rootset;
187 my $level = shift @q;
188 my $node = shift @q or next;
189 $cb->($ctx, $level, $node);
190 unshift @q, $level+1, $node->child, $level, $node->next;
195 my ($ctx, $level, $node) = @_;
196 my $mapping = $ctx->{mapping};
198 if (my $parent = $node->parent) {
199 my $m = $mapping->{$parent->messageid}->[0];
203 $mapping->{$node->messageid} = [ [], '', $node, $idx ];
204 skel_dump($ctx, $level, $node);
209 my $mid = $ctx->{mid};
210 my $sres = $ctx->{srch}->get_thread($mid, { asc => 1 });
211 my $msgs = load_results($sres);
212 my $nr = $sres->{total};
213 return missing_thread($ctx) if $nr == 0;
214 my $skel = '</pre><hr /><pre>';
215 $skel .= $nr == 1 ? 'only message in thread' : 'end of thread';
216 $skel .= ", back to <a\nhref=\"../../\">index</a>";
217 $skel .= "\n<a\nid=t>$nr+ messages in thread:</a> (download: ";
218 $skel .= "<a\nhref=\"../t.mbox.gz\">mbox.gz</a>";
219 $skel .= " / follow: <a\nhref=\"../t.atom\">Atom feed</a>)\n";
220 $ctx->{cur_level} = 0;
221 $ctx->{dst} = \$skel;
222 $ctx->{mapping} = {}; # mid -> [ reply count, from@date, node ];
223 $ctx->{prev_attr} = '';
224 $ctx->{prev_level} = 0;
225 $ctx->{root_anchor} = anchor_for($mid);
228 walk_thread(thread_results($msgs), $ctx, *pre_thread);
230 # lazy load the full message from mini_mime:
231 my $inbox = $ctx->{-inbox};
233 while ($mime = shift @$msgs) {
234 $mime = $inbox->msg_by_mid(mid_clean(mid_mime($mime))) and last;
236 $mime = Email::MIME->new($mime);
237 $ctx->{-upfx} = '../../';
238 $ctx->{-title_html} = ascii_html($mime->header('Subject'));
239 $ctx->{-html_tip} = '<pre>'.index_entry($mime, $ctx, scalar @$msgs);
241 my $body = PublicInbox::WwwStream->new($ctx, sub {
243 while ($mime = shift @$msgs) {
244 $mid = mid_clean(mid_mime($mime));
245 $mime = $inbox->msg_by_mid($mid) and last;
248 $mime = Email::MIME->new($mime);
249 return index_entry($mime, $ctx, scalar @$msgs);
254 [ 200, ['Content-Type', 'text/html; charset=UTF-8'], $body ];
257 sub multipart_text_as_html {
258 my ($mime, $upfx) = @_;
261 # scan through all parts, looking for displayable text
262 msg_iter($mime, sub {
264 $rv .= add_text_body($upfx, $p);
270 my ($s, $l, $quot) = @_;
272 # show everything in the full version with anchor from
273 # short version (see above)
274 my $rv = $l->linkify_1(join('', @$quot));
277 # we use a <span> here to allow users to specify their own
278 # color for quoted text
279 $rv = $l->linkify_2(ascii_html($rv));
280 $$s .= qq(<span\nclass="q">) . $rv . '</span>'
283 sub attach_link ($$$$) {
284 my ($upfx, $ct, $p, $fn) = @_;
285 my ($part, $depth, @idx) = @$p;
286 my $nl = $idx[-1] > 1 ? "\n" : '';
287 my $idx = join('.', @idx);
288 my $size = bytes::length($part->body);
289 $ct ||= 'text/plain';
290 $ct =~ s/;.*//; # no attributes
291 $ct = ascii_html($ct);
292 my $desc = $part->header('Content-Description');
293 $desc = $fn unless defined $desc;
294 $desc = '' unless defined $desc;
296 if (defined $fn && $fn =~ /\A[[:alnum:]][\w\.-]+[[:alnum:]]\z/) {
298 } elsif ($ct eq 'text/plain') {
303 my @ret = qq($nl<a\nhref="$upfx$idx-$sfn">[-- Attachment #$idx: );
304 my $ts = "Type: $ct, Size: $size bytes";
305 push(@ret, ($desc eq '') ? "$ts --]" : "$desc --]\n[-- $ts --]");
306 join('', @ret, "</a>\n");
310 my ($upfx, $p) = @_; # from msg_iter: [ Email::MIME, depth, @idx ]
311 my ($part, $depth, @idx) = @$p;
312 my $ct = $part->content_type;
313 my $fn = $part->filename;
315 if (defined $ct && $ct =~ m!\btext/x?html\b!i) {
316 return attach_link($upfx, $ct, $p, $fn);
319 my $s = eval { $part->body_str };
321 # badly-encoded message? tell the world about it!
322 return attach_link($upfx, $ct, $p, $fn) if $@;
324 my @lines = split(/^/m, $s);
326 if (defined($fn) || $depth > 0) {
327 $s .= attach_link($upfx, $ct, $p, $fn);
331 my $l = PublicInbox::Linkify->new;
332 while (defined(my $cur = shift @lines)) {
334 # show the previously buffered quote inline
335 flush_quote(\$s, $l, \@quot) if @quot;
338 $cur = $l->linkify_1($cur);
339 $cur = ascii_html($cur);
340 $s .= $l->linkify_2($cur);
349 flush_quote(\$s, $l, \@quot);
351 $s =~ s/[ \t]+$//sgm; # kill per-line trailing whitespace
352 $s =~ s/\A\n+//s; # kill leading blank lines
353 $s =~ s/\s+\z//s; # kill all trailing spaces
357 sub _msg_html_prepare {
358 my ($hdr, $ctx) = @_;
359 my $srch = $ctx->{srch} if $ctx;
361 my $rv = "<pre\nid=b>"; # anchor for body start
364 $ctx->{-upfx} = '../';
367 my $mid = $hdr->header_raw('Message-ID');
368 $mid = PublicInbox::Hval->new_msgid($mid);
369 foreach my $h (qw(From To Cc Subject Date)) {
370 my $v = $hdr->header($h);
371 defined($v) && ($v ne '') or next;
372 $v = PublicInbox::Hval->new($v);
375 my @n = PublicInbox::Address::names($v->raw);
376 $title[1] = ascii_html(join(', ', @n));
377 } elsif ($h eq 'Subject') {
378 $title[0] = $v->as_html;
380 $rv .= qq($h: <a\nhref="#r"\nid=t>);
381 $rv .= $v->as_html . "</a>\n";
386 $v =~ s/(\@[^,]+,) /$1\n\t/g if ($h eq 'Cc' || $h eq 'To');
390 $title[0] ||= '(no subject)';
391 $ctx->{-title_html} = join(' - ', @title);
392 $rv .= 'Message-ID: <' . $mid->as_html . '> ';
393 $rv .= "(<a\nhref=\"raw\">raw</a>)\n";
394 $rv .= _parent_headers($hdr, $srch);
399 my ($dst, $ctx, $hdr, $tpfx) = @_;
400 my $srch = $ctx->{srch};
401 my $mid = mid_clean($hdr->header_raw('Message-ID'));
402 my $sres = $srch->get_thread($mid);
403 my $nr = $sres->{total};
404 my $expand = qq(<a\nhref="${tpfx}t/#u">expand</a> ) .
405 qq(/ <a\nhref="${tpfx}t.mbox.gz">mbox.gz</a> ) .
406 qq(/ <a\nhref="${tpfx}t.atom">Atom feed</a>);
408 my $parent = in_reply_to($hdr);
410 if (defined $parent) {
411 $$dst .= "($expand)\n ";
412 $$dst .= ghost_parent("$tpfx../", $parent) . "\n";
414 $$dst .= "[no followups, yet] ($expand)\n";
416 $ctx->{next_msg} = undef;
417 $ctx->{parent_msg} = $parent;
421 $$dst .= "$nr+ messages in thread ($expand";
422 $$dst .= qq! / <a\nhref="#b">[top]</a>)\n!;
424 my $subj = $srch->subject_path($hdr->header('Subject'));
425 $ctx->{seen} = { $subj => 1 };
427 $ctx->{prev_attr} = '';
428 $ctx->{prev_level} = 0;
430 walk_thread(thread_results(load_results($sres)), $ctx, *skel_dump);
431 $ctx->{parent_msg} = $parent;
434 sub _parent_headers {
435 my ($hdr, $srch) = @_;
438 my $irt = in_reply_to($hdr);
440 my $v = PublicInbox::Hval->new_msgid($irt, 1);
441 my $html = $v->as_html;
442 my $href = $v->as_href;
443 $rv .= "In-Reply-To: <";
444 $rv .= "<a\nhref=\"../$href/\">$html</a>>\n";
447 # do not display References: if search is present,
448 # we show the thread skeleton at the bottom, instead.
451 my $refs = $hdr->header_raw('References');
453 # avoid redundant URLs wasting bandwidth
455 $seen{$irt} = 1 if defined $irt;
457 my @raw_refs = ($refs =~ /<([^>]+)>/g);
458 foreach my $ref (@raw_refs) {
461 push @refs, linkify_ref_nosrch($ref);
465 $rv .= 'References: '. join("\n\t", @refs) . "\n";
471 sub squote_maybe ($) {
473 if ($val =~ m{([^\w@\./,\%\+\-])}) {
474 $val =~ s/(['!])/'\\$1'/g; # '!' for csh
480 sub mailto_arg_link {
482 my %cc; # everyone else
483 my $to; # this is the From address
485 foreach my $h (qw(From To Cc)) {
486 my $v = $hdr->header($h);
487 defined($v) && ($v ne '') or next;
488 my @addrs = PublicInbox::Address::emails($v);
489 foreach my $address (@addrs) {
490 my $dst = lc($address);
491 $cc{$dst} ||= $address;
497 my $subj = $hdr->header('Subject') || '';
498 $subj = "Re: $subj" unless $subj =~ /\bRe:/i;
499 my $mid = $hdr->header_raw('Message-ID');
500 push @arg, '--in-reply-to='.ascii_html(squote_maybe(mid_clean($mid)));
501 my $irt = uri_escape_utf8($mid);
503 push @arg, '--to=' . ascii_html($to);
504 $to = uri_escape_utf8($to);
505 $subj = uri_escape_utf8($subj);
506 my $cc = join(',', sort values %cc);
507 push @arg, '--cc=' . ascii_html($cc);
508 $cc = uri_escape_utf8($cc);
509 my $href = "mailto:$to?In-Reply-To=$irt&Cc=${cc}&Subject=$subj";
512 (\@arg, ascii_html($href));
516 my ($hdr, $standalone, $ctx, $rhref) = @_;
518 my $srch = $ctx->{srch} if $ctx;
521 my $idx = $standalone ? " <a\nhref=\"$upfx\">index</a>" : '';
525 thread_skel(\$idx, $ctx, $hdr, $tpfx);
526 my $p = $ctx->{parent_msg};
527 my $next = $ctx->{next_msg};
529 $p = PublicInbox::Hval->new_msgid($p);
531 $irt = "<a\nhref=\"$upfx$p/\"\nrel=prev>parent</a> ";
533 $irt = ' ' x length('parent ');
536 my $n = PublicInbox::Hval->new_msgid($next)->as_href;
537 $irt .= "<a\nhref=\"$upfx$n/\"\nrel=next>next</a> ";
539 $irt .= ' ' x length('next ');
545 $irt .= qq(<a\nhref="$rhref">reply</a>);
549 sub linkify_ref_nosrch {
550 my $v = PublicInbox::Hval->new_msgid($_[0], 1);
551 my $html = $v->as_html;
552 my $href = $v->as_href;
553 "<<a\nhref=\"../$href/\">$html</a>>";
558 'm' . id_compress($msgid, 1);
562 my ($upfx, $mid) = @_;
563 # 'subject dummy' is used internally by Mail::Thread
564 return '[no common parent]' if ($mid eq 'subject dummy');
566 $mid = PublicInbox::Hval->new_msgid($mid);
567 my $href = $mid->as_href;
568 my $html = $mid->as_html;
569 qq{[parent not found: <<a\nhref="$upfx$href/">$html</a>>]};
574 INDENT x ($level - 1);
580 [ map { $_->mini_mime } @{delete $sres->{msgs}} ];
585 my $ts = eval { str2time($hdr->header('Date')) };
586 defined($ts) ? $ts : 0;
591 require PublicInbox::Thread;
592 my $th = PublicInbox::Thread->new(@$msgs);
594 $th->order(*sort_ts);
600 require PublicInbox::ExtMsg;
601 PublicInbox::ExtMsg::ext_msg($ctx);
606 my $ts = $hdr->header('X-PI-TS') || msg_timestamp($hdr);
610 sub fmt_ts { POSIX::strftime('%Y-%m-%d %k:%M', gmtime($_[0])) }
613 my ($ctx, $hdr, $level) = @_;
615 my $dst = $ctx->{dst};
616 my $cur = $ctx->{cur};
617 my $mid = mid_clean($hdr->header_raw('Message-ID'));
618 my $f = ascii_html($hdr->header('X-PI-From'));
619 my $d = _msg_date($hdr) . ' ' . indent_for($level) . th_pfx($level);
621 $ctx->{first_level} ||= $level;
623 if ($attr ne $ctx->{prev_attr} || $ctx->{prev_level} > $level) {
624 $ctx->{prev_attr} = $attr;
628 $ctx->{prev_level} = $level;
634 $$dst .= "<b><a\nid=r\nhref=\"#t\">".
635 "$attr [this message]</a></b>\n";
639 $ctx->{next_msg} ||= $mid;
642 # Subject is never undef, this mail was loaded from
643 # our Xapian which would've resulted in '' if it were
644 # really missing (and Filter rejects empty subjects)
645 my $s = $hdr->header('Subject');
646 my $h = $ctx->{srch}->subject_path($s);
647 if ($ctx->{seen}->{$h}) {
650 $ctx->{seen}->{$h} = 1;
651 $s = PublicInbox::Hval->new($s);
654 my $m = PublicInbox::Hval->new_msgid($mid);
656 my $mapping = $ctx->{mapping};
657 my $end = defined($s) ? "$s</a> $f\n" : "$f</a>\n";
659 my $map = $mapping->{$mid};
660 $id = id_compress($mid, 1);
662 $map->[1] = "$d<a\nhref=\"$m\">$end";
665 $m = $ctx->{-upfx}.$m->as_href.'/';
667 $$dst .= $d . "<a\nhref=\"$m\"$id>" . $end;
671 my ($ctx, $level, $node) = @_;
672 if (my $mime = $node->message) {
673 _skel_header($ctx, $mime->header_obj, $level);
675 my $mid = $node->messageid;
676 my $dst = $ctx->{dst};
677 my $mapping = $ctx->{mapping};
678 my $map = $mapping->{$mid} if $mapping;
679 if ($mid eq 'subject dummy') {
680 my $ncp = "\t[no common parent]\n";
681 $map->[1] = $ncp if $map;
685 my $d = $ctx->{pct} ? ' [irrelevant] ' # search result
687 $d .= indent_for($level) . th_pfx($level);
688 my $upfx = $ctx->{-upfx};
689 my $m = PublicInbox::Hval->new_msgid($mid);
690 my $href = $upfx . $m->as_href . '/';
691 my $html = $m->as_html;
694 my $id = id_compress($mid, 1);
695 $map->[1] = $d . qq{<<a\nhref=#r$id>$html</a>>\n};
696 $d .= qq{<<a\nhref="$href"\nid=r$id>$html</a>>\n};
698 $d .= qq{<<a\nhref="$href">$html</a>>\n};
706 (eval { $a->topmost->message->header('X-PI-TS') } || 0) <=>
707 (eval { $b->topmost->message->header('X-PI-TS') } || 0)
711 sub _tryload_ghost ($$) {
712 my ($srch, $mid) = @_;
713 my $smsg = $srch->lookup_mail($mid) or return;
717 # accumulate recent topics if search is supported
718 # returns 1 if done, undef if not
720 my ($ctx, $level, $node) = @_;
721 my $srch = $ctx->{srch};
722 my $mid = $node->messageid;
723 my $x = $node->message || _tryload_ghost($srch, $mid);
727 $subj = $x->header('Subject');
728 $subj = $srch->subject_normalized($subj);
729 $ts = $x->header('X-PI-TS');
730 } else { # ghost message, do not bump level
734 if (++$ctx->{subjs}->{$subj} == 1) {
735 push @{$ctx->{order}}, [ $level, $subj ];
737 my $exist = $ctx->{latest}->{$subj};
738 if (!$exist || $exist->[1] < $ts) {
739 $ctx->{latest}->{$subj} = [ $mid, $ts ];
745 my $order = $ctx->{order};
746 my $subjs = $ctx->{subjs};
747 my $latest = $ctx->{latest};
749 return $fh->write("\n[No topics in range]</pre>") unless scalar @$order;
755 while (defined(my $info = shift @$order)) {
756 my ($level, $subj) = @$info;
757 my $n = delete $subjs->{$subj};
758 my ($mid, $ts) = @{delete $latest->{$subj}};
759 $mid = PublicInbox::Hval->new_msgid($mid)->as_href;
760 $pfx = indent_for($level);
761 my $nl = $level == $prev ? "\n" : '';
766 $cur ||= [ $ts, '' ];
767 $cur->[0] = $ts if $ts > $cur->[0];
768 $cur->[1] .= $nl . $pfx . th_pfx($level);
769 if ($ts == -666) { # ghost
770 $cur->[1] .= ghost_parent('', $mid) . "\n";
771 next; # child will have mbox / atom link
774 $subj = PublicInbox::Hval->new($subj)->as_html;
775 $cur->[1] .= "<a\nhref=\"$mid/t/#u\"><b>$subj</b></a>\n";
777 my $attr = " $ts UTC";
779 # $n isn't the total number of posts on the topic,
780 # just the number of posts in the current results window
781 $n = $n == 1 ? '' : " ($n+ messages)";
783 if ($level == 0 || $attr ne $prev_attr) {
784 my $mbox = qq(<a\nhref="$mid/t.mbox.gz">mbox.gz</a>);
785 my $atom = qq(<a\nhref="$mid/t.atom">Atom</a>);
786 $pfx .= INDENT if $level > 0;
787 $cur->[1] .= $pfx . $attr . $n . " - $mbox / $atom\n";
791 push @recent, $cur if $cur;
792 @recent = map { $_->[1] } sort { $b->[0] <=> $a->[0] } @recent;
793 $fh->write(join('', @recent) . '</pre>');
796 sub emit_index_topics {
798 my ($off) = (($ctx->{cgi}->param('o') || '0') =~ /(\d+)/);
803 my %opts = ( offset => $off, limit => $max * 4 );
804 while (scalar @{$ctx->{order}} < $max) {
805 my $sres = $ctx->{srch}->query('', \%opts);
806 my $nr = scalar @{$sres->{msgs}} or last;
807 $sres = load_results($sres);
808 walk_thread(thread_results($sres), $ctx, *add_topic);
809 $opts{offset} += $nr;