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 my $n = PublicInbox::Address::from_name($v->raw);
328 $title[1] = ascii_html($n);
329 } elsif ($h eq 'Subject') {
330 $title[0] = $v->as_html;
332 $rv .= qq($h: <a\nhref="#r"\nid=t>);
333 $rv .= $v->as_html . "</a>\n";
337 $rv .= "$h: " . $v->as_html . "\n";
340 $rv .= 'Message-ID: <' . $mid->as_html . '> ';
341 $rv .= "(<a\nhref=\"${upfx}raw\">raw</a>)\n";
342 $rv .= _parent_headers($hdr, $srch);
345 ("<html><head><title>". join(' - ', @title) . "</title>$atom".
346 PublicInbox::Hval::STYLE .
347 "</head><body><pre\nid=b>" . # anchor for body start
352 my ($dst, $ctx, $hdr, $tpfx) = @_;
353 my $srch = $ctx->{srch};
354 my $mid = mid_clean($hdr->header_raw('Message-ID'));
355 my $sres = $srch->get_thread($mid);
356 my $nr = $sres->{total};
357 my $expand = qq(<a\nhref="${tpfx}t/#u">expand</a> ) .
358 qq(/ <a\nhref="${tpfx}t.mbox.gz">mbox.gz</a> ) .
359 qq(/ <a\nhref="${tpfx}t.atom">Atom feed</a>);
361 my $parent = in_reply_to($hdr);
363 if (defined $parent) {
364 $$dst .= "($expand)\n ";
365 $$dst .= ghost_parent("$tpfx../", $parent) . "\n";
367 $$dst .= "[no followups, yet] ($expand)\n";
369 $ctx->{next_msg} = undef;
370 $ctx->{parent_msg} = $parent;
374 $$dst .= "$nr+ messages in thread ($expand";
375 $$dst .= qq! / <a\nhref="#b">[top]</a>)\n!;
377 my $subj = $srch->subject_path($hdr->header('Subject'));
379 seen => { $subj => 1 },
385 for (thread_results(load_results($sres))->rootset) {
386 skel_dump($dst, $state, $tpfx, $_, 0);
388 $ctx->{next_msg} = $state->{next_msg};
389 $ctx->{parent_msg} = $parent;
392 sub _parent_headers {
393 my ($hdr, $srch) = @_;
396 my $irt = in_reply_to($hdr);
398 my $v = PublicInbox::Hval->new_msgid($irt, 1);
399 my $html = $v->as_html;
400 my $href = $v->as_href;
401 $rv .= "In-Reply-To: <";
402 $rv .= "<a\nhref=\"../$href/\">$html</a>>\n";
405 # do not display References: if search is present,
406 # we show the thread skeleton at the bottom, instead.
409 my $refs = $hdr->header_raw('References');
411 # avoid redundant URLs wasting bandwidth
413 $seen{$irt} = 1 if defined $irt;
415 my @raw_refs = ($refs =~ /<([^>]+)>/g);
416 foreach my $ref (@raw_refs) {
419 push @refs, linkify_ref_nosrch($ref);
423 $rv .= 'References: '. join(' ', @refs) . "\n";
429 sub mailto_arg_link {
431 my %cc; # everyone else
432 my $to; # this is the From address
434 foreach my $h (qw(From To Cc)) {
435 my $v = $hdr->header($h);
436 defined($v) && ($v ne '') or next;
437 my @addrs = PublicInbox::Address::emails($v);
438 foreach my $address (@addrs) {
439 my $dst = lc($address);
440 $cc{$dst} ||= $address;
446 my $subj = $hdr->header('Subject') || '';
447 $subj = "Re: $subj" unless $subj =~ /\bRe:/i;
448 my $mid = $hdr->header_raw('Message-ID');
449 push @arg, "--in-reply-to='" . ascii_html($mid) . "'";
450 my $irt = uri_escape_utf8($mid);
452 push @arg, '--to=' . ascii_html($to);
453 $to = uri_escape_utf8($to);
454 $subj = uri_escape_utf8($subj);
455 my $cc = join(',', sort values %cc);
456 push @arg, '--cc=' . ascii_html($cc);
457 $cc = uri_escape_utf8($cc);
458 my $href = "mailto:$to?In-Reply-To=$irt&Cc=${cc}&Subject=$subj";
465 my ($hdr, $standalone, $ctx, $rhref) = @_;
467 my $srch = $ctx->{srch} if $ctx;
470 my $idx = $standalone ? " <a\nhref=\"$upfx\">index</a>" : '';
474 thread_skel(\$idx, $ctx, $hdr, $tpfx);
475 my $p = $ctx->{parent_msg};
476 my $next = $ctx->{next_msg};
478 $p = PublicInbox::Hval->new_msgid($p);
480 $irt = "<a\nhref=\"$upfx$p/\"rel=prev>parent</a> ";
482 $irt = ' ' x length('parent ');
485 my $n = PublicInbox::Hval->new_msgid($next)->as_href;
486 $irt .= "<a\nhref=\"$upfx$n/\"\nrel=next>next</a> ";
488 $irt .= ' ' x length('next ');
494 $irt .= qq(<a\nhref="$rhref">reply</a>);
498 sub linkify_ref_nosrch {
499 my $v = PublicInbox::Hval->new_msgid($_[0], 1);
500 my $html = $v->as_html;
501 my $href = $v->as_href;
502 "<<a\nhref=\"../$href/\">$html</a>>";
508 if ($id !~ /\A[a-f0-9]{40}\z/) {
509 $id = id_compress(mid_clean($id), 1);
514 sub thread_html_head {
515 my ($hdr, $state) = @_;
516 my $res = delete $state->{res} or die "BUG: no Plack callback in {res}";
517 my $fh = $res->([200, ['Content-Type'=> 'text/html; charset=UTF-8']]);
520 my $s = ascii_html($hdr->header('Subject'));
521 $fh->write("<html><head><title>$s</title>".
522 qq{<link\nrel=alternate\ntitle="Atom feed"\n} .
523 qq!href="../t.atom"\ntype="application/atom+xml"/>! .
524 PublicInbox::Hval::STYLE .
528 sub pre_anchor_entry {
529 my ($seen, $mime) = @_;
530 my $id = anchor_for(mid_mime($mime));
531 $seen->{$id} = "#$id"; # save the anchor for children, later
535 my ($upfx, $mid) = @_;
536 # 'subject dummy' is used internally by Mail::Thread
537 return '[no common parent]' if ($mid eq 'subject dummy');
539 $mid = PublicInbox::Hval->new_msgid($mid);
540 my $href = $mid->as_href;
541 my $html = $mid->as_html;
542 qq{[parent not found: <<a\nhref="$upfx$href/">$html</a>>]};
545 sub thread_adj_level {
546 my ($state, $level) = @_;
548 my $max = $state->{cur_level};
550 return '' if $max == 0; # flat output
552 # reset existing lists
553 my $x = $max > 1 ? ('</ul></li>' x ($max - 1)) : '';
554 $state->{fh}->write($x . '</ul>');
555 $state->{cur_level} = 0;
558 if ($level == $max) { # continue existing list
559 $state->{fh}->write('<li>');
560 } elsif ($level < $max) {
561 my $x = $max > 1 ? ('</ul></li>' x ($max - $level)) : '';
562 $state->{fh}->write($x .= '<li>');
563 $state->{cur_level} = $level;
564 } else { # ($level > $max) # start a new level
565 $state->{cur_level} = $level;
566 $state->{fh}->write(($max ? '<li>' : '') . '<ul><li>');
572 my ($state, $upfx, $mid, $level) = @_;
573 my $end = '<pre>'. ghost_parent($upfx, $mid) . '</pre>';
574 $state->{fh}->write($end .= thread_adj_level($state, $level));
578 my ($state, $mime, $level) = @_;
580 # lazy load the full message from mini_mime:
582 my $path = mid2path(mid_clean(mid_mime($mime)));
583 Email::MIME->new($state->{ctx}->{git}->cat_file('HEAD:'.$path));
586 thread_html_head($mime, $state) if $state->{anchor_idx} == 0;
587 if (my $ghost = delete $state->{ghost}) {
588 # n.b. ghost messages may only be parents, not children
589 foreach my $g (@$ghost) {
590 ghost_flush($state, '../../', @$g);
593 my $end = thread_adj_level($state, $level);
594 index_entry($mime, $level, $state);
595 $state->{fh}->write($end) if $end;
602 INDENT x ($level - 1);
605 sub __ghost_prepare {
606 my ($state, $node, $level) = @_;
607 my $ghost = $state->{ghost} ||= [];
608 push @$ghost, [ $node->messageid, $level ];
612 my ($state, $node, $level) = @_;
614 if (my $mime = $node->message) {
615 unless (__thread_entry($state, $mime, $level)) {
616 __ghost_prepare($state, $node, $level);
619 __ghost_prepare($state, $node, $level);
622 thread_entry($state, $node->child, $level + 1);
623 thread_entry($state, $node->next, $level);
629 [ map { $_->mini_mime } @{delete $sres->{msgs}} ];
634 my $ts = eval { str2time($hdr->header('Date')) };
635 defined($ts) ? $ts : 0;
640 require PublicInbox::Thread;
641 my $th = PublicInbox::Thread->new(@$msgs);
643 $th->order(*sort_ts);
648 my ($res, $ctx) = @_;
649 require PublicInbox::ExtMsg;
651 $res->(PublicInbox::ExtMsg::ext_msg($ctx))
656 my $ts = $hdr->header('X-PI-TS') || msg_timestamp($hdr);
660 sub fmt_ts { POSIX::strftime('%Y-%m-%d %k:%M', gmtime($_[0])) }
663 my ($dst, $state, $upfx, $hdr, $level) = @_;
665 my $cur = $state->{cur};
666 my $mid = mid_clean($hdr->header_raw('Message-ID'));
667 my $f = ascii_html($hdr->header('X-PI-From'));
668 my $d = _msg_date($hdr);
669 my $pfx = "$d " . indent_for($level) . th_pfx($level);
671 $state->{first_level} ||= $level;
673 if ($attr ne $state->{prev_attr} || $state->{prev_level} > $level) {
674 $state->{prev_attr} = $attr;
678 $state->{prev_level} = $level;
682 delete $state->{cur};
683 $$dst .= "$pfx<b><a\nid=r\nhref=\"#t\">".
684 "$attr [this message]</a></b>\n";
689 $state->{next_msg} ||= $mid;
692 # Subject is never undef, this mail was loaded from
693 # our Xapian which would've resulted in '' if it were
694 # really missing (and Filter rejects empty subjects)
695 my $s = $hdr->header('Subject');
696 my $h = $state->{srch}->subject_path($s);
697 if ($state->{seen}->{$h}) {
700 $state->{seen}->{$h} = 1;
701 $s = PublicInbox::Hval->new($s);
704 my $m = PublicInbox::Hval->new_msgid($mid);
705 $m = $upfx . '../' . $m->as_href . '/';
706 $$dst .= "$pfx<a\nhref=\"$m\">";
707 $$dst .= defined($s) ? "$s</a> $f\n" : "$f</a>\n";
711 my ($dst, $state, $upfx, $node, $level) = @_;
713 if (my $mime = $node->message) {
714 my $hdr = $mime->header_obj;
715 my $mid = mid_clean($hdr->header_raw('Message-ID'));
716 _skel_header($dst, $state, $upfx, $hdr, $level);
718 my $mid = $node->messageid;
719 if ($mid eq 'subject dummy') {
720 $$dst .= "\t[no common parent]\n";
722 $$dst .= ' [not found] ';
723 $$dst .= indent_for($level) . th_pfx($level);
724 $mid = PublicInbox::Hval->new_msgid($mid);
725 my $href = "$upfx../" . $mid->as_href . '/';
726 my $html = $mid->as_html;
727 $$dst .= qq{<<a\nhref="$href">$html</a>>\n};
730 skel_dump($dst, $state, $upfx, $node->child, $level+1);
731 skel_dump($dst, $state, $upfx, $node->next, $level);
736 (eval { $a->topmost->message->header('X-PI-TS') } || 0) <=>
737 (eval { $b->topmost->message->header('X-PI-TS') } || 0)
741 # accumulate recent topics if search is supported
742 # returns 1 if done, undef if not
744 my ($state, $node, $level) = @_;
746 my $child_adjust = 1;
748 if (my $x = $node->message) {
752 $subj = $x->header('Subject');
753 $subj = $state->{srch}->subject_normalized($subj);
755 if (++$state->{subjs}->{$subj} == 1) {
756 push @{$state->{order}}, [ $level, $subj ];
759 my $mid = mid_clean($x->header_raw('Message-ID'));
761 my $ts = $x->header('X-PI-TS');
762 my $exist = $state->{latest}->{$subj};
763 if (!$exist || $exist->[1] < $ts) {
764 $state->{latest}->{$subj} = [ $mid, $ts ];
767 # ghost message, do not bump level
771 add_topic($state, $node->child, $level + $child_adjust);
772 add_topic($state, $node->next, $level);
777 my $order = $state->{order};
778 my $subjs = $state->{subjs};
779 my $latest = $state->{latest};
780 my $fh = $state->{fh};
781 return $fh->write("\n[No topics in range]</pre>") unless scalar @$order;
787 while (defined(my $info = shift @$order)) {
788 my ($level, $subj) = @$info;
789 my $n = delete $subjs->{$subj};
790 my ($mid, $ts) = @{delete $latest->{$subj}};
791 $mid = PublicInbox::Hval->new_msgid($mid)->as_href;
792 $subj = PublicInbox::Hval->new($subj)->as_html;
793 $pfx = indent_for($level);
794 my $nl = $level == $prev ? "\n" : '';
799 $cur ||= [ $ts, '' ];
800 $cur->[0] = $ts if $ts > $cur->[0];
801 $cur->[1] .= $nl . $pfx . th_pfx($level) .
802 "<a\nhref=\"$mid/t/#u\"><b>" .
803 $subj . "</b></a>\n";
806 my $attr = " $ts UTC";
808 # $n isn't the total number of posts on the topic,
809 # just the number of posts in the current results window
810 $n = $n == 1 ? '' : " ($n+ messages)";
812 if ($level == 0 || $attr ne $prev_attr) {
813 my $mbox = qq(<a\nhref="$mid/t.mbox.gz">mbox.gz</a>);
814 my $atom = qq(<a\nhref="$mid/t.atom">Atom</a>);
815 $pfx .= INDENT if $level > 0;
816 $cur->[1] .= $pfx . $attr . $n . " - $mbox / $atom\n";
820 push @recent, $cur if $cur;
821 @recent = map { $_->[1] } sort { $b->[0] <=> $a->[0] } @recent;
822 $fh->write(join('', @recent) . '</pre>');
825 sub emit_index_topics {
827 my ($off) = (($state->{ctx}->{cgi}->param('o') || '0') =~ /(\d+)/);
828 $state->{order} = [];
829 $state->{subjs} = {};
830 $state->{latest} = {};
832 my %opts = ( offset => $off, limit => $max * 4 );
833 while (scalar @{$state->{order}} < $max) {
834 my $sres = $state->{srch}->query('', \%opts);
835 my $nr = scalar @{$sres->{msgs}} or last;
837 for (thread_results(load_results($sres))->rootset) {
838 add_topic($state, $_, 0);
840 $opts{offset} += $nr;