]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/View.pm
view: remove attribution for topics in top-level view
[public-inbox.git] / lib / PublicInbox / View.pm
index de2d667c91f7612e30d4023e3d5131302caad6dc..534b5539272e2e4357354c7a78ec6d795de6ff21 100644 (file)
@@ -9,9 +9,10 @@ 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
@@ -117,7 +118,7 @@ sub index_entry {
        my $mhref = "${path}$href/";
 
        # show full message if it's our root message
-       if ($root_anchor ne $id) {
+       if ($root_anchor ne $id || ($level != 0 && !$ctx->{flat})) {
                $fhref = "${path}$href/f/";
                $more_ref = \$more;
        }
@@ -198,7 +199,8 @@ 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>";
-       $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>");
@@ -410,7 +412,7 @@ sub headers_to_html_header {
        my $mid = $header_obj->header('Message-ID');
        $mid = PublicInbox::Hval->new_msgid($mid);
        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);
 
@@ -432,15 +434,24 @@ sub headers_to_html_header {
        $rv .= 'Message-ID: &lt;' . $mid->as_html . '&gt; ';
        my $upfx = $full_pfx ? '' : '../';
        $rv .= "(<a\nhref=\"${upfx}raw\">raw</a>)\n";
+       my $atom;
        if ($srch) {
-               $rv .= "<a\nhref=\"${upfx}t/\">References: [expand]</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>" . PRE_WRAP . $rv);
 }
 
 sub thread_inline {
@@ -536,10 +547,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) {
@@ -572,18 +588,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 {
@@ -804,9 +823,11 @@ 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 ];
+               my $exist = $state->{latest}->{$topic};
+               if (!$exist || $exist->[2] < $ts) {
+                       $state->{latest}->{$topic} = [ $mid, $ts ];
+               }
        } else {
                # ghost message, do not bump level
                $child_adjust = 0;
@@ -829,10 +850,9 @@ 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 - 1);
                my $nl = $level == $prev ? "\n" : '';
                my $dot = $level == 0 ? '' : '` ';
@@ -841,18 +861,22 @@ sub dump_topics {
                my $attr;
                $ts = POSIX::strftime('%Y-%m-%d %H:%M', gmtime($ts));
                if ($n == 1) {
-                       $attr = "created by $u @ $ts UTC";
-                       $n = "\n";
+                       $attr = "created @ $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 = "updated @ $ts UTC";
+                       $n = " ($n)";
                }
                if ($level == 0 || $attr ne $prev_attr) {
+                       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;
+                       $dst .= " - $mbox / $atom\n";
                        $prev_attr = $attr;
                }
        }