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 '<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) }
156 my ($th, $state, $cb) = @_;
157 my @q = map { (0, $_) } $th->rootset;
159 my $level = shift @q;
160 my $node = shift @q or next;
161 $cb->($state, $level, $node);
162 unshift @q, $level+1, $node->child, $level, $node->next;
166 # only private functions below.
168 sub emit_thread_html {
169 my ($res, $ctx, $foot, $srch) = @_;
170 my $mid = $ctx->{mid};
171 my $flat = $ctx->{flat};
172 my $msgs = load_results($srch->get_thread($mid, { asc => $flat }));
173 my $nr = scalar @$msgs;
174 return missing_thread($res, $ctx) if $nr == 0;
180 root_anchor => anchor_for($mid),
185 require PublicInbox::Git;
186 $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir});
188 pre_anchor_entry($seen, $_) for (@$msgs);
189 __thread_entry($state, $_, 0) for (@$msgs);
191 walk_thread(thread_results($msgs), $state, *thread_entry);
192 if (my $max = $state->{cur_level}) {
194 ('</ul></li>' x ($max - 1)) . '</ul>');
198 # there could be a race due to a message being deleted in git
199 # but still being in the Xapian index:
200 my $fh = delete $state->{fh} or return missing_thread($res, $ctx);
202 my $final_anchor = $state->{anchor_idx};
203 my $next = "<a\nid=s$final_anchor>";
204 $next .= $final_anchor == 1 ? 'only message in' : 'end of';
205 $next .= " thread</a>, back to <a\nhref=\"../../\">index</a>";
206 $next .= "\ndownload thread: ";
207 $next .= "<a\nhref=\"../t.mbox.gz\">mbox.gz</a>";
208 $next .= " / follow: <a\nhref=\"../t.atom\">Atom feed</a>";
209 $fh->write('<hr /><pre>' . $next . "\n\n".
210 $foot . '</pre></body></html>');
215 my ($fh, $upfx, $p) = @_;
216 my $s = add_text_body($upfx, $p);
223 sub multipart_text_as_html {
224 my ($mime, $upfx) = @_;
227 # scan through all parts, looking for displayable text
228 msg_iter($mime, sub {
230 $rv .= add_text_body($upfx, $p);
236 my ($s, $l, $quot) = @_;
238 # show everything in the full version with anchor from
239 # short version (see above)
240 my $rv = $l->linkify_1(join('', @$quot));
243 # we use a <span> here to allow users to specify their own
244 # color for quoted text
245 $rv = $l->linkify_2(ascii_html($rv));
246 $$s .= qq(<span\nclass="q">) . $rv . '</span>'
249 sub attach_link ($$$$) {
250 my ($upfx, $ct, $p, $fn) = @_;
251 my ($part, $depth, @idx) = @$p;
252 my $nl = $idx[-1] > 1 ? "\n" : '';
253 my $idx = join('.', @idx);
254 my $size = bytes::length($part->body);
255 $ct ||= 'text/plain';
256 $ct =~ s/;.*//; # no attributes
257 $ct = ascii_html($ct);
258 my $desc = $part->header('Content-Description');
259 $desc = $fn unless defined $desc;
260 $desc = '' unless defined $desc;
262 if (defined $fn && $fn =~ /\A[[:alnum:]][\w\.-]+[[:alnum:]]\z/) {
264 } elsif ($ct eq 'text/plain') {
269 my @ret = qq($nl<a\nhref="$upfx$idx-$sfn">[-- Attachment #$idx: );
270 my $ts = "Type: $ct, Size: $size bytes";
271 push(@ret, ($desc eq '') ? "$ts --]" : "$desc --]\n[-- $ts --]");
272 join('', @ret, "</a>\n");
276 my ($upfx, $p) = @_; # from msg_iter: [ Email::MIME, depth, @idx ]
277 my ($part, $depth, @idx) = @$p;
278 my $ct = $part->content_type;
279 my $fn = $part->filename;
281 if (defined $ct && $ct =~ m!\btext/x?html\b!i) {
282 return attach_link($upfx, $ct, $p, $fn);
285 my $s = eval { $part->body_str };
287 # badly-encoded message? tell the world about it!
288 return attach_link($upfx, $ct, $p, $fn) if $@;
290 my @lines = split(/^/m, $s);
292 if (defined($fn) || $depth > 0) {
293 $s .= attach_link($upfx, $ct, $p, $fn);
297 my $l = PublicInbox::Linkify->new;
298 while (defined(my $cur = shift @lines)) {
300 # show the previously buffered quote inline
301 flush_quote(\$s, $l, \@quot) if @quot;
304 $cur = $l->linkify_1($cur);
305 $cur = ascii_html($cur);
306 $s .= $l->linkify_2($cur);
315 flush_quote(\$s, $l, \@quot);
317 $s =~ s/[ \t]+$//sgm; # kill per-line trailing whitespace
318 $s =~ s/\A\n+//s; # kill leading blank lines
319 $s =~ s/\s+\z//s; # kill all trailing spaces
323 sub _msg_html_prepare {
324 my ($hdr, $ctx) = @_;
325 my $srch = $ctx->{srch} if $ctx;
327 my $rv = "<pre\nid=b>"; # anchor for body start
330 $ctx->{-upfx} = '../';
333 my $mid = $hdr->header_raw('Message-ID');
334 $mid = PublicInbox::Hval->new_msgid($mid);
335 foreach my $h (qw(From To Cc Subject Date)) {
336 my $v = $hdr->header($h);
337 defined($v) && ($v ne '') or next;
338 $v = PublicInbox::Hval->new($v);
341 my $n = PublicInbox::Address::from_name($v->raw);
342 $title[1] = ascii_html($n);
343 } elsif ($h eq 'Subject') {
344 $title[0] = $v->as_html;
346 $rv .= qq($h: <a\nhref="#r"\nid=t>);
347 $rv .= $v->as_html . "</a>\n";
352 $v =~ s/(\@[^,]+,) /$1\n\t/g if ($h eq 'Cc' || $h eq 'To');
356 $title[0] ||= '(no subject)';
357 $ctx->{-title_html} = join(' - ', @title);
358 $rv .= 'Message-ID: <' . $mid->as_html . '> ';
359 $rv .= "(<a\nhref=\"raw\">raw</a>)\n";
360 $rv .= _parent_headers($hdr, $srch);
365 my ($dst, $ctx, $hdr, $tpfx) = @_;
366 my $srch = $ctx->{srch};
367 my $mid = mid_clean($hdr->header_raw('Message-ID'));
368 my $sres = $srch->get_thread($mid);
369 my $nr = $sres->{total};
370 my $expand = qq(<a\nhref="${tpfx}t/#u">expand</a> ) .
371 qq(/ <a\nhref="${tpfx}t.mbox.gz">mbox.gz</a> ) .
372 qq(/ <a\nhref="${tpfx}t.atom">Atom feed</a>);
374 my $parent = in_reply_to($hdr);
376 if (defined $parent) {
377 $$dst .= "($expand)\n ";
378 $$dst .= ghost_parent("$tpfx../", $parent) . "\n";
380 $$dst .= "[no followups, yet] ($expand)\n";
382 $ctx->{next_msg} = undef;
383 $ctx->{parent_msg} = $parent;
387 $$dst .= "$nr+ messages in thread ($expand";
388 $$dst .= qq! / <a\nhref="#b">[top]</a>)\n!;
390 my $subj = $srch->subject_path($hdr->header('Subject'));
392 seen => { $subj => 1 },
400 walk_thread(thread_results(load_results($sres)), $state, *skel_dump);
401 $ctx->{next_msg} = $state->{next_msg};
402 $ctx->{parent_msg} = $parent;
405 sub _parent_headers {
406 my ($hdr, $srch) = @_;
409 my $irt = in_reply_to($hdr);
411 my $v = PublicInbox::Hval->new_msgid($irt, 1);
412 my $html = $v->as_html;
413 my $href = $v->as_href;
414 $rv .= "In-Reply-To: <";
415 $rv .= "<a\nhref=\"../$href/\">$html</a>>\n";
418 # do not display References: if search is present,
419 # we show the thread skeleton at the bottom, instead.
422 my $refs = $hdr->header_raw('References');
424 # avoid redundant URLs wasting bandwidth
426 $seen{$irt} = 1 if defined $irt;
428 my @raw_refs = ($refs =~ /<([^>]+)>/g);
429 foreach my $ref (@raw_refs) {
432 push @refs, linkify_ref_nosrch($ref);
436 $rv .= 'References: '. join("\n\t", @refs) . "\n";
442 sub mailto_arg_link {
444 my %cc; # everyone else
445 my $to; # this is the From address
447 foreach my $h (qw(From To Cc)) {
448 my $v = $hdr->header($h);
449 defined($v) && ($v ne '') or next;
450 my @addrs = PublicInbox::Address::emails($v);
451 foreach my $address (@addrs) {
452 my $dst = lc($address);
453 $cc{$dst} ||= $address;
459 my $subj = $hdr->header('Subject') || '';
460 $subj = "Re: $subj" unless $subj =~ /\bRe:/i;
461 my $mid = $hdr->header_raw('Message-ID');
462 push @arg, "--in-reply-to='" . ascii_html($mid) . "'";
463 my $irt = uri_escape_utf8($mid);
465 push @arg, '--to=' . ascii_html($to);
466 $to = uri_escape_utf8($to);
467 $subj = uri_escape_utf8($subj);
468 my $cc = join(',', sort values %cc);
469 push @arg, '--cc=' . ascii_html($cc);
470 $cc = uri_escape_utf8($cc);
471 my $href = "mailto:$to?In-Reply-To=$irt&Cc=${cc}&Subject=$subj";
478 my ($hdr, $standalone, $ctx, $rhref) = @_;
480 my $srch = $ctx->{srch} if $ctx;
483 my $idx = $standalone ? " <a\nhref=\"$upfx\">index</a>" : '';
487 thread_skel(\$idx, $ctx, $hdr, $tpfx);
488 my $p = $ctx->{parent_msg};
489 my $next = $ctx->{next_msg};
491 $p = PublicInbox::Hval->new_msgid($p);
493 $irt = "<a\nhref=\"$upfx$p/\"rel=prev>parent</a> ";
495 $irt = ' ' x length('parent ');
498 my $n = PublicInbox::Hval->new_msgid($next)->as_href;
499 $irt .= "<a\nhref=\"$upfx$n/\"\nrel=next>next</a> ";
501 $irt .= ' ' x length('next ');
507 $irt .= qq(<a\nhref="$rhref">reply</a>);
511 sub linkify_ref_nosrch {
512 my $v = PublicInbox::Hval->new_msgid($_[0], 1);
513 my $html = $v->as_html;
514 my $href = $v->as_href;
515 "<<a\nhref=\"../$href/\">$html</a>>";
521 if ($id !~ /\A[a-f0-9]{40}\z/) {
522 $id = id_compress(mid_clean($id), 1);
527 sub thread_html_head {
528 my ($hdr, $state) = @_;
529 my $res = delete $state->{res} or die "BUG: no Plack callback in {res}";
530 my $fh = $res->([200, ['Content-Type'=> 'text/html; charset=UTF-8']]);
533 my $s = ascii_html($hdr->header('Subject'));
534 $fh->write("<html><head><title>$s</title>".
535 qq{<link\nrel=alternate\ntitle="Atom feed"\n} .
536 qq!href="../t.atom"\ntype="application/atom+xml"/>! .
537 PublicInbox::Hval::STYLE .
541 sub pre_anchor_entry {
542 my ($seen, $mime) = @_;
543 my $id = anchor_for(mid_mime($mime));
544 $seen->{$id} = "#$id"; # save the anchor for children, later
548 my ($upfx, $mid) = @_;
549 # 'subject dummy' is used internally by Mail::Thread
550 return '[no common parent]' if ($mid eq 'subject dummy');
552 $mid = PublicInbox::Hval->new_msgid($mid);
553 my $href = $mid->as_href;
554 my $html = $mid->as_html;
555 qq{[parent not found: <<a\nhref="$upfx$href/">$html</a>>]};
558 sub thread_adj_level {
559 my ($state, $level) = @_;
561 my $max = $state->{cur_level};
563 return '' if $max == 0; # flat output
565 # reset existing lists
566 my $x = $max > 1 ? ('</ul></li>' x ($max - 1)) : '';
567 $state->{fh}->write($x . '</ul>');
568 $state->{cur_level} = 0;
571 if ($level == $max) { # continue existing list
572 $state->{fh}->write('<li>');
573 } elsif ($level < $max) {
574 my $x = $max > 1 ? ('</ul></li>' x ($max - $level)) : '';
575 $state->{fh}->write($x .= '<li>');
576 $state->{cur_level} = $level;
577 } else { # ($level > $max) # start a new level
578 $state->{cur_level} = $level;
579 $state->{fh}->write(($max ? '<li>' : '') . '<ul><li>');
585 my ($state, $upfx, $mid, $level) = @_;
586 my $end = '<pre>'. ghost_parent($upfx, $mid) . '</pre>';
587 $state->{fh}->write($end .= thread_adj_level($state, $level));
591 my ($state, $mime, $level) = @_;
593 # lazy load the full message from mini_mime:
595 my $mid = mid_clean(mid_mime($mime));
596 $state->{ctx}->{-inbox}->msg_by_mid($mid);
598 $mime = Email::MIME->new($mime);
600 thread_html_head($mime, $state) if $state->{anchor_idx} == 0;
601 if (my $ghost = delete $state->{ghost}) {
602 # n.b. ghost messages may only be parents, not children
603 foreach my $g (@$ghost) {
604 ghost_flush($state, '../../', @$g);
607 my $end = thread_adj_level($state, $level);
608 index_entry($mime, $level, $state);
609 $state->{fh}->write($end) if $end;
616 INDENT x ($level - 1);
619 sub __ghost_prepare {
620 my ($state, $node, $level) = @_;
621 my $ghost = $state->{ghost} ||= [];
622 push @$ghost, [ $node->messageid, $level ];
626 my ($state, $level, $node) = @_;
627 if (my $mime = $node->message) {
628 unless (__thread_entry($state, $mime, $level)) {
629 __ghost_prepare($state, $node, $level);
632 __ghost_prepare($state, $node, $level);
639 [ map { $_->mini_mime } @{delete $sres->{msgs}} ];
644 my $ts = eval { str2time($hdr->header('Date')) };
645 defined($ts) ? $ts : 0;
650 require PublicInbox::Thread;
651 my $th = PublicInbox::Thread->new(@$msgs);
653 $th->order(*sort_ts);
658 my ($res, $ctx) = @_;
659 require PublicInbox::ExtMsg;
661 $res->(PublicInbox::ExtMsg::ext_msg($ctx))
666 my $ts = $hdr->header('X-PI-TS') || msg_timestamp($hdr);
670 sub fmt_ts { POSIX::strftime('%Y-%m-%d %k:%M', gmtime($_[0])) }
673 my ($state, $hdr, $level) = @_;
675 my $dst = $state->{dst};
676 my $cur = $state->{cur};
677 my $mid = mid_clean($hdr->header_raw('Message-ID'));
678 my $f = ascii_html($hdr->header('X-PI-From'));
679 my $d = _msg_date($hdr);
680 my $pfx = "$d " . indent_for($level) . th_pfx($level);
682 $state->{first_level} ||= $level;
684 if ($attr ne $state->{prev_attr} || $state->{prev_level} > $level) {
685 $state->{prev_attr} = $attr;
689 $state->{prev_level} = $level;
693 delete $state->{cur};
694 $$dst .= "$pfx<b><a\nid=r\nhref=\"#t\">".
695 "$attr [this message]</a></b>\n";
700 $state->{next_msg} ||= $mid;
703 # Subject is never undef, this mail was loaded from
704 # our Xapian which would've resulted in '' if it were
705 # really missing (and Filter rejects empty subjects)
706 my $s = $hdr->header('Subject');
707 my $h = $state->{srch}->subject_path($s);
708 if ($state->{seen}->{$h}) {
711 $state->{seen}->{$h} = 1;
712 $s = PublicInbox::Hval->new($s);
715 my $m = PublicInbox::Hval->new_msgid($mid);
716 $m = $state->{upfx} . $m->as_href . '/';
717 $$dst .= "$pfx<a\nhref=\"$m\">";
718 $$dst .= defined($s) ? "$s</a> $f\n" : "$f</a>\n";
722 my ($state, $level, $node) = @_;
723 if (my $mime = $node->message) {
724 my $hdr = $mime->header_obj;
725 my $mid = mid_clean($hdr->header_raw('Message-ID'));
726 _skel_header($state, $hdr, $level);
728 my $mid = $node->messageid;
729 my $dst = $state->{dst};
730 if ($mid eq 'subject dummy') {
731 $$dst .= "\t[no common parent]\n";
733 $$dst .= ' [not found] ';
734 $$dst .= indent_for($level) . th_pfx($level);
735 $mid = PublicInbox::Hval->new_msgid($mid);
736 my $href = $state->{upfx} . $mid->as_href . '/';
737 my $html = $mid->as_html;
738 $$dst .= qq{<<a\nhref="$href">$html</a>>\n};
745 (eval { $a->topmost->message->header('X-PI-TS') } || 0) <=>
746 (eval { $b->topmost->message->header('X-PI-TS') } || 0)
750 sub _tryload_ghost ($$) {
751 my ($srch, $mid) = @_;
752 my $smsg = $srch->lookup_mail($mid) or return;
756 # accumulate recent topics if search is supported
757 # returns 1 if done, undef if not
759 my ($state, $level, $node) = @_;
760 my $srch = $state->{srch};
761 my $mid = $node->messageid;
762 my $x = $node->message || _tryload_ghost($srch, $mid);
766 $subj = $x->header('Subject');
767 $subj = $srch->subject_normalized($subj);
768 $ts = $x->header('X-PI-TS');
769 } else { # ghost message, do not bump level
773 if (++$state->{subjs}->{$subj} == 1) {
774 push @{$state->{order}}, [ $level, $subj ];
776 my $exist = $state->{latest}->{$subj};
777 if (!$exist || $exist->[1] < $ts) {
778 $state->{latest}->{$subj} = [ $mid, $ts ];
784 my $order = $state->{order};
785 my $subjs = $state->{subjs};
786 my $latest = $state->{latest};
787 my $fh = $state->{fh};
788 return $fh->write("\n[No topics in range]</pre>") unless scalar @$order;
794 while (defined(my $info = shift @$order)) {
795 my ($level, $subj) = @$info;
796 my $n = delete $subjs->{$subj};
797 my ($mid, $ts) = @{delete $latest->{$subj}};
798 $mid = PublicInbox::Hval->new_msgid($mid)->as_href;
799 $pfx = indent_for($level);
800 my $nl = $level == $prev ? "\n" : '';
805 $cur ||= [ $ts, '' ];
806 $cur->[0] = $ts if $ts > $cur->[0];
807 $cur->[1] .= $nl . $pfx . th_pfx($level);
808 if ($ts == -666) { # ghost
809 $cur->[1] .= ghost_parent('', $mid) . "\n";
810 next; # child will have mbox / atom link
813 $subj = PublicInbox::Hval->new($subj)->as_html;
814 $cur->[1] .= "<a\nhref=\"$mid/t/#u\"><b>$subj</b></a>\n";
816 my $attr = " $ts UTC";
818 # $n isn't the total number of posts on the topic,
819 # just the number of posts in the current results window
820 $n = $n == 1 ? '' : " ($n+ messages)";
822 if ($level == 0 || $attr ne $prev_attr) {
823 my $mbox = qq(<a\nhref="$mid/t.mbox.gz">mbox.gz</a>);
824 my $atom = qq(<a\nhref="$mid/t.atom">Atom</a>);
825 $pfx .= INDENT if $level > 0;
826 $cur->[1] .= $pfx . $attr . $n . " - $mbox / $atom\n";
830 push @recent, $cur if $cur;
831 @recent = map { $_->[1] } sort { $b->[0] <=> $a->[0] } @recent;
832 $fh->write(join('', @recent) . '</pre>');
835 sub emit_index_topics {
837 my ($off) = (($state->{ctx}->{cgi}->param('o') || '0') =~ /(\d+)/);
838 $state->{order} = [];
839 $state->{subjs} = {};
840 $state->{latest} = {};
842 my %opts = ( offset => $off, limit => $max * 4 );
843 while (scalar @{$state->{order}} < $max) {
844 my $sres = $state->{srch}->query('', \%opts);
845 my $nr = scalar @{$sres->{msgs}} or last;
846 $sres = load_results($sres);
847 walk_thread(thread_results($sres), $state, *add_topic);
848 $opts{offset} += $nr;