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;
12 use PublicInbox::Hval qw/ascii_html/;
13 use PublicInbox::Linkify;
14 use PublicInbox::MID qw/mid_clean id_compress mid2path mid_mime/;
15 use PublicInbox::MsgIter;
16 use PublicInbox::Address;
19 use constant INDENT => ' ';
20 use constant TCHILD => '` ';
21 sub th_pfx ($) { $_[0] == 0 ? '' : TCHILD };
23 # public functions: (unstable)
24 # TODO: stream this, since threading is expensive but also oh-so-important
26 my ($ctx, $mime, $footer) = @_;
27 $footer = defined($footer) ? "\n$footer" : '';
28 my $hdr = $mime->header_obj;
29 headers_to_html_header($hdr, $ctx) .
30 multipart_text_as_html($mime, '') .
32 html_footer($hdr, 1, $ctx) .
33 '</pre>' . msg_reply($ctx, $hdr) .
34 '<hr /><pre>'. $footer . '</pre></body></html>';
37 # /$INBOX/$MESSAGE_ID/#R
41 'https://kernel.org/pub/software/scm/git/docs/git-send-email.html';
43 my ($arg, $link) = mailto_arg_link($hdr);
44 push @$arg, '/path/to/YOUR_REPLY';
47 "You may reply publically to <a\nhref=#t>this message</a> via email\n".
48 "using any one of the following methods:\n\n" .
49 "* Save the following mbox file, import it into your mail client,\n" .
50 " and reply-to-all from there: <a\nhref=raw>mbox</a>\n\n" .
51 "* Reply to all the recipients using the <b>--to</b>, <b>--cc</b>,\n" .
52 " and <b>--in-reply-to</b> switches of git-send-email(1):\n\n" .
53 "\tgit send-email \\\n\t\t" .
54 join(" \\ \n\t\t", @$arg ). "\n\n" .
55 qq( <a\nhref="$se_url">$se_url</a>\n\n) .
56 "* If your mail client supports setting the <b>In-Reply-To</b>" .
57 " header\n via mailto: links, try the " .
58 qq(<a\nhref="$link">mailto: link</a>\n) .
64 my $irt = $hdr->header_raw('In-Reply-To');
66 return mid_clean($irt) if (defined $irt);
68 my $refs = $hdr->header_raw('References');
69 if ($refs && $refs =~ /<([^>]+)>\s*\z/s) {
75 # this is already inside a <pre>
77 my ($mime, $level, $state) = @_;
78 my $midx = $state->{anchor_idx}++;
79 my $ctx = $state->{ctx};
80 my $srch = $ctx->{srch};
81 my $hdr = $mime->header_obj;
82 my $subj = $hdr->header('Subject');
84 my $mid_raw = mid_clean(mid_mime($mime));
85 my $id = anchor_for($mid_raw);
86 my $seen = $state->{seen};
87 $seen->{$id} = "#$id"; # save the anchor for children, later
89 my $mid = PublicInbox::Hval->new_msgid($mid_raw);
90 my $from = PublicInbox::Address::from_name($hdr->header('From'));
92 my $root_anchor = $state->{root_anchor} || '';
93 my $path = $root_anchor ? '../../' : '';
94 my $href = $mid->as_href;
95 my $irt = in_reply_to($hdr);
96 my $parent_anchor = $seen->{anchor_for($irt)} if defined $irt;
98 $from = ascii_html($from);
99 $subj = ascii_html($subj);
100 $subj = "<a\nhref=\"${path}$href/\">$subj</a>";
101 $subj = "<u\nid=u>$subj</u>" if $root_anchor eq $id;
103 my $ts = _msg_date($hdr);
104 my $rv = "<pre\nid=s$midx>";
105 $rv .= "<b\nid=$id>$subj</b>\n";
106 my $txt = "${path}$href/raw";
107 my $fh = $state->{fh};
108 $fh->write($rv .= "- $from @ $ts UTC (<a\nhref=\"$txt\">raw</a>)\n\n");
110 my $mhref = "${path}$href/";
112 # scan through all parts, looking for displayable text
113 msg_iter($mime, sub { index_walk($fh, $mhref, $_[0]) });
114 $rv = "\n" . html_footer($hdr, 0, $ctx, "$path$href/#R");
117 unless (defined $parent_anchor) {
118 my $v = PublicInbox::Hval->new_msgid($irt, 1);
120 $parent_anchor = "${path}$v/";
122 $rv .= " <a\nhref=\"$parent_anchor\">parent</a>";
124 if (my $pct = $state->{pct}) { # used by SearchView.pm
125 $rv .= " [relevance $pct->{$mid_raw}%]";
127 my $threaded = 'threaded';
131 $flat = "<b>$flat</b>";
132 $end = "\n"; # for lynx
134 $threaded = "<b>$threaded</b>";
136 $rv .= " [<a\nhref=\"${path}$href/t/#u\">$threaded</a>";
137 $rv .= "|<a\nhref=\"${path}$href/T/#u\">$flat</a>]$end";
139 $fh->write($rv .= '</pre>');
143 my ($ctx, $foot, $srch) = @_;
144 # $_[0] in sub is the Plack callback
145 sub { emit_thread_html($_[0], $ctx, $foot, $srch) }
148 # only private functions below.
150 sub emit_thread_html {
151 my ($res, $ctx, $foot, $srch) = @_;
152 my $mid = $ctx->{mid};
153 my $flat = $ctx->{flat};
154 my $msgs = load_results($srch->get_thread($mid, { asc => $flat }));
155 my $nr = scalar @$msgs;
156 return missing_thread($res, $ctx) if $nr == 0;
162 root_anchor => anchor_for($mid),
167 require PublicInbox::Git;
168 $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir});
170 pre_anchor_entry($seen, $_) for (@$msgs);
171 __thread_entry($state, $_, 0) for (@$msgs);
173 my $th = thread_results($msgs);
174 thread_entry($state, $_, 0) for $th->rootset;
175 if (my $max = $state->{cur_level}) {
177 ('</ul></li>' x ($max - 1)) . '</ul>');
181 # there could be a race due to a message being deleted in git
182 # but still being in the Xapian index:
183 my $fh = delete $state->{fh} or return missing_thread($res, $ctx);
185 my $final_anchor = $state->{anchor_idx};
186 my $next = "<a\nid=s$final_anchor>";
187 $next .= $final_anchor == 1 ? 'only message in' : 'end of';
188 $next .= " thread</a>, back to <a\nhref=\"../../\">index</a>";
189 $next .= "\ndownload thread: ";
190 $next .= "<a\nhref=\"../t.mbox.gz\">mbox.gz</a>";
191 $next .= " / follow: <a\nhref=\"../t.atom\">Atom feed</a>";
192 $fh->write('<hr /><pre>' . $next . "\n\n".
193 $foot . '</pre></body></html>');
198 my ($fh, $upfx, $p) = @_;
199 my $s = add_text_body($upfx, $p);
203 $s .= "\n"; # ensure there's a trailing newline
208 sub multipart_text_as_html {
209 my ($mime, $upfx) = @_;
212 # scan through all parts, looking for displayable text
213 msg_iter($mime, sub {
215 $p = add_text_body($upfx, $p);
217 $rv .= "\n" if $p ne '';
223 my ($s, $l, $quot) = @_;
225 # show everything in the full version with anchor from
226 # short version (see above)
227 my $rv = $l->linkify_1(join('', @$quot));
230 # we use a <div> here to allow users to specify their own
231 # color for quoted text
232 $rv = $l->linkify_2(ascii_html($rv));
233 $$s .= qq(<span\nclass="q">) . $rv . '</span>'
236 sub attach_link ($$$$) {
237 my ($upfx, $ct, $p, $fn) = @_;
238 my ($part, $depth, @idx) = @$p;
239 my $nl = $idx[-1] > 1 ? "\n" : '';
240 my $idx = join('.', @idx);
241 my $size = bytes::length($part->body);
242 $ct ||= 'text/plain';
243 $ct =~ s/;.*//; # no attributes
244 $ct = ascii_html($ct);
245 my $desc = $part->header('Content-Description');
246 $desc = $fn unless defined $desc;
247 $desc = '' unless defined $desc;
249 if (defined $fn && $fn =~ /\A[[:alnum:]][\w\.-]+[[:alnum:]]\z/) {
251 } elsif ($ct eq 'text/plain') {
256 my @ret = qq($nl<a\nhref="$upfx$idx-$sfn">[-- Attachment #$idx: );
257 my $ts = "Type: $ct, Size: $size bytes";
258 push(@ret, ($desc eq '') ? "$ts --]" : "$desc --]\n[-- $ts --]");
259 join('', @ret, '</a>');
263 my ($upfx, $p) = @_; # from msg_iter: [ Email::MIME, depth, @idx ]
264 my ($part, $depth, @idx) = @$p;
265 my $ct = $part->content_type;
266 my $fn = $part->filename;
268 if (defined $ct && $ct =~ m!\btext/x?html\b!i) {
269 return attach_link($upfx, $ct, $p, $fn);
272 my $s = eval { $part->body_str };
274 # badly-encoded message? tell the world about it!
275 return attach_link($upfx, $ct, $p, $fn) if $@;
277 my @lines = split(/^/m, $s);
279 if (defined($fn) || $depth > 0) {
280 $s .= attach_link($upfx, $ct, $p, $fn);
284 my $l = PublicInbox::Linkify->new;
285 while (defined(my $cur = shift @lines)) {
287 # show the previously buffered quote inline
288 flush_quote(\$s, $l, \@quot) if @quot;
291 $cur = $l->linkify_1($cur);
292 $cur = ascii_html($cur);
293 $s .= $l->linkify_2($cur);
299 flush_quote(\$s, $l, \@quot) if @quot;
300 $s =~ s/[ \t]+$//sgm; # kill per-line trailing whitespace
301 $s =~ s/\A\n+//s; # kill leading blank lines
302 $s =~ s/\s+\z//s; # kill all trailing spaces (final "\n" added if ne '')
306 sub headers_to_html_header {
307 my ($hdr, $ctx) = @_;
308 my $srch = $ctx->{srch} if $ctx;
314 $atom = qq{<link\nrel=alternate\ntitle="Atom feed"\n} .
315 qq!href="${upfx}t.atom"\ntype="application/atom+xml"/>!;
319 my $mid = $hdr->header_raw('Message-ID');
320 $mid = PublicInbox::Hval->new_msgid($mid);
321 foreach my $h (qw(From To Cc Subject Date)) {
322 my $v = $hdr->header($h);
323 defined($v) && ($v ne '') or next;
324 $v = PublicInbox::Hval->new($v);
327 $title[1] = PublicInbox::Address::from_name($v->raw);
328 } elsif ($h eq 'Subject') {
329 $title[0] = $v->as_html;
331 $rv .= qq($h: <a\nhref="#r"\nid=t>);
332 $rv .= $v->as_html . "</a>\n";
336 $rv .= "$h: " . $v->as_html . "\n";
339 $rv .= 'Message-ID: <' . $mid->as_html . '> ';
340 $rv .= "(<a\nhref=\"${upfx}raw\">raw</a>)\n";
341 $rv .= _parent_headers($hdr, $srch);
344 ("<html><head><title>". join(' - ', @title) . "</title>$atom".
345 PublicInbox::Hval::STYLE .
346 "</head><body><pre\nid=b>" . # anchor for body start
351 my ($dst, $ctx, $hdr, $tpfx) = @_;
352 my $srch = $ctx->{srch};
353 my $mid = mid_clean($hdr->header_raw('Message-ID'));
354 my $sres = $srch->get_thread($mid);
355 my $nr = $sres->{total};
356 my $expand = qq(<a\nhref="${tpfx}t/#u">expand</a> ) .
357 qq(/ <a\nhref="${tpfx}t.mbox.gz">mbox.gz</a> ) .
358 qq(/ <a\nhref="${tpfx}t.atom">Atom feed</a>);
360 my $parent = in_reply_to($hdr);
362 if (defined $parent) {
363 $$dst .= "($expand)\n ";
364 $$dst .= ghost_parent("$tpfx../", $parent) . "\n";
366 $$dst .= "[no followups, yet] ($expand)\n";
368 $ctx->{next_msg} = undef;
369 $ctx->{parent_msg} = $parent;
373 $$dst .= "$nr+ messages in thread ($expand";
374 $$dst .= qq! / <a\nhref="#b">[top]</a>)\n!;
376 my $subj = $srch->subject_path($hdr->header('Subject'));
378 seen => { $subj => 1 },
384 for (thread_results(load_results($sres))->rootset) {
385 skel_dump($dst, $state, $tpfx, $_, 0);
387 $ctx->{next_msg} = $state->{next_msg};
388 $ctx->{parent_msg} = $parent;
391 sub _parent_headers {
392 my ($hdr, $srch) = @_;
395 my $irt = in_reply_to($hdr);
397 my $v = PublicInbox::Hval->new_msgid($irt, 1);
398 my $html = $v->as_html;
399 my $href = $v->as_href;
400 $rv .= "In-Reply-To: <";
401 $rv .= "<a\nhref=\"../$href/\">$html</a>>\n";
404 # do not display References: if search is present,
405 # we show the thread skeleton at the bottom, instead.
408 my $refs = $hdr->header_raw('References');
410 # avoid redundant URLs wasting bandwidth
412 $seen{$irt} = 1 if defined $irt;
414 my @raw_refs = ($refs =~ /<([^>]+)>/g);
415 foreach my $ref (@raw_refs) {
418 push @refs, linkify_ref_nosrch($ref);
422 $rv .= 'References: '. join(' ', @refs) . "\n";
428 sub mailto_arg_link {
430 my %cc; # everyone else
431 my $to; # this is the From address
433 foreach my $h (qw(From To Cc)) {
434 my $v = $hdr->header($h);
435 defined($v) && ($v ne '') or next;
436 my @addrs = PublicInbox::Address::emails($v);
437 foreach my $address (@addrs) {
438 my $dst = lc($address);
439 $cc{$dst} ||= $address;
445 my $subj = $hdr->header('Subject') || '';
446 $subj = "Re: $subj" unless $subj =~ /\bRe:/i;
447 my $mid = $hdr->header_raw('Message-ID');
448 push @arg, "--in-reply-to='" . ascii_html($mid) . "'";
449 my $irt = uri_escape_utf8($mid);
451 push @arg, '--to=' . ascii_html($to);
452 $to = uri_escape_utf8($to);
453 $subj = uri_escape_utf8($subj);
454 my $cc = join(',', sort values %cc);
455 push @arg, '--cc=' . ascii_html($cc);
456 $cc = uri_escape_utf8($cc);
457 my $href = "mailto:$to?In-Reply-To=$irt&Cc=${cc}&Subject=$subj";
464 my ($hdr, $standalone, $ctx, $rhref) = @_;
466 my $srch = $ctx->{srch} if $ctx;
469 my $idx = $standalone ? " <a\nhref=\"$upfx\">index</a>" : '';
473 thread_skel(\$idx, $ctx, $hdr, $tpfx);
474 my $p = $ctx->{parent_msg};
475 my $next = $ctx->{next_msg};
477 $p = PublicInbox::Hval->new_msgid($p);
479 $irt = "<a\nhref=\"$upfx$p/\"rel=prev>parent</a> ";
481 $irt = ' ' x length('parent ');
484 my $n = PublicInbox::Hval->new_msgid($next)->as_href;
485 $irt .= "<a\nhref=\"$upfx$n/\"\nrel=next>next</a> ";
487 $irt .= ' ' x length('next ');
493 $irt .= qq(<a\nhref="$rhref">reply</a>);
497 sub linkify_ref_nosrch {
498 my $v = PublicInbox::Hval->new_msgid($_[0], 1);
499 my $html = $v->as_html;
500 my $href = $v->as_href;
501 "<<a\nhref=\"../$href/\">$html</a>>";
507 if ($id !~ /\A[a-f0-9]{40}\z/) {
508 $id = id_compress(mid_clean($id), 1);
513 sub thread_html_head {
514 my ($hdr, $state) = @_;
515 my $res = delete $state->{res} or die "BUG: no Plack callback in {res}";
516 my $fh = $res->([200, ['Content-Type'=> 'text/html; charset=UTF-8']]);
519 my $s = ascii_html($hdr->header('Subject'));
520 $fh->write("<html><head><title>$s</title>".
521 qq{<link\nrel=alternate\ntitle="Atom feed"\n} .
522 qq!href="../t.atom"\ntype="application/atom+xml"/>! .
523 PublicInbox::Hval::STYLE .
527 sub pre_anchor_entry {
528 my ($seen, $mime) = @_;
529 my $id = anchor_for(mid_mime($mime));
530 $seen->{$id} = "#$id"; # save the anchor for children, later
534 my ($upfx, $mid) = @_;
535 # 'subject dummy' is used internally by Mail::Thread
536 return '[no common parent]' if ($mid eq 'subject dummy');
538 $mid = PublicInbox::Hval->new_msgid($mid);
539 my $href = $mid->as_href;
540 my $html = $mid->as_html;
541 qq{[parent not found: <<a\nhref="$upfx$href/">$html</a>>]};
544 sub thread_adj_level {
545 my ($state, $level) = @_;
547 my $max = $state->{cur_level};
549 return '' if $max == 0; # flat output
551 # reset existing lists
552 my $x = $max > 1 ? ('</ul></li>' x ($max - 1)) : '';
553 $state->{fh}->write($x . '</ul>');
554 $state->{cur_level} = 0;
557 if ($level == $max) { # continue existing list
558 $state->{fh}->write('<li>');
559 } elsif ($level < $max) {
560 my $x = $max > 1 ? ('</ul></li>' x ($max - $level)) : '';
561 $state->{fh}->write($x .= '<li>');
562 $state->{cur_level} = $level;
563 } else { # ($level > $max) # start a new level
564 $state->{cur_level} = $level;
565 $state->{fh}->write(($max ? '<li>' : '') . '<ul><li>');
571 my ($state, $upfx, $mid, $level) = @_;
572 my $end = '<pre>'. ghost_parent($upfx, $mid) . '</pre>';
573 $state->{fh}->write($end .= thread_adj_level($state, $level));
577 my ($state, $mime, $level) = @_;
579 # lazy load the full message from mini_mime:
581 my $path = mid2path(mid_clean(mid_mime($mime)));
582 Email::MIME->new($state->{ctx}->{git}->cat_file('HEAD:'.$path));
585 thread_html_head($mime, $state) if $state->{anchor_idx} == 0;
586 if (my $ghost = delete $state->{ghost}) {
587 # n.b. ghost messages may only be parents, not children
588 foreach my $g (@$ghost) {
589 ghost_flush($state, '../../', @$g);
592 my $end = thread_adj_level($state, $level);
593 index_entry($mime, $level, $state);
594 $state->{fh}->write($end) if $end;
601 INDENT x ($level - 1);
604 sub __ghost_prepare {
605 my ($state, $node, $level) = @_;
606 my $ghost = $state->{ghost} ||= [];
607 push @$ghost, [ $node->messageid, $level ];
611 my ($state, $node, $level) = @_;
613 if (my $mime = $node->message) {
614 unless (__thread_entry($state, $mime, $level)) {
615 __ghost_prepare($state, $node, $level);
618 __ghost_prepare($state, $node, $level);
621 thread_entry($state, $node->child, $level + 1);
622 thread_entry($state, $node->next, $level);
628 [ map { $_->mini_mime } @{delete $sres->{msgs}} ];
633 my $ts = eval { str2time($hdr->header('Date')) };
634 defined($ts) ? $ts : 0;
639 require PublicInbox::Thread;
640 my $th = PublicInbox::Thread->new(@$msgs);
642 $th->order(*sort_ts);
647 my ($res, $ctx) = @_;
648 require PublicInbox::ExtMsg;
650 $res->(PublicInbox::ExtMsg::ext_msg($ctx))
655 my $ts = $hdr->header('X-PI-TS') || msg_timestamp($hdr);
659 sub fmt_ts { POSIX::strftime('%Y-%m-%d %k:%M', gmtime($_[0])) }
662 my ($dst, $state, $upfx, $hdr, $level) = @_;
664 my $cur = $state->{cur};
665 my $mid = mid_clean($hdr->header_raw('Message-ID'));
666 my $f = ascii_html($hdr->header('X-PI-From'));
667 my $d = _msg_date($hdr);
668 my $pfx = "$d " . indent_for($level) . th_pfx($level);
670 $state->{first_level} ||= $level;
672 if ($attr ne $state->{prev_attr} || $state->{prev_level} > $level) {
673 $state->{prev_attr} = $attr;
677 $state->{prev_level} = $level;
681 delete $state->{cur};
682 $$dst .= "$pfx<b><a\nid=r\nhref=\"#t\">".
683 "$attr [this message]</a></b>\n";
688 $state->{next_msg} ||= $mid;
691 # Subject is never undef, this mail was loaded from
692 # our Xapian which would've resulted in '' if it were
693 # really missing (and Filter rejects empty subjects)
694 my $s = $hdr->header('Subject');
695 my $h = $state->{srch}->subject_path($s);
696 if ($state->{seen}->{$h}) {
699 $state->{seen}->{$h} = 1;
700 $s = PublicInbox::Hval->new($s);
703 my $m = PublicInbox::Hval->new_msgid($mid);
704 $m = $upfx . '../' . $m->as_href . '/';
705 $$dst .= "$pfx<a\nhref=\"$m\">";
706 $$dst .= defined($s) ? "$s</a> $f\n" : "$f</a>\n";
710 my ($dst, $state, $upfx, $node, $level) = @_;
712 if (my $mime = $node->message) {
713 my $hdr = $mime->header_obj;
714 my $mid = mid_clean($hdr->header_raw('Message-ID'));
715 _skel_header($dst, $state, $upfx, $hdr, $level);
717 my $mid = $node->messageid;
718 if ($mid eq 'subject dummy') {
719 $$dst .= "\t[no common parent]\n";
721 $$dst .= ' [not found] ';
722 $$dst .= indent_for($level) . th_pfx($level);
723 $mid = PublicInbox::Hval->new_msgid($mid);
724 my $href = "$upfx../" . $mid->as_href . '/';
725 my $html = $mid->as_html;
726 $$dst .= qq{<<a\nhref="$href">$html</a>>\n};
729 skel_dump($dst, $state, $upfx, $node->child, $level+1);
730 skel_dump($dst, $state, $upfx, $node->next, $level);
735 (eval { $a->topmost->message->header('X-PI-TS') } || 0) <=>
736 (eval { $b->topmost->message->header('X-PI-TS') } || 0)
740 # accumulate recent topics if search is supported
741 # returns 1 if done, undef if not
743 my ($state, $node, $level) = @_;
745 my $child_adjust = 1;
747 if (my $x = $node->message) {
751 $subj = $x->header('Subject');
752 $subj = $state->{srch}->subject_normalized($subj);
754 if (++$state->{subjs}->{$subj} == 1) {
755 push @{$state->{order}}, [ $level, $subj ];
758 my $mid = mid_clean($x->header_raw('Message-ID'));
760 my $ts = $x->header('X-PI-TS');
761 my $exist = $state->{latest}->{$subj};
762 if (!$exist || $exist->[1] < $ts) {
763 $state->{latest}->{$subj} = [ $mid, $ts ];
766 # ghost message, do not bump level
770 add_topic($state, $node->child, $level + $child_adjust);
771 add_topic($state, $node->next, $level);
776 my $order = $state->{order};
777 my $subjs = $state->{subjs};
778 my $latest = $state->{latest};
779 my $fh = $state->{fh};
780 return $fh->write("\n[No topics in range]</pre>") unless scalar @$order;
786 while (defined(my $info = shift @$order)) {
787 my ($level, $subj) = @$info;
788 my $n = delete $subjs->{$subj};
789 my ($mid, $ts) = @{delete $latest->{$subj}};
790 $mid = PublicInbox::Hval->new_msgid($mid)->as_href;
791 $subj = PublicInbox::Hval->new($subj)->as_html;
792 $pfx = indent_for($level);
793 my $nl = $level == $prev ? "\n" : '';
798 $cur ||= [ $ts, '' ];
799 $cur->[0] = $ts if $ts > $cur->[0];
800 $cur->[1] .= $nl . $pfx . th_pfx($level) .
801 "<a\nhref=\"$mid/t/#u\"><b>" .
802 $subj . "</b></a>\n";
805 my $attr = " $ts UTC";
807 # $n isn't the total number of posts on the topic,
808 # just the number of posts in the current results window
809 $n = $n == 1 ? '' : " ($n+ messages)";
811 if ($level == 0 || $attr ne $prev_attr) {
812 my $mbox = qq(<a\nhref="$mid/t.mbox.gz">mbox.gz</a>);
813 my $atom = qq(<a\nhref="$mid/t.atom">Atom</a>);
814 $pfx .= INDENT if $level > 0;
815 $cur->[1] .= $pfx . $attr . $n . " - $mbox / $atom\n";
819 push @recent, $cur if $cur;
820 @recent = map { $_->[1] } sort { $b->[0] <=> $a->[0] } @recent;
821 $fh->write(join('', @recent) . '</pre>');
824 sub emit_index_topics {
826 my ($off) = (($state->{ctx}->{cgi}->param('o') || '0') =~ /(\d+)/);
827 $state->{order} = [];
828 $state->{subjs} = {};
829 $state->{latest} = {};
831 my %opts = ( offset => $off, limit => $max * 4 );
832 while (scalar @{$state->{order}} < $max) {
833 my $sres = $state->{srch}->query('', \%opts);
834 my $nr = scalar @{$sres->{msgs}} or last;
836 for (thread_results(load_results($sres))->rootset) {
837 add_topic($state, $_, 0);
839 $opts{offset} += $nr;