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) }
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 @q = map { (0, $_) } thread_results($msgs)->rootset;
182 my $level = shift @q;
183 my $node = shift @q or next;
184 thread_entry($state, $level, $node);
185 unshift @q, $level+1, $node->child, $level, $node->next;
187 if (my $max = $state->{cur_level}) {
189 ('</ul></li>' x ($max - 1)) . '</ul>');
193 # there could be a race due to a message being deleted in git
194 # but still being in the Xapian index:
195 my $fh = delete $state->{fh} or return missing_thread($res, $ctx);
197 my $final_anchor = $state->{anchor_idx};
198 my $next = "<a\nid=s$final_anchor>";
199 $next .= $final_anchor == 1 ? 'only message in' : 'end of';
200 $next .= " thread</a>, back to <a\nhref=\"../../\">index</a>";
201 $next .= "\ndownload thread: ";
202 $next .= "<a\nhref=\"../t.mbox.gz\">mbox.gz</a>";
203 $next .= " / follow: <a\nhref=\"../t.atom\">Atom feed</a>";
204 $fh->write('<hr /><pre>' . $next . "\n\n".
205 $foot . '</pre></body></html>');
210 my ($fh, $upfx, $p) = @_;
211 my $s = add_text_body($upfx, $p);
218 sub multipart_text_as_html {
219 my ($mime, $upfx) = @_;
222 # scan through all parts, looking for displayable text
223 msg_iter($mime, sub {
225 $rv .= add_text_body($upfx, $p);
231 my ($s, $l, $quot) = @_;
233 # show everything in the full version with anchor from
234 # short version (see above)
235 my $rv = $l->linkify_1(join('', @$quot));
238 # we use a <span> here to allow users to specify their own
239 # color for quoted text
240 $rv = $l->linkify_2(ascii_html($rv));
241 $$s .= qq(<span\nclass="q">) . $rv . '</span>'
244 sub attach_link ($$$$) {
245 my ($upfx, $ct, $p, $fn) = @_;
246 my ($part, $depth, @idx) = @$p;
247 my $nl = $idx[-1] > 1 ? "\n" : '';
248 my $idx = join('.', @idx);
249 my $size = bytes::length($part->body);
250 $ct ||= 'text/plain';
251 $ct =~ s/;.*//; # no attributes
252 $ct = ascii_html($ct);
253 my $desc = $part->header('Content-Description');
254 $desc = $fn unless defined $desc;
255 $desc = '' unless defined $desc;
257 if (defined $fn && $fn =~ /\A[[:alnum:]][\w\.-]+[[:alnum:]]\z/) {
259 } elsif ($ct eq 'text/plain') {
264 my @ret = qq($nl<a\nhref="$upfx$idx-$sfn">[-- Attachment #$idx: );
265 my $ts = "Type: $ct, Size: $size bytes";
266 push(@ret, ($desc eq '') ? "$ts --]" : "$desc --]\n[-- $ts --]");
267 join('', @ret, "</a>\n");
271 my ($upfx, $p) = @_; # from msg_iter: [ Email::MIME, depth, @idx ]
272 my ($part, $depth, @idx) = @$p;
273 my $ct = $part->content_type;
274 my $fn = $part->filename;
276 if (defined $ct && $ct =~ m!\btext/x?html\b!i) {
277 return attach_link($upfx, $ct, $p, $fn);
280 my $s = eval { $part->body_str };
282 # badly-encoded message? tell the world about it!
283 return attach_link($upfx, $ct, $p, $fn) if $@;
285 my @lines = split(/^/m, $s);
287 if (defined($fn) || $depth > 0) {
288 $s .= attach_link($upfx, $ct, $p, $fn);
292 my $l = PublicInbox::Linkify->new;
293 while (defined(my $cur = shift @lines)) {
295 # show the previously buffered quote inline
296 flush_quote(\$s, $l, \@quot) if @quot;
299 $cur = $l->linkify_1($cur);
300 $cur = ascii_html($cur);
301 $s .= $l->linkify_2($cur);
310 flush_quote(\$s, $l, \@quot);
312 $s =~ s/[ \t]+$//sgm; # kill per-line trailing whitespace
313 $s =~ s/\A\n+//s; # kill leading blank lines
314 $s =~ s/\s+\z//s; # kill all trailing spaces
318 sub _msg_html_prepare {
319 my ($hdr, $ctx) = @_;
320 my $srch = $ctx->{srch} if $ctx;
322 my $rv = "<pre\nid=b>"; # anchor for body start
325 $ctx->{-upfx} = '../';
328 my $mid = $hdr->header_raw('Message-ID');
329 $mid = PublicInbox::Hval->new_msgid($mid);
330 foreach my $h (qw(From To Cc Subject Date)) {
331 my $v = $hdr->header($h);
332 defined($v) && ($v ne '') or next;
333 $v = PublicInbox::Hval->new($v);
336 my $n = PublicInbox::Address::from_name($v->raw);
337 $title[1] = ascii_html($n);
338 } elsif ($h eq 'Subject') {
339 $title[0] = $v->as_html;
341 $rv .= qq($h: <a\nhref="#r"\nid=t>);
342 $rv .= $v->as_html . "</a>\n";
347 $v =~ s/(\@[^,]+,) /$1\n\t/g if ($h eq 'Cc' || $h eq 'To');
351 $ctx->{-title_html} = join(' - ', @title);
352 $rv .= 'Message-ID: <' . $mid->as_html . '> ';
353 $rv .= "(<a\nhref=\"raw\">raw</a>)\n";
354 $rv .= _parent_headers($hdr, $srch);
359 my ($dst, $ctx, $hdr, $tpfx) = @_;
360 my $srch = $ctx->{srch};
361 my $mid = mid_clean($hdr->header_raw('Message-ID'));
362 my $sres = $srch->get_thread($mid);
363 my $nr = $sres->{total};
364 my $expand = qq(<a\nhref="${tpfx}t/#u">expand</a> ) .
365 qq(/ <a\nhref="${tpfx}t.mbox.gz">mbox.gz</a> ) .
366 qq(/ <a\nhref="${tpfx}t.atom">Atom feed</a>);
368 my $parent = in_reply_to($hdr);
370 if (defined $parent) {
371 $$dst .= "($expand)\n ";
372 $$dst .= ghost_parent("$tpfx../", $parent) . "\n";
374 $$dst .= "[no followups, yet] ($expand)\n";
376 $ctx->{next_msg} = undef;
377 $ctx->{parent_msg} = $parent;
381 $$dst .= "$nr+ messages in thread ($expand";
382 $$dst .= qq! / <a\nhref="#b">[top]</a>)\n!;
384 my $subj = $srch->subject_path($hdr->header('Subject'));
386 seen => { $subj => 1 },
394 my @q = map { (0, $_) } thread_results(load_results($sres))->rootset;
396 my $level = shift @q;
397 my $node = shift @q or next;
398 skel_dump($state, $level, $node);
399 unshift @q, $level+1, $node->child, $level, $node->next;
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, $node) = @_;
752 my $mid = $node->messageid;
753 my $smsg = $srch->lookup_mail($mid) or return;
757 # accumulate recent topics if search is supported
758 # returns 1 if done, undef if not
760 my ($state, $node, $level) = @_;
762 my $child_adjust = 1;
763 my $srch = $state->{srch};
764 my $x = $node->message || _tryload_ghost($srch, $node);
769 $subj = $x->header('Subject');
770 $subj = $srch->subject_normalized($subj);
772 if (++$state->{subjs}->{$subj} == 1) {
773 push @{$state->{order}}, [ $level, $subj ];
776 my $mid = mid_clean($x->header_raw('Message-ID'));
778 my $ts = $x->header('X-PI-TS');
779 my $exist = $state->{latest}->{$subj};
780 if (!$exist || $exist->[1] < $ts) {
781 $state->{latest}->{$subj} = [ $mid, $ts ];
784 # ghost message, do not bump level
788 add_topic($state, $node->child, $level + $child_adjust);
789 add_topic($state, $node->next, $level);
794 my $order = $state->{order};
795 my $subjs = $state->{subjs};
796 my $latest = $state->{latest};
797 my $fh = $state->{fh};
798 return $fh->write("\n[No topics in range]</pre>") unless scalar @$order;
804 while (defined(my $info = shift @$order)) {
805 my ($level, $subj) = @$info;
806 my $n = delete $subjs->{$subj};
807 my ($mid, $ts) = @{delete $latest->{$subj}};
808 $mid = PublicInbox::Hval->new_msgid($mid)->as_href;
809 $subj = PublicInbox::Hval->new($subj)->as_html;
810 $pfx = indent_for($level);
811 my $nl = $level == $prev ? "\n" : '';
816 $cur ||= [ $ts, '' ];
817 $cur->[0] = $ts if $ts > $cur->[0];
818 $cur->[1] .= $nl . $pfx . th_pfx($level) .
819 "<a\nhref=\"$mid/t/#u\"><b>" .
820 $subj . "</b></a>\n";
823 my $attr = " $ts UTC";
825 # $n isn't the total number of posts on the topic,
826 # just the number of posts in the current results window
827 $n = $n == 1 ? '' : " ($n+ messages)";
829 if ($level == 0 || $attr ne $prev_attr) {
830 my $mbox = qq(<a\nhref="$mid/t.mbox.gz">mbox.gz</a>);
831 my $atom = qq(<a\nhref="$mid/t.atom">Atom</a>);
832 $pfx .= INDENT if $level > 0;
833 $cur->[1] .= $pfx . $attr . $n . " - $mbox / $atom\n";
837 push @recent, $cur if $cur;
838 @recent = map { $_->[1] } sort { $b->[0] <=> $a->[0] } @recent;
839 $fh->write(join('', @recent) . '</pre>');
842 sub emit_index_topics {
844 my ($off) = (($state->{ctx}->{cgi}->param('o') || '0') =~ /(\d+)/);
845 $state->{order} = [];
846 $state->{subjs} = {};
847 $state->{latest} = {};
849 my %opts = ( offset => $off, limit => $max * 4 );
850 while (scalar @{$state->{order}} < $max) {
851 my $sres = $state->{srch}->query('', \%opts);
852 my $nr = scalar @{$sres->{msgs}} or last;
854 for (thread_results(load_results($sres))->rootset) {
855 add_topic($state, $_, 0);
857 $opts{offset} += $nr;