]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/View.pm
rename 'GitCatFile' package to 'Git'
[public-inbox.git] / lib / PublicInbox / View.pm
index ee5ba20e2a91e7b15dfd1ae6e3243fad167ba294..2ca7f95ceb8c77caea34323c749632b724a8e082 100644 (file)
@@ -1,5 +1,8 @@
-# Copyright (C) 2014, Eric Wong <normalperson@yhbt.net> and all contributors
+# Copyright (C) 2014-2015 all contributors <meta@public-inbox.org>
 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
+#
+# Used for displaying the HTML web interface.
+# See Documentation/design_www.txt for this.
 package PublicInbox::View;
 use strict;
 use warnings;
@@ -9,15 +12,15 @@ use Encode qw/find_encoding/;
 use Encode::MIME::Header;
 use Email::MIME::ContentType qw/parse_content_type/;
 use PublicInbox::Hval;
-use PublicInbox::MID qw/mid_clean mid_compress mid2path/;
+use PublicInbox::MID qw/mid_clean id_compress mid2path/;
 use Digest::SHA qw/sha1_hex/;
 my $SALT = rand;
+my $MBOX_TITLE = 'title="download thread as gzipped mbox"';
 require POSIX;
 
 # TODO: make these constants tunable
 use constant MAX_INLINE_QUOTED => 12; # half an 80x24 terminal
 use constant MAX_TRUNC_LEN => 72;
-use constant PRE_WRAP => "<pre\nstyle=\"white-space:pre-wrap\">";
 use constant T_ANCHOR => '#u';
 use constant INDENT => '  ';
 
@@ -35,7 +38,7 @@ sub msg_html {
        }
        headers_to_html_header($mime, $full_pfx, $ctx) .
                multipart_text_as_html($mime, $full_pfx) .
-               '</pre><hr />' . PRE_WRAP .
+               '</pre><hr />' . PublicInbox::Hval::PRE .
                html_footer($mime, 1, $full_pfx, $ctx) .
                $footer .
                '</pre></body></html>';
