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 mid2path 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 '<pre>' . html_footer($hdr, 1, $ctx) .
37 '</pre>' . msg_reply($ctx, $hdr);
44 # /$INBOX/$MESSAGE_ID/#R
48 'https://kernel.org/pub/software/scm/git/docs/git-send-email.html';
50 my ($arg, $link) = mailto_arg_link($hdr);
51 push @$arg, '/path/to/YOUR_REPLY';
54 "You may reply publically to <a\nhref=#t>this message</a> via\n".
55 "plain-text email using any one of the following methods:\n\n" .
56 "* Save the following mbox file, import it into your mail client,\n" .
57 " and reply-to-all from there: <a\nhref=raw>mbox</a>\n\n" .
58 "* Reply to all the recipients using the <b>--to</b>, <b>--cc</b>,\n" .
59 " and <b>--in-reply-to</b> switches of git-send-email(1):\n\n" .
60 " git send-email \\\n " .
61 join(" \\\n ", @$arg ). "\n\n" .
62 qq( <a\nhref="$se_url">$se_url</a>\n\n) .
63 "* If your mail client supports setting the <b>In-Reply-To</b>" .
64 " header\n via mailto: links, try the " .
65 qq(<a\nhref="$link">mailto: link</a>\n) .
71 my $irt = $hdr->header_raw('In-Reply-To');
73 return mid_clean($irt) if (defined $irt);
75 my $refs = $hdr->header_raw('References');
76 if ($refs && $refs =~ /<([^>]+)>\s*\z/s) {
82 # this is already inside a <pre>
84 my ($mime, $level, $state) = @_;
85 my $midx = $state->{anchor_idx}++;
86 my $ctx = $state->{ctx};
87 my $srch = $ctx->{srch};
88 my $hdr = $mime->header_obj;
89 my $subj = $hdr->header('Subject');
91 my $mid_raw = mid_clean(mid_mime($mime));
92 my $id = anchor_for($mid_raw);
93 my $seen = $state->{seen};
94 $seen->{$id} = "#$id"; # save the anchor for children, later
96 my $mid = PublicInbox::Hval->new_msgid($mid_raw);
97 my $from = PublicInbox::Address::from_name($hdr->header('From'));
99 my $root_anchor = $state->{root_anchor} || '';
100 my $path = $root_anchor ? '../../' : '';
101 my $href = $mid->as_href;
102 my $irt = in_reply_to($hdr);
103 my $parent_anchor = $seen->{anchor_for($irt)} if defined $irt;
105 $from = ascii_html($from);
106 $subj = ascii_html($subj);
107 $subj = "<a\nhref=\"${path}$href/\">$subj</a>";
108 $subj = "<u\nid=u>$subj</u>" if $root_anchor eq $id;
110 my $ts = _msg_date($hdr);
111 my $rv = "<pre\nid=s$midx>";
112 $rv .= "<b\nid=$id>$subj</b>\n";
113 my $txt = "${path}$href/raw";
114 my $fh = $state->{fh};
115 $fh->write($rv .= "- $from @ $ts UTC (<a\nhref=\"$txt\">raw</a>)\n\n");
117 my $mhref = "${path}$href/";
119 # scan through all parts, looking for displayable text
120 msg_iter($mime, sub { index_walk($fh, $mhref, $_[0]) });
121 $rv = "\n" . html_footer($hdr, 0, $ctx, "$path$href/#R");
124 unless (defined $parent_anchor) {
125 my $v = PublicInbox::Hval->new_msgid($irt, 1);
127 $parent_anchor = "${path}$v/";
129 $rv .= " <a\nhref=\"$parent_anchor\">parent</a>";
131 if (my $pct = $state->{pct}) { # used by SearchView.pm
132 $rv .= " [relevance $pct->{$mid_raw}%]";
134 my $threaded = 'threaded';
138 $flat = "<b>$flat</b>";
139 $end = "\n"; # for lynx
141 $threaded = "<b>$threaded</b>";
143 $rv .= " [<a\nhref=\"${path}$href/t/#u\">$threaded</a>";
144 $rv .= "|<a\nhref=\"${path}$href/T/#u\">$flat</a>]$end";
146 $fh->write($rv .= '</pre>');
150 my ($ctx, $foot, $srch) = @_;
151 # $_[0] in sub is the Plack callback
152 sub { emit_thread_html($_[0], $ctx, $foot, $srch) }
155 # only private functions below.
157 sub emit_thread_html {
158 my ($res, $ctx, $foot, $srch) = @_;
159 my $mid = $ctx->{mid};
160 my $flat = $ctx->{flat};
161 my $msgs = load_results($srch->get_thread($mid, { asc => $flat }));
162 my $nr = scalar @$msgs;
163 return missing_thread($res, $ctx) if $nr == 0;
169 root_anchor => anchor_for($mid),
174 require PublicInbox::Git;
175 $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir});
177 pre_anchor_entry($seen, $_) for (@$msgs);
178 __thread_entry($state, $_, 0) for (@$msgs);
180 my $th = thread_results($msgs);
181 thread_entry($state, $_, 0) for $th->rootset;
182 if (my $max = $state->{cur_level}) {
184 ('</ul></li>' x ($max - 1)) . '</ul>');
188 # there could be a race due to a message being deleted in git
189 # but still being in the Xapian index:
190 my $fh = delete $state->{fh} or return missing_thread($res, $ctx);
192 my $final_anchor = $state->{anchor_idx};
193 my $next = "<a\nid=s$final_anchor>";
194 $next .= $final_anchor == 1 ? 'only message in' : 'end of';
195 $next .= " thread</a>, back to <a\nhref=\"../../\">index</a>";
196 $next .= "\ndownload thread: ";
197 $next .= "<a\nhref=\"../t.mbox.gz\">mbox.gz</a>";
198 $next .= " / follow: <a\nhref=\"../t.atom\">Atom feed</a>";
199 $fh->write('<hr /><pre>' . $next . "\n\n".
200 $foot . '</pre></body></html>');
205 my ($fh, $upfx, $p) = @_;
206 my $s = add_text_body($upfx, $p);
213 sub multipart_text_as_html {
214 my ($mime, $upfx) = @_;
217 # scan through all parts, looking for displayable text
218 msg_iter($mime, sub {
220 $rv .= add_text_body($upfx, $p);
226 my ($s, $l, $quot) = @_;
228 # show everything in the full version with anchor from
229 # short version (see above)
230 my $rv = $l->linkify_1(join('', @$quot));
233 # we use a <span> here to allow users to specify their own
234 # color for quoted text
235 $rv = $l->linkify_2(ascii_html($rv));
236 $$s .= qq(<span\nclass="q">) . $rv . '</span>'
239 sub attach_link ($$$$) {
240 my ($upfx, $ct, $p, $fn) = @_;
241 my ($part, $depth, @idx) = @$p;
242 my $nl = $idx[-1] > 1 ? "\n" : '';
243 my $idx = join('.', @idx);
244 my $size = bytes::length($part->body);
245 $ct ||= 'text/plain';
246 $ct =~ s/;.*//; # no attributes
247 $ct = ascii_html($ct);
248 my $desc = $part->header('Content-Description');
249 $desc = $fn unless defined $desc;
250 $desc = '' unless defined $desc;
252 if (defined $fn && $fn =~ /\A[[:alnum:]][\w\.-]+[[:alnum:]]\z/) {
254 } elsif ($ct eq 'text/plain') {
259 my @ret = qq($nl<a\nhref="$upfx$idx-$sfn">[-- Attachment #$idx: );
260 my $ts = "Type: $ct, Size: $size bytes";
261 push(@ret, ($desc eq '') ? "$ts --]" : "$desc --]\n[-- $ts --]");
262 join('', @ret, "</a>\n");
266 my ($upfx, $p) = @_; # from msg_iter: [ Email::MIME, depth, @idx ]
267 my ($part, $depth, @idx) = @$p;
268 my $ct = $part->content_type;
269 my $fn = $part->filename;
271 if (defined $ct && $ct =~ m!\btext/x?html\b!i) {
272 return attach_link($upfx, $ct, $p, $fn);
275 my $s = eval { $part->body_str };
277 # badly-encoded message? tell the world about it!
278 return attach_link($upfx, $ct, $p, $fn) if $@;
280 my @lines = split(/^/m, $s);
282 if (defined($fn) || $depth > 0) {
283 $s .= attach_link($upfx, $ct, $p, $fn);
287 my $l = PublicInbox::Linkify->new;
288 while (defined(my $cur = shift @lines)) {
290 # show the previously buffered quote inline
291 flush_quote(\$s, $l, \@quot) if @quot;
294 $cur = $l->linkify_1($cur);
295 $cur = ascii_html($cur);
296 $s .= $l->linkify_2($cur);
305 flush_quote(\$s, $l, \@quot);
307 $s =~ s/[ \t]+$//sgm; # kill per-line trailing whitespace
308 $s =~ s/\A\n+//s; # kill leading blank lines
309 $s =~ s/\s+\z//s; # kill all trailing spaces
313 sub _msg_html_prepare {
314 my ($hdr, $ctx) = @_;
315 my $srch = $ctx->{srch} if $ctx;
317 my $rv = "<pre\nid=b>"; # anchor for body start
320 $ctx->{-upfx} = '../';
323 my $mid = $hdr->header_raw('Message-ID');
324 $mid = PublicInbox::Hval->new_msgid($mid);
325 foreach my $h (qw(From To Cc Subject Date)) {
326 my $v = $hdr->header($h);
327 defined($v) && ($v ne '') or next;
328 $v = PublicInbox::Hval->new($v);
331 my $n = PublicInbox::Address::from_name($v->raw);
332 $title[1] = ascii_html($n);
333 } elsif ($h eq 'Subject') {
334 $title[0] = $v->as_html;
336 $rv .= qq($h: <a\nhref="#r"\nid=t>);
337 $rv .= $v->as_html . "</a>\n";
342 $v =~ s/(\@[^,]+,) /$1\n\t/g if ($h eq 'Cc' || $h eq 'To');
346 $ctx->{-title_html} = join(' - ', @title);
347 $rv .= 'Message-ID: <' . $mid->as_html . '> ';
348 $rv .= "(<a\nhref=\"raw\">raw</a>)\n";
349 $rv .= _parent_headers($hdr, $srch);
354 my ($dst, $ctx, $hdr, $tpfx) = @_;
355 my $srch = $ctx->{srch};
356 my $mid = mid_clean($hdr->header_raw('Message-ID'));
357 my $sres = $srch->get_thread($mid);
358 my $nr = $sres->{total};
359 my $expand = qq(<a\nhref="${tpfx}t/#u">expand</a> ) .
360 qq(/ <a\nhref="${tpfx}t.mbox.gz">mbox.gz</a> ) .
361 qq(/ <a\nhref="${tpfx}t.atom">Atom feed</a>);
363 my $parent = in_reply_to($hdr);
365 if (defined $parent) {
366 $$dst .= "($expand)\n ";
367 $$dst .= ghost_parent("$tpfx../", $parent) . "\n";
369 $$dst .= "[no followups, yet] ($expand)\n";
371 $ctx->{next_msg} = undef;
372 $ctx->{parent_msg} = $parent;
376 $$dst .= "$nr+ messages in thread ($expand";
377 $$dst .= qq! / <a\nhref="#b">[top]</a>)\n!;
379 my $subj = $srch->subject_path($hdr->header('Subject'));
381 seen => { $subj => 1 },
387 for (thread_results(load_results($sres))->rootset) {
388 skel_dump($dst, $state, $tpfx, $_, 0);
390 $ctx->{next_msg} = $state->{next_msg};
391 $ctx->{parent_msg} = $parent;
394 sub _parent_headers {
395 my ($hdr, $srch) = @_;
398 my $irt = in_reply_to($hdr);
400 my $v = PublicInbox::Hval->new_msgid($irt, 1);
401 my $html = $v->as_html;
402 my $href = $v->as_href;
403 $rv .= "In-Reply-To: <";
404 $rv .= "<a\nhref=\"../$href/\">$html</a>>\n";
407 # do not display References: if search is present,
408 # we show the thread skeleton at the bottom, instead.
411 my $refs = $hdr->header_raw('References');
413 # avoid redundant URLs wasting bandwidth
415 $seen{$irt} = 1 if defined $irt;
417 my @raw_refs = ($refs =~ /<([^>]+)>/g);
418 foreach my $ref (@raw_refs) {
421 push @refs, linkify_ref_nosrch($ref);
425 $rv .= 'References: '. join("\n\t", @refs) . "\n";
431 sub mailto_arg_link {
433 my %cc; # everyone else
434 my $to; # this is the From address
436 foreach my $h (qw(From To Cc)) {
437 my $v = $hdr->header($h);
438 defined($v) && ($v ne '') or next;
439 my @addrs = PublicInbox::Address::emails($v);
440 foreach my $address (@addrs) {
441 my $dst = lc($address);
442 $cc{$dst} ||= $address;
448 my $subj = $hdr->header('Subject') || '';
449 $subj = "Re: $subj" unless $subj =~ /\bRe:/i;
450 my $mid = $hdr->header_raw('Message-ID');
451 push @arg, "--in-reply-to='" . ascii_html($mid) . "'";
452 my $irt = uri_escape_utf8($mid);
454 push @arg, '--to=' . ascii_html($to);
455 $to = uri_escape_utf8($to);
456 $subj = uri_escape_utf8($subj);
457 my $cc = join(',', sort values %cc);
458 push @arg, '--cc=' . ascii_html($cc);
459 $cc = uri_escape_utf8($cc);
460 my $href = "mailto:$to?In-Reply-To=$irt&Cc=${cc}&Subject=$subj";
467 my ($hdr, $standalone, $ctx, $rhref) = @_;
469 my $srch = $ctx->{srch} if $ctx;
472 my $idx = $standalone ? " <a\nhref=\"$upfx\">index</a>" : '';
476 thread_skel(\$idx, $ctx, $hdr, $tpfx);
477 my $p = $ctx->{parent_msg};
478 my $next = $ctx->{next_msg};
480 $p = PublicInbox::Hval->new_msgid($p);
482 $irt = "<a\nhref=\"$upfx$p/\"rel=prev>parent</a> ";
484 $irt = ' ' x length('parent ');
487 my $n = PublicInbox::Hval->new_msgid($next)->as_href;
488 $irt .= "<a\nhref=\"$upfx$n/\"\nrel=next>next</a> ";
490 $irt .= ' ' x length('next ');
496 $irt .= qq(<a\nhref="$rhref">reply</a>);
500 sub linkify_ref_nosrch {
501 my $v = PublicInbox::Hval->new_msgid($_[0], 1);
502 my $html = $v->as_html;
503 my $href = $v->as_href;
504 "<<a\nhref=\"../$href/\">$html</a>>";
510 if ($id !~ /\A[a-f0-9]{40}\z/) {
511 $id = id_compress(mid_clean($id), 1);
516 sub thread_html_head {
517 my ($hdr, $state) = @_;
518 my $res = delete $state->{res} or die "BUG: no Plack callback in {res}";
519 my $fh = $res->([200, ['Content-Type'=> 'text/html; charset=UTF-8']]);
522 my $s = ascii_html($hdr->header('Subject'));
523 $fh->write("<html><head><title>$s</title>".
524 qq{<link\nrel=alternate\ntitle="Atom feed"\n} .
525 qq!href="../t.atom"\ntype="application/atom+xml"/>! .
526 PublicInbox::Hval::STYLE .
530 sub pre_anchor_entry {
531 my ($seen, $mime) = @_;
532 my $id = anchor_for(mid_mime($mime));
533 $seen->{$id} = "#$id"; # save the anchor for children, later
537 my ($upfx, $mid) = @_;
538 # 'subject dummy' is used internally by Mail::Thread
539 return '[no common parent]' if ($mid eq 'subject dummy');
541 $mid = PublicInbox::Hval->new_msgid($mid);
542 my $href = $mid->as_href;
543 my $html = $mid->as_html;
544 qq{[parent not found: <<a\nhref="$upfx$href/">$html</a>>]};
547 sub thread_adj_level {
548 my ($state, $level) = @_;
550 my $max = $state->{cur_level};
552 return '' if $max == 0; # flat output
554 # reset existing lists
555 my $x = $max > 1 ? ('</ul></li>' x ($max - 1)) : '';
556 $state->{fh}->write($x . '</ul>');
557 $state->{cur_level} = 0;
560 if ($level == $max) { # continue existing list
561 $state->{fh}->write('<li>');
562 } elsif ($level < $max) {
563 my $x = $max > 1 ? ('</ul></li>' x ($max - $level)) : '';
564 $state->{fh}->write($x .= '<li>');
565 $state->{cur_level} = $level;
566 } else { # ($level > $max) # start a new level
567 $state->{cur_level} = $level;
568 $state->{fh}->write(($max ? '<li>' : '') . '<ul><li>');
574 my ($state, $upfx, $mid, $level) = @_;
575 my $end = '<pre>'. ghost_parent($upfx, $mid) . '</pre>';
576 $state->{fh}->write($end .= thread_adj_level($state, $level));
580 my ($state, $mime, $level) = @_;
582 # lazy load the full message from mini_mime:
584 my $path = mid2path(mid_clean(mid_mime($mime)));
585 Email::MIME->new($state->{ctx}->{git}->cat_file('HEAD:'.$path));
588 thread_html_head($mime, $state) if $state->{anchor_idx} == 0;
589 if (my $ghost = delete $state->{ghost}) {
590 # n.b. ghost messages may only be parents, not children
591 foreach my $g (@$ghost) {
592 ghost_flush($state, '../../', @$g);
595 my $end = thread_adj_level($state, $level);
596 index_entry($mime, $level, $state);
597 $state->{fh}->write($end) if $end;
604 INDENT x ($level - 1);
607 sub __ghost_prepare {
608 my ($state, $node, $level) = @_;
609 my $ghost = $state->{ghost} ||= [];
610 push @$ghost, [ $node->messageid, $level ];
614 my ($state, $node, $level) = @_;
616 if (my $mime = $node->message) {
617 unless (__thread_entry($state, $mime, $level)) {
618 __ghost_prepare($state, $node, $level);
621 __ghost_prepare($state, $node, $level);
624 thread_entry($state, $node->child, $level + 1);
625 thread_entry($state, $node->next, $level);
631 [ map { $_->mini_mime } @{delete $sres->{msgs}} ];
636 my $ts = eval { str2time($hdr->header('Date')) };
637 defined($ts) ? $ts : 0;
642 require PublicInbox::Thread;
643 my $th = PublicInbox::Thread->new(@$msgs);
645 $th->order(*sort_ts);
650 my ($res, $ctx) = @_;
651 require PublicInbox::ExtMsg;
653 $res->(PublicInbox::ExtMsg::ext_msg($ctx))
658 my $ts = $hdr->header('X-PI-TS') || msg_timestamp($hdr);
662 sub fmt_ts { POSIX::strftime('%Y-%m-%d %k:%M', gmtime($_[0])) }
665 my ($dst, $state, $upfx, $hdr, $level) = @_;
667 my $cur = $state->{cur};
668 my $mid = mid_clean($hdr->header_raw('Message-ID'));
669 my $f = ascii_html($hdr->header('X-PI-From'));
670 my $d = _msg_date($hdr);
671 my $pfx = "$d " . indent_for($level) . th_pfx($level);
673 $state->{first_level} ||= $level;
675 if ($attr ne $state->{prev_attr} || $state->{prev_level} > $level) {
676 $state->{prev_attr} = $attr;
680 $state->{prev_level} = $level;
684 delete $state->{cur};
685 $$dst .= "$pfx<b><a\nid=r\nhref=\"#t\">".
686 "$attr [this message]</a></b>\n";
691 $state->{next_msg} ||= $mid;
694 # Subject is never undef, this mail was loaded from
695 # our Xapian which would've resulted in '' if it were
696 # really missing (and Filter rejects empty subjects)
697 my $s = $hdr->header('Subject');
698 my $h = $state->{srch}->subject_path($s);
699 if ($state->{seen}->{$h}) {
702 $state->{seen}->{$h} = 1;
703 $s = PublicInbox::Hval->new($s);
706 my $m = PublicInbox::Hval->new_msgid($mid);
707 $m = $upfx . '../' . $m->as_href . '/';
708 $$dst .= "$pfx<a\nhref=\"$m\">";
709 $$dst .= defined($s) ? "$s</a> $f\n" : "$f</a>\n";
713 my ($dst, $state, $upfx, $node, $level) = @_;
715 if (my $mime = $node->message) {
716 my $hdr = $mime->header_obj;
717 my $mid = mid_clean($hdr->header_raw('Message-ID'));
718 _skel_header($dst, $state, $upfx, $hdr, $level);
720 my $mid = $node->messageid;
721 if ($mid eq 'subject dummy') {
722 $$dst .= "\t[no common parent]\n";
724 $$dst .= ' [not found] ';
725 $$dst .= indent_for($level) . th_pfx($level);
726 $mid = PublicInbox::Hval->new_msgid($mid);
727 my $href = "$upfx../" . $mid->as_href . '/';
728 my $html = $mid->as_html;
729 $$dst .= qq{<<a\nhref="$href">$html</a>>\n};
732 skel_dump($dst, $state, $upfx, $node->child, $level+1);
733 skel_dump($dst, $state, $upfx, $node->next, $level);
738 (eval { $a->topmost->message->header('X-PI-TS') } || 0) <=>
739 (eval { $b->topmost->message->header('X-PI-TS') } || 0)
743 # accumulate recent topics if search is supported
744 # returns 1 if done, undef if not
746 my ($state, $node, $level) = @_;
748 my $child_adjust = 1;
750 if (my $x = $node->message) {
754 $subj = $x->header('Subject');
755 $subj = $state->{srch}->subject_normalized($subj);
757 if (++$state->{subjs}->{$subj} == 1) {
758 push @{$state->{order}}, [ $level, $subj ];
761 my $mid = mid_clean($x->header_raw('Message-ID'));
763 my $ts = $x->header('X-PI-TS');
764 my $exist = $state->{latest}->{$subj};
765 if (!$exist || $exist->[1] < $ts) {
766 $state->{latest}->{$subj} = [ $mid, $ts ];
769 # ghost message, do not bump level
773 add_topic($state, $node->child, $level + $child_adjust);
774 add_topic($state, $node->next, $level);
779 my $order = $state->{order};
780 my $subjs = $state->{subjs};
781 my $latest = $state->{latest};
782 my $fh = $state->{fh};
783 return $fh->write("\n[No topics in range]</pre>") unless scalar @$order;
789 while (defined(my $info = shift @$order)) {
790 my ($level, $subj) = @$info;
791 my $n = delete $subjs->{$subj};
792 my ($mid, $ts) = @{delete $latest->{$subj}};
793 $mid = PublicInbox::Hval->new_msgid($mid)->as_href;
794 $subj = PublicInbox::Hval->new($subj)->as_html;
795 $pfx = indent_for($level);
796 my $nl = $level == $prev ? "\n" : '';
801 $cur ||= [ $ts, '' ];
802 $cur->[0] = $ts if $ts > $cur->[0];
803 $cur->[1] .= $nl . $pfx . th_pfx($level) .
804 "<a\nhref=\"$mid/t/#u\"><b>" .
805 $subj . "</b></a>\n";
808 my $attr = " $ts UTC";
810 # $n isn't the total number of posts on the topic,
811 # just the number of posts in the current results window
812 $n = $n == 1 ? '' : " ($n+ messages)";
814 if ($level == 0 || $attr ne $prev_attr) {
815 my $mbox = qq(<a\nhref="$mid/t.mbox.gz">mbox.gz</a>);
816 my $atom = qq(<a\nhref="$mid/t.atom">Atom</a>);
817 $pfx .= INDENT if $level > 0;
818 $cur->[1] .= $pfx . $attr . $n . " - $mbox / $atom\n";
822 push @recent, $cur if $cur;
823 @recent = map { $_->[1] } sort { $b->[0] <=> $a->[0] } @recent;
824 $fh->write(join('', @recent) . '</pre>');
827 sub emit_index_topics {
829 my ($off) = (($state->{ctx}->{cgi}->param('o') || '0') =~ /(\d+)/);
830 $state->{order} = [];
831 $state->{subjs} = {};
832 $state->{latest} = {};
834 my %opts = ( offset => $off, limit => $max * 4 );
835 while (scalar @{$state->{order}} < $max) {
836 my $sres = $state->{srch}->query('', \%opts);
837 my $nr = scalar @{$sres->{msgs}} or last;
839 for (thread_results(load_results($sres))->rootset) {
840 add_topic($state, $_, 0);
842 $opts{offset} += $nr;