]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/View.pm
view: use '+' instead of '%20' to escape spaces in mailto:
[public-inbox.git] / lib / PublicInbox / View.pm
index ea313644979a835350ff022dad5f946ab19722d5..07023e814516c40862ed32b0c2c86ebe7ba5f4db 100644 (file)
@@ -1,4 +1,4 @@
-# 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)
 package PublicInbox::View;
 use strict;
@@ -72,7 +72,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
@@ -117,7 +117,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;
        }
@@ -139,7 +139,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>]";
@@ -353,7 +355,7 @@ sub add_text_body {
 
        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 '';
        }
@@ -407,9 +409,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);
 
@@ -429,17 +430,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>" . PRE_WRAP . $rv);
 }
 
 sub thread_inline {
@@ -535,10 +545,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) {
@@ -577,12 +592,15 @@ sub anchor_for {
 }
 
 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 {
@@ -599,7 +617,15 @@ sub ghost_parent {
        $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;]};
+       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>" .
+               PRE_WRAP . ghost_parent($upfx, $mid) .
+               '</pre></td></table>';
 }
 
 sub __thread_entry {
@@ -618,10 +644,7 @@ sub __thread_entry {
        if (my $ghost = delete $state->{ghost}) {
                # n.b. ghost messages may only be parents, not children
                foreach my $g (@$ghost) {
-                       $$cb->write("<table\nsummary=ghost><tr><td>" .
-                               (INDENT x $g->[1]) . "</td><td>" .
-                               PRE_WRAP . ghost_parent('', $g->[0]) .
-                               '</pre></td></table>');
+                       $$cb->write(ghost_table('../../', @$g));
                }
        }
        index_entry($$cb, $mime, $level, $state);
@@ -752,7 +775,8 @@ sub inline_dump {
        } else {
                my $dot = $level == 0 ? '' : '` ';
                my $pfx = (INDENT x $level) . $dot;
-               $$dst .= $pfx . ghost_parent($upfx, $node->messageid) . "\n";
+               $$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);