@@ -44,7 +47,8 @@ sub msg_html {
 sub feed_entry {
        my ($class, $mime, $full_pfx) = @_;
 
-       PRE_WRAP . multipart_text_as_html($mime, $full_pfx) . '</pre>';
+       PublicInbox::Hval::PRE .
+               multipart_text_as_html($mime, $full_pfx) . '</pre>';
 }
 
 sub in_reply_to {
@@ -72,7 +76,7 @@ sub index_entry {
        my $subj = $mime->header('Subject');
        my $header_obj = $mime->header_obj;
 
-       my $mid_raw = $header_obj->header('Message-ID');
+       my $mid_raw = mid_clean($header_obj->header('Message-ID'));
        my $id = anchor_for($mid_raw);
        my $seen = $state->{seen};
        $seen->{$id} = "#$id"; # save the anchor for children, later
@@ -84,8 +88,7 @@ sub index_entry {
 
        $from = PublicInbox::Hval->new_oneline($from)->as_html;
        $subj = PublicInbox::Hval->new_oneline($subj)->as_html;
-       my $more = 'permalink';
-       my $root_anchor = $state->{root_anchor};
+       my $root_anchor = $state->{root_anchor} || '';
        my $path = $root_anchor ? '../../' : '';
        my $href = $mid->as_href;
        my $irt = in_reply_to($header_obj);
@@ -95,7 +98,7 @@ sub index_entry {
                my $t = $ctx->{flat} ? 'T' : 't';
                $subj = "<a\nhref=\"${path}$href/$t/#u\">$subj</a>";
        }
-       if ($root_anchor && $root_anchor eq $id) {
+       if ($root_anchor eq $id) {
                $subj = "<u\nid=\"u\">$subj</u>";
        }
 
@@ -104,9 +107,9 @@ sub index_entry {
        if ($level) {
                $rv .= '<td><pre>' . (INDENT x $level) . '</pre></td>';
        }
-       $rv .= "<td\nid=s$midx>" . PRE_WRAP;
+       $rv .= "<td\nid=s$midx>" . PublicInbox::Hval::PRE;
        $rv .= "<b\nid=\"$id\">$subj</b>\n";
-       $rv .= "- by $from @ $ts UTC - ";
+       $rv .= "- $from @ $ts UTC - ";
        $rv .= "<a\nhref=\"#s$next\">next</a>";
        if ($prev >= 0) {
                $rv .= "/<a\nhref=\"#s$prev\">prev</a>";
@@ -115,9 +118,11 @@ sub index_entry {
 
        my ($fhref, $more_ref);
        my $mhref = "${path}$href/";
+       my $more = 'permalink';
 
-       # show full messages at level == 0 in threaded view
-       if ($level > 0 || ($ctx->{flat} && $root_anchor ne $id)) {
+       # show full message if it's our root message
+       my $neq = $root_anchor ne $id;
+       if ($neq || ($neq && $level != 0 && !$ctx->{flat})) {
                $fhref = "${path}$href/f/";
                $more_ref = \$more;
        }
@@ -139,7 +144,9 @@ sub index_entry {
                }
                $rv .= " <a\nhref=\"$parent_anchor\">parent</a>";
        }
-       if ($srch) {
+       if (my $pct = $state->{pct}) {
+               $rv .= " [$pct->{$mid_raw}%]";
+       } elsif ($srch) {
                if ($ctx->{flat}) {
                        $rv .= " [<a\nhref=\"${path}$href/t/#u\">threaded</a>" .
                                "|<b>flat</b>]";
@@ -176,8 +183,8 @@ sub emit_thread_html {
                anchor_idx => 0,
        };
 
-       require PublicInbox::GitCatFile;
-       my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
+       require PublicInbox::Git;
+       my $git = $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir});
        if ($flat) {
                pre_anchor_entry($seen, $_) for (@$msgs);
                __thread_entry(\$cb, $git, $state, $_, 0) for (@$msgs);
@@ -196,15 +203,11 @@ sub emit_thread_html {
        my $next = "<a\nid=\"s$final_anchor\">";
        $next .= $final_anchor == 1 ? 'only message in' : 'end of';
        $next .= " thread</a>, back to <a\nhref=\"../../\">index</a>";
-       if ($flat) {
-               $next .= " [<a\nhref=\"../t/#u\">threaded</a>|<b>flat</b>]";
-       } else {
-               $next .= " [<b>threaded</b>|<a\nhref=\"../T/#u\">flat</a>]";
-       }
-       $next .= "\ndownload thread: <a\nhref=\"../t.mbox.gz\">mbox.gz</a>";
+       $next .= "\ndownload thread: ";
+       $next .= "<a\n$MBOX_TITLE\nhref=\"../t.mbox.gz\">mbox.gz</a>";
        $next .= " / follow: <a\nhref=\"../t.atom\">Atom feed</a>";
-       $cb->write("<hr />" . PRE_WRAP . $next . "\n\n". $foot .
-                  "</pre></body></html>");
+       $cb->write("<hr />" . PublicInbox::Hval::PRE . $next . "\n\n".
+               $foot .  "</pre></body></html>");
        $cb->close;
 }
 
@@ -213,12 +216,14 @@ sub index_walk {
        my $s = add_text_body($enc, $part, $part_nr, $fhref);
 
        if ($more) {
+               my $m = 0;
                # drop the remainder of git patches, they're usually better
                # to review when the full message is viewed
-               $s =~ s!^---+\n.*\z!!ms and $$more = 'more...';
+               $s =~ s!^---+\n.*\z!!ms and $m = 1;
 
                # Drop signatures
-               $s =~ s/^-- \n.*\z//ms and $$more = 'more...';
+               $s =~ s/^-- \n.*\z//ms and $m = 1;
+               $$more = "<b>More...</b>\n\n$$more" if $m;
        }
 
        # kill any leading or trailing whitespace lines
@@ -256,7 +261,7 @@ sub multipart_text_as_html {
        # scan through all parts, looking for displayable text
        $mime->walk_parts(sub {
                my ($part) = @_;
-               $rv .= add_text_body($enc, $part, \$part_nr, $full_pfx);
+               $rv .= add_text_body($enc, $part, \$part_nr, $full_pfx, 1);
        });
        $mime->body_set('');
        $rv;
@@ -308,7 +313,7 @@ sub linkify_2 {
 }
 
 sub flush_quote {
-       my ($quot, $n, $part_nr, $full_pfx, $final) = @_;
+       my ($quot, $n, $part_nr, $full_pfx, $final, $do_anchor) = @_;
 
        if ($full_pfx) {
                if (!$final && scalar(@$quot) <= MAX_INLINE_QUOTED) {
@@ -342,23 +347,23 @@ sub flush_quote {
        } else {
                # show everything in the full version with anchor from
                # short version (see above)
-               my $nr = ++$$n;
-               my $rv = "";
                my %l;
-               $rv .= join('', map { linkify_1(\%l, $_) } @$quot);
+               my $rv .= join('', map { linkify_1(\%l, $_) } @$quot);
                @$quot = ();
                $rv = ascii_html($rv);
+               return linkify_2(\%l, $rv) unless $do_anchor;
+               my $nr = ++$$n;
                "<a\nid=q${part_nr}_$nr></a>" . linkify_2(\%l, $rv);
        }
 }
 
 sub add_text_body {
-       my ($enc_msg, $part, $part_nr, $full_pfx) = @_;
+       my ($enc_msg, $part, $part_nr, $full_pfx, $do_anchor) = @_;
        return '' if $part->subparts;
 
        my $ct = $part->content_type;
        # account for filter bugs...
-       if (defined $ct && $ct =~ m!\btext/[xh]+tml\b!i) {
+       if (defined $ct && $ct =~ m!\btext/x?html\b!i) {
                $part->body_set('');
                return '';
        }
@@ -383,7 +388,7 @@ sub add_text_body {
                        # show the previously buffered quote inline
                        if (scalar @quot) {
                                $s .= flush_quote(\@quot, \$n, $$part_nr,
-                                                 $full_pfx, 0);
+                                                 $full_pfx, 0, $do_anchor);
                        }
 
                        # regular line, OK
@@ -395,7 +400,10 @@ sub add_text_body {
                        push @quot, $cur;
                }
        }
-       $s .= flush_quote(\@quot, \$n, $$part_nr, $full_pfx, 1) if scalar @quot;
+       if (scalar @quot) {
+               $s .= flush_quote(\@quot, \$n, $$part_nr, $full_pfx, 1,
+                                 $do_anchor);
+       }
        $s .= "\n" unless $s =~ /\n\z/s;
        ++$$part_nr;
        $s;
@@ -409,9 +417,8 @@ sub headers_to_html_header {
        my $header_obj = $mime->header_obj;
        my $mid = $header_obj->header('Message-ID');
        $mid = PublicInbox::Hval->new_msgid($mid);
-       my $mid_href = $mid->as_href;
        foreach my $h (qw(From To Cc Subject Date)) {
-               my $v = $mime->header($h);
+               my $v = $header_obj->header($h);
                defined($v) && ($v ne '') or next;
                $v = PublicInbox::Hval->new_oneline($v);
 
@@ -431,17 +438,26 @@ sub headers_to_html_header {
 
        }
        $rv .= 'Message-ID: &lt;' . $mid->as_html . '&gt; ';
-       my $raw_ref = $full_pfx ? 'raw' : '../raw';
-       $rv .= "(<a\nhref=\"$raw_ref\">raw</a>)\n";
+       my $upfx = $full_pfx ? '' : '../';
+       $rv .= "(<a\nhref=\"${upfx}raw\">raw</a>)\n";
+       my $atom;
        if ($srch) {
-               $rv .= "<a\nhref=\"#r\">References: [see below]</a>\n";
+               if ($header_obj->header('In-Reply-To') ||
+                   $header_obj->header('References')) {
+                       $rv .= "<a\nhref=\"${upfx}t/#u\">" .
+                               "References: [expand]</a>\n";
+               }
+
+               $atom = qq{<link\nrel=alternate\ntitle="Atom feed"\n} .
+                       qq!href="${upfx}t.atom"\ntype="application/atom+xml"/>!;
        } else {
                $rv .= _parent_headers_nosrch($header_obj);
+               $atom = '';
        }
        $rv .= "\n";
 
        ("<html><head><title>".  join(' - ', @title) .
-        '</title></head><body>' . PRE_WRAP . $rv);
+        "</title>$atom</head><body>" . PublicInbox::Hval::PRE . $rv);
 }
 
 sub thread_inline {
@@ -450,15 +466,17 @@ sub thread_inline {
        my $mid = mid_clean($cur->header('Message-ID'));
        my $res = $srch->get_thread($mid);
        my $nr = $res->{total};
+       my $upfx = $full_pfx ? '' : '../';
+       my $expand = "(<a\nhref=\"${upfx}t/#u\">expand</a> " .
+                       "/ <a\nhref=\"${upfx}t.mbox.gz\">mbox.gz</a>)";
 
        if ($nr <= 1) {
-               $$dst .= "\n[no followups, yet]\n";
+               $$dst .= "\n[no followups, yet] $expand\n";
                return (undef, in_reply_to($cur));
        }
-       my $upfx = $full_pfx ? '' : '../';
 
-       $$dst .= "\n\n~$nr messages in thread: ".
-                "(<a\nhref=\"${upfx}t/#u\">expand</a>)\n";
+       $$dst .= "\n\n~$nr messages in thread: $expand\n";
+
        my $subj = $srch->subject_path($cur->header('Subject'));
        my $parent = in_reply_to($cur);
        my $state = {
@@ -467,6 +485,8 @@ sub thread_inline {
                cur => $mid,
                parent_cmp => defined $parent ? $parent : '',
                parent => $parent,
+               prev_attr => '',
+               prev_level => 0,
        };
        for (thread_results(load_results($res))->rootset) {
                inline_dump($dst, $state, $upfx, $_, 0);
@@ -535,10 +555,15 @@ sub html_footer {
 
        my $cc = uri_escape_utf8(join(',', sort values %cc));
        my $href = "mailto:$to?In-Reply-To=$irt&Cc=${cc}&Subject=$subj";
+       $href =~ s/%20/+/g;
 
        my $srch = $ctx->{srch} if $ctx;
        my $upfx = $full_pfx ? '../' : '../../';
        my $idx = $standalone ? " <a\nhref=\"$upfx\">index</a>" : '';
+
+       if ($srch && $standalone) {
+               $idx .= qq{ / follow: <a\nhref="t.atom">Atom feed</a>};
+       }
        if ($idx && $srch) {
                my ($next, $p) = thread_inline(\$idx, $ctx, $mime, $full_pfx);
                if (defined $p) {
@@ -571,18 +596,21 @@ sub anchor_for {
        my ($msgid) = @_;
        my $id = $msgid;
        if ($id !~ /\A[a-f0-9]{40}\z/) {
-               $id = mid_compress(mid_clean($id), 1);
+               $id = id_compress(mid_clean($id), 1);
        }
        'm' . $id;
 }
 
 sub thread_html_head {
-       my ($cb, $mime) = @_;
+       my ($cb, $header, $state) = @_;
        $$cb = $$cb->([200, ['Content-Type'=> 'text/html; charset=UTF-8']]);
 
-       my $s = PublicInbox::Hval->new_oneline($mime->header('Subject'));
+       my $s = PublicInbox::Hval->new_oneline($header->header('Subject'));
        $s = $s->as_html;
-       $$cb->write("<html><head><title>$s</title></head><body>");
+       $$cb->write("<html><head><title>$s</title>".
+               qq{<link\nrel=alternate\ntitle="Atom feed"\n} .
+               qq!href="../t.atom"\ntype="application/atom+xml"/>! .
+               "</head><body>");
 }
 
 sub pre_anchor_entry {
@@ -591,6 +619,25 @@ sub pre_anchor_entry {
        $seen->{$id} = "#$id"; # save the anchor for children, later
 }
 
+sub ghost_parent {
+       my ($upfx, $mid) = @_;
+       # 'subject dummy' is used internally by Mail::Thread
+       return '[no common parent]' if ($mid eq 'subject dummy');
+
+       $mid = PublicInbox::Hval->new_msgid($mid);
+       my $href = $mid->as_href;
+       my $html = $mid->as_html;
+       qq{[parent not found: &lt;<a\nhref="$upfx$href/">$html</a>&gt;]};
+}
+
+sub ghost_table {
+       my ($upfx, $mid, $level) = @_;
+       "<table\nsummary=ghost><tr><td>" .
+               (INDENT x $level) . "</td><td>" .
+               PublicInbox::Hval::PRE . ghost_parent($upfx, $mid) .
+               '</pre></td></table>';
+}
+
 sub __thread_entry {
        my ($cb, $git, $state, $mime, $level) = @_;
 
@@ -607,15 +654,7 @@ sub __thread_entry {
        if (my $ghost = delete $state->{ghost}) {
                # n.b. ghost messages may only be parents, not children
                foreach my $g (@$ghost) {
-                       my $mid = PublicInbox::Hval->new_msgid($g->[0]);
-                       my $pfx = INDENT x $g->[1];
-                       my $href = $mid->as_href;
-                       my $html = $mid->as_html;
-                       $$cb->write("<table><tr><td>$pfx</td><td>" .
-                                       PRE_WRAP .
-                                       '[parent not found: &lt;' .
-                                       qq{<a\nhref="../../$href/">}.
-                                       "$html</a>&gt;]</pre></td></table>");
+                       $$cb->write(ghost_table('../../', @$g));
                }
        }
        index_entry($$cb, $mime, $level, $state);
@@ -662,7 +701,7 @@ sub thread_results {
        no warnings 'once';
        $Mail::Thread::nosubject = $nosubject;
        $th->thread;
-       $th->order(*PublicInbox::Thread::sort_ts);
+       $th->order(*sort_ts);
        $th
 }
 
@@ -676,26 +715,38 @@ sub missing_thread {
 sub _msg_date {
        my ($mime) = @_;
        my $ts = $mime->header('X-PI-TS') || msg_timestamp($mime);
-       POSIX::strftime('%Y-%m-%d %H:%M', gmtime($ts));
+       fmt_ts($ts);
 }
 
+sub fmt_ts { POSIX::strftime('%Y-%m-%d %k:%M', gmtime($_[0])) }
+
 sub _inline_header {
        my ($dst, $state, $upfx, $mime, $level) = @_;
-       my $pfx = INDENT x $level;
+       my $pfx = INDENT x ($level - 1);
+       my $dot = $level == 0 ? '' : '` ';
 
        my $cur = $state->{cur};
        my $mid = mid_clean($mime->header('Message-ID'));
        my $f = $mime->header('X-PI-From');
        my $d = _msg_date($mime);
-       $f = PublicInbox::Hval->new($f);
-       $d = PublicInbox::Hval->new($d);
-       $f = $f->as_html;
-       $d = $d->as_html . ' UTC';
+       $f = PublicInbox::Hval->new($f)->as_html;
+       $d = PublicInbox::Hval->new($d)->as_html;
+       my $attr = "$f @ $d";
+       $state->{first_level} ||= $level;
+       if ($attr ne $state->{prev_attr} || $state->{prev_level} > $level) {
+               $state->{prev_attr} = $attr;
+               $attr = ' - ' . $attr;
+               $attr .= ' UTC' if $level >= $state->{first_level};
+       } else {
+               $attr = '';
+       }
+       $state->{prev_level} = $level;
+
        if ($cur) {
                if ($cur eq $mid) {
                        delete $state->{cur};
-                       $$dst .= "$pfx<b><a\nid=\"r\"\nhref=\"#t\">".
-                                "[this message]</a></b> by $f @ $d\n";
+                       $$dst .= "$pfx$dot<b><a\nid=\"r\"\nhref=\"#t\">".
+                                "[this message]</a></b>$attr\n";
 
                        return;
                }
@@ -718,10 +769,9 @@ sub _inline_header {
        my $m = PublicInbox::Hval->new_msgid($mid);
        $m = $upfx . '../' . $m->as_href . '/';
        if (defined $s) {
-               $$dst .= "$pfx` <a\nhref=\"$m\">$s</a>\n" .
-                        "$pfx  $f @ $d\n";
+               $$dst .= "$pfx$dot<a\nhref=\"$m\">$s</a>$attr\n";
        } else {
-               $$dst .= "$pfx<a\nhref=\"$m\">$f @ $d</a>\n";
+               $$dst .= "$pfx$dot<a\nhref=\"$m\">$f @ $d</a>\n";
        }
 }
 
@@ -735,18 +785,22 @@ sub inline_dump {
                }
                _inline_header($dst, $state, $upfx, $mime, $level);
        } else {
-               my $pfx = INDENT x $level;
-               my $v = PublicInbox::Hval->new_msgid($node->messageid, 1);
-               my $html = $v->as_html;
-               my $href = $v->as_href;
-               $$dst .= $pfx . '` [parent not found: &lt;' .
-                               qq{<a\nhref="$upfx../$href/">}.
-                               "$html</a>&gt;]\n";
+               my $dot = $level == 0 ? '' : '` ';
+               my $pfx = (INDENT x $level) . $dot;
+               $$dst .= $pfx;
+               $$dst .= ghost_parent("$upfx../", $node->messageid) . "\n";
        }
        inline_dump($dst, $state, $upfx, $node->child, $level+1);
        inline_dump($dst, $state, $upfx, $node->next, $level);
 }
 
+sub sort_ts {
+       sort {
+               (eval { $a->topmost->message->header('X-PI-TS') } || 0) <=>
+               (eval { $b->topmost->message->header('X-PI-TS') } || 0)
+       } @_;
+}
+
 sub rsort_ts {
        sort {
                (eval { $b->topmost->message->header('X-PI-TS') } || 0) <=>
@@ -759,6 +813,7 @@ sub rsort_ts {
 sub add_topic {
        my ($state, $node, $level) = @_;
        return unless $node;
+       my $child_adjust = 1;
 
        if (my $x = $node->message) {
                $x = $x->header_obj;
@@ -769,8 +824,9 @@ sub add_topic {
                $topic = $subj;
 
                # kill "[PATCH v2]" etc. for summarization
-               $topic =~ s/\A\s*\[[^\]]+\]\s*//g;
-               $topic = substr($topic, 0, 30);
+               unless ($level == 0) {
+                       $topic =~ s/\A\s*\[[^\]]+\]\s*//g;
+               }
 
                if (++$state->{subjs}->{$topic} == 1) {
                        push @{$state->{order}}, [ $level, $subj, $topic ];
@@ -778,12 +834,17 @@ sub add_topic {
 
                my $mid = mid_clean($x->header('Message-ID'));
 
-               my $u = $x->header('X-PI-From');
                my $ts = $x->header('X-PI-TS');
-               $state->{latest}->{$topic} = [ $mid, $u, $ts ];
-       } # else { } # ghost ignored...
+               my $exist = $state->{latest}->{$topic};
+               if (!$exist || $exist->[1] < $ts) {
+                       $state->{latest}->{$topic} = [ $mid, $ts ];
+               }
+       } else {
+               # ghost message, do not bump level
+               $child_adjust = 0;
+       }
 
-       add_topic($state, $node->child, $level + 1);
+       add_topic($state, $node->child, $level + $child_adjust);
        add_topic($state, $node->next, $level);
 }
 
@@ -800,29 +861,32 @@ sub dump_topics {
        while (defined(my $info = shift @$order)) {
                my ($level, $subj, $topic) = @$info;
                my $n = delete $subjs->{$topic};
-               my ($mid, $u, $ts) = @{delete $latest->{$topic}};
+               my ($mid, $ts) = @{delete $latest->{$topic}};
                $mid = PublicInbox::Hval->new($mid)->as_href;
                $subj = PublicInbox::Hval->new($subj)->as_html;
-               $u = PublicInbox::Hval->new($u)->as_html;
-               $pfx = INDENT x $level;
+               $pfx = INDENT x ($level - 1);
                my $nl = $level == $prev ? "\n" : '';
-               my $dot = $level == 0 ? '' : '`';
+               my $dot = $level == 0 ? '' : '` ';
                $dst .= "$nl$pfx$dot<a\nhref=\"$mid/t/#u\"><b>$subj</b></a>\n";
 
                my $attr;
-               $ts = POSIX::strftime('%Y-%m-%d %H:%M', gmtime($ts));
+               $ts = fmt_ts($ts);
                if ($n == 1) {
-                       $attr = "created by $u @ $ts UTC";
-                       $n = "\n";
+                       $attr = "@ $ts UTC";
+                       $n = "";
                } else {
                        # $n isn't the total number of posts on the topic,
                        # just the number of posts in the current results
                        # window, so leave it unlabeled
-                       $attr = "updated by $u @ $ts UTC";
-                       $n = " ($n)\n";
+                       $attr = "@ $ts UTC";
+                       $n = " ($n)";
                }
                if ($level == 0 || $attr ne $prev_attr) {
-                       $dst .= "$pfx - ". $attr . $n;
+                       my $mbox = qq(<a\n$MBOX_TITLE\n) .
+                                  qq(href="$mid/t.mbox.gz">mbox.gz</a>);
+                       my $atom = qq(<a\nhref="$mid/t.atom">Atom</a>);
+                       $pfx .= INDENT if $level > 0;
+                       $dst .= $pfx . $attr . $n . " - $mbox / $atom\n";
                        $prev_attr = $attr;
                }
        }