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 my $mapping = $ctx->{mapping};
123 $rv .= "From: "._hdr_names($hdr, 'From').' @ '._msg_date($hdr)." UTC";
124 my $upfx = $ctx->{-upfx};
125 $rv .= qq{ (<a\nhref="$upfx$mid_raw/">permalink</a> / };
126 $rv .= qq{<a\nhref="$upfx$mid_raw/raw">raw</a>)\n};
127 $rv .= ' '.join('; +', @tocc) . "\n" if @tocc;
128 if (!$mapping && $irt) {
129 $rv .= qq(In-Reply-To: <<a\nhref="$upfx$irt/">$irt</a>>\n)
133 # scan through all parts, looking for displayable text
134 my $href = $mid->as_href;
135 my $mhref = $ctx->{-upfx}.$href.'/';
136 msg_iter($mime, sub { $rv .= add_text_body($mhref, $_[0]) });
139 $rv .= "\n<a\nhref=#$id_m\nid=e$id>^</a> ".
140 "<a\nhref=\"$mhref\">permalink</a>" .
141 " / <a\nhref=\"${mhref}raw\">raw</a>" .
142 " / <a\nhref=\"${mhref}#R\">reply</a>";
143 if (my $pct = $ctx->{pct}) { # used by SearchView.pm
144 $rv .= " [relevance $pct->{$mid_raw}%]";
146 $rv .= $more ? "\n\n" : "\n";
150 my ($mid_raw, $irt, $id, $ctx) = @_;
152 my $mapping = $ctx->{mapping} or return $rv;
154 # map = [children, attr, node, idx, level]
155 my $map = $mapping->{$mid_raw};
156 my $nr_c = scalar @{$map->[0]};
159 my $irt_map = $mapping->{$irt};
160 my $siblings = $irt_map->[0];
161 $nr_s = scalar(@$siblings) - 1;
162 $nr_s = 0 if $nr_s < 0;
163 $rv .= $pad . $irt_map->[1];
166 my $prev = $siblings->[$idx - 1];
167 $rv .= $pad . $mapping->{$prev->messageid}->[1];
170 my $s_s = nr_to_s($nr_s, 'sibling', 'siblings');
171 my $s_c = nr_to_s($nr_c, 'reply', 'replies');
172 my $this = $map->[1];
173 $this =~ s!\n\z!</b>\n!s;
174 $this =~ s!<a\nhref.*a> !!s; # no point in duplicating subject
176 my $node = $map->[2];
177 if (my $child = $node->child) {
178 $rv .= $pad . $mapping->{$child->messageid}->[1];
180 if (my $next = $node->next) {
181 $rv .= $pad . $mapping->{$next->messageid}->[1];
183 $rv .= "<a\nhref=#e$id\nid=m$id>_<a> <a\nhref=#r$id\n>$s_s, $s_c</a>\n";
187 my ($th, $ctx, $cb) = @_;
188 my @q = map { (0, $_) } $th->rootset;
190 my $level = shift @q;
191 my $node = shift @q or next;
192 $cb->($ctx, $level, $node);
193 unshift @q, $level+1, $node->child, $level, $node->next;
198 my ($ctx, $level, $node) = @_;
199 my $mapping = $ctx->{mapping};
201 if (my $parent = $node->parent) {
202 my $m = $mapping->{$parent->messageid}->[0];
206 $mapping->{$node->messageid} = [ [], '', $node, $idx ];
207 skel_dump($ctx, $level, $node);
212 my $mid = $ctx->{mid};
213 my $sres = $ctx->{srch}->get_thread($mid, { asc => 1 });
214 my $msgs = load_results($sres);
215 my $nr = $sres->{total};
216 return missing_thread($ctx) if $nr == 0;
217 my $skel = '</pre><hr /><pre>';
218 $skel .= $nr == 1 ? 'only message in thread' : 'end of thread';
219 $skel .= ", back to <a\nhref=\"../../\">index</a>";
220 $skel .= "\n<a\nid=t>$nr+ messages in thread:</a> (download: ";
221 $skel .= "<a\nhref=\"../t.mbox.gz\">mbox.gz</a>";
222 $skel .= " / follow: <a\nhref=\"../t.atom\">Atom feed</a>)\n";
223 $ctx->{cur_level} = 0;
224 $ctx->{dst} = \$skel;
225 $ctx->{mapping} = {}; # mid -> [ reply count, from@date, node ];
226 $ctx->{prev_attr} = '';
227 $ctx->{prev_level} = 0;
228 $ctx->{root_anchor} = anchor_for($mid);
231 walk_thread(thread_results($msgs), $ctx, *pre_thread);
233 # lazy load the full message from mini_mime:
234 my $inbox = $ctx->{-inbox};
236 while ($mime = shift @$msgs) {
237 $mime = $inbox->msg_by_mid(mid_clean(mid_mime($mime))) and last;
239 $mime = Email::MIME->new($mime);
240 $ctx->{-upfx} = '../../';
241 $ctx->{-title_html} = ascii_html($mime->header('Subject'));
242 $ctx->{-html_tip} = '<pre>'.index_entry($mime, $ctx, scalar @$msgs);
244 my $body = PublicInbox::WwwStream->new($ctx, sub {
246 while ($mime = shift @$msgs) {
247 $mid = mid_clean(mid_mime($mime));
248 $mime = $inbox->msg_by_mid($mid) and last;
251 $mime = Email::MIME->new($mime);
252 return index_entry($mime, $ctx, scalar @$msgs);
257 [ 200, ['Content-Type', 'text/html; charset=UTF-8'], $body ];
260 sub multipart_text_as_html {
261 my ($mime, $upfx) = @_;
264 # scan through all parts, looking for displayable text
265 msg_iter($mime, sub {
267 $rv .= add_text_body($upfx, $p);
273 my ($s, $l, $quot) = @_;
275 # show everything in the full version with anchor from
276 # short version (see above)
277 my $rv = $l->linkify_1(join('', @$quot));
280 # we use a <span> here to allow users to specify their own
281 # color for quoted text
282 $rv = $l->linkify_2(ascii_html($rv));
283 $$s .= qq(<span\nclass="q">) . $rv . '</span>'
286 sub attach_link ($$$$) {
287 my ($upfx, $ct, $p, $fn) = @_;
288 my ($part, $depth, @idx) = @$p;
289 my $nl = $idx[-1] > 1 ? "\n" : '';
290 my $idx = join('.', @idx);
291 my $size = bytes::length($part->body);
292 $ct ||= 'text/plain';
293 $ct =~ s/;.*//; # no attributes
294 $ct = ascii_html($ct);
295 my $desc = $part->header('Content-Description');
296 $desc = $fn unless defined $desc;
297 $desc = '' unless defined $desc;
299 if (defined $fn && $fn =~ /\A[[:alnum:]][\w\.-]+[[:alnum:]]\z/) {
301 } elsif ($ct eq 'text/plain') {
306 my @ret = qq($nl<a\nhref="$upfx$idx-$sfn">[-- Attachment #$idx: );
307 my $ts = "Type: $ct, Size: $size bytes";
308 push(@ret, ($desc eq '') ? "$ts --]" : "$desc --]\n[-- $ts --]");
309 join('', @ret, "</a>\n");
313 my ($upfx, $p) = @_; # from msg_iter: [ Email::MIME, depth, @idx ]
314 my ($part, $depth, @idx) = @$p;
315 my $ct = $part->content_type;
316 my $fn = $part->filename;
318 if (defined $ct && $ct =~ m!\btext/x?html\b!i) {
319 return attach_link($upfx, $ct, $p, $fn);
322 my $s = eval { $part->body_str };
324 # badly-encoded message? tell the world about it!
325 return attach_link($upfx, $ct, $p, $fn) if $@;
327 my @lines = split(/^/m, $s);
329 if (defined($fn) || $depth > 0) {
330 $s .= attach_link($upfx, $ct, $p, $fn);
334 my $l = PublicInbox::Linkify->new;
335 while (defined(my $cur = shift @lines)) {
337 # show the previously buffered quote inline
338 flush_quote(\$s, $l, \@quot) if @quot;
341 $cur = $l->linkify_1($cur);
342 $cur = ascii_html($cur);
343 $s .= $l->linkify_2($cur);
352 flush_quote(\$s, $l, \@quot);
354 $s =~ s/[ \t]+$//sgm; # kill per-line trailing whitespace
355 $s =~ s/\A\n+//s; # kill leading blank lines
356 $s =~ s/\s+\z//s; # kill all trailing spaces
360 sub _msg_html_prepare {
361 my ($hdr, $ctx) = @_;
362 my $srch = $ctx->{srch} if $ctx;
364 my $rv = "<pre\nid=b>"; # anchor for body start
367 $ctx->{-upfx} = '../';
370 my $mid = $hdr->header_raw('Message-ID');
371 $mid = PublicInbox::Hval->new_msgid($mid);
372 foreach my $h (qw(From To Cc Subject Date)) {
373 my $v = $hdr->header($h);
374 defined($v) && ($v ne '') or next;
375 $v = PublicInbox::Hval->new($v);
378 my @n = PublicInbox::Address::names($v->raw);
379 $title[1] = ascii_html(join(', ', @n));
380 } elsif ($h eq 'Subject') {
381 $title[0] = $v->as_html;
383 $rv .= qq($h: <a\nhref="#r"\nid=t>);
384 $rv .= $v->as_html . "</a>\n";
389 $v =~ s/(\@[^,]+,) /$1\n\t/g if ($h eq 'Cc' || $h eq 'To');
393 $title[0] ||= '(no subject)';
394 $ctx->{-title_html} = join(' - ', @title);
395 $rv .= 'Message-ID: <' . $mid->as_html . '> ';
396 $rv .= "(<a\nhref=\"raw\">raw</a>)\n";
397 $rv .= _parent_headers($hdr, $srch);
402 my ($dst, $ctx, $hdr, $tpfx) = @_;
403 my $srch = $ctx->{srch};
404 my $mid = mid_clean($hdr->header_raw('Message-ID'));
405 my $sres = $srch->get_thread($mid);
406 my $nr = $sres->{total};
407 my $expand = qq(<a\nhref="${tpfx}t/#u">expand</a> ) .
408 qq(/ <a\nhref="${tpfx}t.mbox.gz">mbox.gz</a> ) .
409 qq(/ <a\nhref="${tpfx}t.atom">Atom feed</a>);
411 my $parent = in_reply_to($hdr);
413 if (defined $parent) {
414 $$dst .= "($expand)\n ";
415 $$dst .= ghost_parent("$tpfx../", $parent) . "\n";
417 $$dst .= "[no followups, yet] ($expand)\n";
419 $ctx->{next_msg} = undef;
420 $ctx->{parent_msg} = $parent;
424 $$dst .= "$nr+ messages in thread ($expand";
425 $$dst .= qq! / <a\nhref="#b">[top]</a>)\n!;
427 my $subj = $srch->subject_path($hdr->header('Subject'));
428 $ctx->{seen} = { $subj => 1 };
430 $ctx->{prev_attr} = '';
431 $ctx->{prev_level} = 0;
433 walk_thread(thread_results(load_results($sres)), $ctx, *skel_dump);
434 $ctx->{parent_msg} = $parent;
437 sub _parent_headers {
438 my ($hdr, $srch) = @_;
441 my $irt = in_reply_to($hdr);
443 my $v = PublicInbox::Hval->new_msgid($irt, 1);
444 my $html = $v->as_html;
445 my $href = $v->as_href;
446 $rv .= "In-Reply-To: <";
447 $rv .= "<a\nhref=\"../$href/\">$html</a>>\n";
450 # do not display References: if search is present,
451 # we show the thread skeleton at the bottom, instead.
454 my $refs = $hdr->header_raw('References');
456 # avoid redundant URLs wasting bandwidth
458 $seen{$irt} = 1 if defined $irt;
460 my @raw_refs = ($refs =~ /<([^>]+)>/g);
461 foreach my $ref (@raw_refs) {
464 push @refs, linkify_ref_nosrch($ref);
468 $rv .= 'References: '. join("\n\t", @refs) . "\n";
474 sub squote_maybe ($) {
476 if ($val =~ m{([^\w@\./,\%\+\-])}) {
477 $val =~ s/(['!])/'\\$1'/g; # '!' for csh
483 sub mailto_arg_link {
485 my %cc; # everyone else
486 my $to; # this is the From address
488 foreach my $h (qw(From To Cc)) {
489 my $v = $hdr->header($h);
490 defined($v) && ($v ne '') or next;
491 my @addrs = PublicInbox::Address::emails($v);
492 foreach my $address (@addrs) {
493 my $dst = lc($address);
494 $cc{$dst} ||= $address;
500 my $subj = $hdr->header('Subject') || '';
501 $subj = "Re: $subj" unless $subj =~ /\bRe:/i;
502 my $mid = $hdr->header_raw('Message-ID');
503 push @arg, '--in-reply-to='.ascii_html(squote_maybe(mid_clean($mid)));
504 my $irt = uri_escape_utf8($mid);
506 push @arg, '--to=' . ascii_html($to);
507 $to = uri_escape_utf8($to);
508 $subj = uri_escape_utf8($subj);
509 my $cc = join(',', sort values %cc);
510 push @arg, '--cc=' . ascii_html($cc);
511 $cc = uri_escape_utf8($cc);
512 my $href = "mailto:$to?In-Reply-To=$irt&Cc=${cc}&Subject=$subj";
515 (\@arg, ascii_html($href));
519 my ($hdr, $standalone, $ctx, $rhref) = @_;
521 my $srch = $ctx->{srch} if $ctx;
524 my $idx = $standalone ? " <a\nhref=\"$upfx\">index</a>" : '';
528 thread_skel(\$idx, $ctx, $hdr, $tpfx);
529 my $p = $ctx->{parent_msg};
530 my $next = $ctx->{next_msg};
532 $p = PublicInbox::Hval->new_msgid($p);
534 $irt = "<a\nhref=\"$upfx$p/\"\nrel=prev>parent</a> ";
536 $irt = ' ' x length('parent ');
539 my $n = PublicInbox::Hval->new_msgid($next)->as_href;
540 $irt .= "<a\nhref=\"$upfx$n/\"\nrel=next>next</a> ";
542 $irt .= ' ' x length('next ');
548 $irt .= qq(<a\nhref="$rhref">reply</a>);
552 sub linkify_ref_nosrch {
553 my $v = PublicInbox::Hval->new_msgid($_[0], 1);
554 my $html = $v->as_html;
555 my $href = $v->as_href;
556 "<<a\nhref=\"../$href/\">$html</a>>";
561 'm' . id_compress($msgid, 1);
565 my ($upfx, $mid) = @_;
566 # 'subject dummy' is used internally by Mail::Thread
567 return '[no common parent]' if ($mid eq 'subject dummy');
569 $mid = PublicInbox::Hval->new_msgid($mid);
570 my $href = $mid->as_href;
571 my $html = $mid->as_html;
572 qq{[parent not found: <<a\nhref="$upfx$href/">$html</a>>]};
577 INDENT x ($level - 1);
583 [ map { $_->mini_mime } @{delete $sres->{msgs}} ];
588 my $ts = eval { str2time($hdr->header('Date')) };
589 defined($ts) ? $ts : 0;
594 require PublicInbox::Thread;
595 my $th = PublicInbox::Thread->new(@$msgs);
597 $th->order(*sort_ts);
603 require PublicInbox::ExtMsg;
604 PublicInbox::ExtMsg::ext_msg($ctx);
609 my $ts = $hdr->header('X-PI-TS') || msg_timestamp($hdr);
613 sub fmt_ts { POSIX::strftime('%Y-%m-%d %k:%M', gmtime($_[0])) }
616 my ($ctx, $hdr, $level) = @_;
618 my $dst = $ctx->{dst};
619 my $cur = $ctx->{cur};
620 my $mid = mid_clean($hdr->header_raw('Message-ID'));
621 my $f = ascii_html($hdr->header('X-PI-From'));
622 my $d = _msg_date($hdr) . ' ' . indent_for($level) . th_pfx($level);
624 $ctx->{first_level} ||= $level;
626 if ($attr ne $ctx->{prev_attr} || $ctx->{prev_level} > $level) {
627 $ctx->{prev_attr} = $attr;
631 $ctx->{prev_level} = $level;
637 $$dst .= "<b><a\nid=r\nhref=\"#t\">".
638 "$attr [this message]</a></b>\n";
642 $ctx->{next_msg} ||= $mid;
645 # Subject is never undef, this mail was loaded from
646 # our Xapian which would've resulted in '' if it were
647 # really missing (and Filter rejects empty subjects)
648 my $s = $hdr->header('Subject');
649 my $h = $ctx->{srch}->subject_path($s);
650 if ($ctx->{seen}->{$h}) {
653 $ctx->{seen}->{$h} = 1;
654 $s = PublicInbox::Hval->new($s);
657 my $m = PublicInbox::Hval->new_msgid($mid);
659 my $mapping = $ctx->{mapping};
660 my $end = defined($s) ? "$s</a> $f\n" : "$f</a>\n";
662 my $map = $mapping->{$mid};
663 $id = id_compress($mid, 1);
665 $map->[1] = "$d<a\nhref=\"$m\">$end";
668 $m = $ctx->{-upfx}.$m->as_href.'/';
670 $$dst .= $d . "<a\nhref=\"$m\"$id>" . $end;
674 my ($ctx, $level, $node) = @_;
675 if (my $mime = $node->message) {
676 _skel_header($ctx, $mime->header_obj, $level);
678 my $mid = $node->messageid;
679 my $dst = $ctx->{dst};
680 my $mapping = $ctx->{mapping};
681 my $map = $mapping->{$mid} if $mapping;
682 if ($mid eq 'subject dummy') {
683 my $ncp = "\t[no common parent]\n";
684 $map->[1] = $ncp if $map;
688 my $d = $ctx->{pct} ? ' [irrelevant] ' # search result
690 $d .= indent_for($level) . th_pfx($level);
691 my $upfx = $ctx->{-upfx};
692 my $m = PublicInbox::Hval->new_msgid($mid);
693 my $href = $upfx . $m->as_href . '/';
694 my $html = $m->as_html;
697 my $id = id_compress($mid, 1);
698 $map->[1] = $d . qq{<<a\nhref=#r$id>$html</a>>\n};
699 $d .= qq{<<a\nhref="$href"\nid=r$id>$html</a>>\n};
701 $d .= qq{<<a\nhref="$href">$html</a>>\n};
709 (eval { $a->topmost->message->header('X-PI-TS') } || 0) <=>
710 (eval { $b->topmost->message->header('X-PI-TS') } || 0)
714 sub _tryload_ghost ($$) {
715 my ($srch, $mid) = @_;
716 my $smsg = $srch->lookup_mail($mid) or return;
720 # accumulate recent topics if search is supported
721 # returns 1 if done, undef if not
723 my ($ctx, $level, $node) = @_;
724 my $srch = $ctx->{srch};
725 my $mid = $node->messageid;
726 my $x = $node->message || _tryload_ghost($srch, $mid);
730 $subj = $x->header('Subject');
731 $subj = $srch->subject_normalized($subj);
732 $ts = $x->header('X-PI-TS');
733 } else { # ghost message, do not bump level
737 if (++$ctx->{subjs}->{$subj} == 1) {
738 push @{$ctx->{order}}, [ $level, $subj ];
740 my $exist = $ctx->{latest}->{$subj};
741 if (!$exist || $exist->[1] < $ts) {
742 $ctx->{latest}->{$subj} = [ $mid, $ts ];
748 my $order = $ctx->{order};
749 my $subjs = $ctx->{subjs};
750 my $latest = $ctx->{latest};
752 return $fh->write("\n[No topics in range]</pre>") unless scalar @$order;
758 while (defined(my $info = shift @$order)) {
759 my ($level, $subj) = @$info;
760 my $n = delete $subjs->{$subj};
761 my ($mid, $ts) = @{delete $latest->{$subj}};
762 $mid = PublicInbox::Hval->new_msgid($mid)->as_href;
763 $pfx = indent_for($level);
764 my $nl = $level == $prev ? "\n" : '';
769 $cur ||= [ $ts, '' ];
770 $cur->[0] = $ts if $ts > $cur->[0];
771 $cur->[1] .= $nl . $pfx . th_pfx($level);
772 if ($ts == -666) { # ghost
773 $cur->[1] .= ghost_parent('', $mid) . "\n";
774 next; # child will have mbox / atom link
777 $subj = PublicInbox::Hval->new($subj)->as_html;
778 $cur->[1] .= "<a\nhref=\"$mid/t/#u\"><b>$subj</b></a>\n";
780 my $attr = " $ts UTC";
782 # $n isn't the total number of posts on the topic,
783 # just the number of posts in the current results window
784 $n = $n == 1 ? '' : " ($n+ messages)";
786 if ($level == 0 || $attr ne $prev_attr) {
787 my $mbox = qq(<a\nhref="$mid/t.mbox.gz">mbox.gz</a>);
788 my $atom = qq(<a\nhref="$mid/t.atom">Atom</a>);
789 $pfx .= INDENT if $level > 0;
790 $cur->[1] .= $pfx . $attr . $n . " - $mbox / $atom\n";
794 push @recent, $cur if $cur;
795 @recent = map { $_->[1] } sort { $b->[0] <=> $a->[0] } @recent;
796 $fh->write(join('', @recent) . '</pre>');
799 sub emit_index_topics {
801 my ($off) = (($ctx->{cgi}->param('o') || '0') =~ /(\d+)/);
806 my %opts = ( offset => $off, limit => $max * 4 );
807 while (scalar @{$ctx->{order}} < $max) {
808 my $sres = $ctx->{srch}->query('', \%opts);
809 my $nr = scalar @{$sres->{msgs}} or last;
810 $sres = load_results($sres);
811 walk_thread(thread_results($sres), $ctx, *add_topic);
812 $opts{offset} += $nr;