]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/View.pm
constent X?HTML MIME type filtering
[public-inbox.git] / lib / PublicInbox / View.pm
index d025c99340ac28b37a2b23e345e809c99f45db84..9f87546f9428b680ad90768419700f1f62f70755 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;
@@ -85,7 +85,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 +95,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>";
        }
 
@@ -116,8 +116,8 @@ sub index_entry {
        my ($fhref, $more_ref);
        my $mhref = "${path}$href/";
 
-       # 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
+       if ($root_anchor ne $id) {
                $fhref = "${path}$href/f/";
                $more_ref = \$more;
        }
@@ -353,7 +353,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,7 +407,6 @@ 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);
                defined($v) && ($v ne '') or next;
@@ -429,10 +428,10 @@ 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";
        if ($srch) {
-               $rv .= "<a\nhref=\"#r\">References: [see below]</a>\n";
+               $rv .= "<a\nhref=\"${upfx}t/\">References: [expand]</a>\n";
        } else {
                $rv .= _parent_headers_nosrch($header_obj);
        }
@@ -620,7 +619,7 @@ sub __thread_entry {
                foreach my $g (@$ghost) {
                        $$cb->write("<table\nsummary=ghost><tr><td>" .
                                (INDENT x $g->[1]) . "</td><td>" .
-                               PRE_WRAP . ghost_parent('', $g->[0]) .
+                               PRE_WRAP . ghost_parent('../', $g->[0]) .
                                '</pre></td></table>');
                }
        }
@@ -687,7 +686,8 @@ sub _msg_date {
 
 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'));
@@ -709,7 +709,7 @@ sub _inline_header {
        if ($cur) {
                if ($cur eq $mid) {
                        delete $state->{cur};
-                       $$dst .= "$pfx<b><a\nid=\"r\"\nhref=\"#t\">".
+                       $$dst .= "$pfx$dot<b><a\nid=\"r\"\nhref=\"#t\">".
                                 "[this message]</a></b>$attr\n";
 
                        return;
@@ -733,9 +733,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>$attr\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";
        }
 }
 
@@ -749,7 +749,8 @@ sub inline_dump {
                }
                _inline_header($dst, $state, $upfx, $mime, $level);
        } else {
-               my $pfx = (INDENT x $level) . '` ';
+               my $dot = $level == 0 ? '' : '` ';
+               my $pfx = (INDENT x $level) . $dot;
                $$dst .= $pfx . ghost_parent($upfx, $node->messageid) . "\n";
        }
        inline_dump($dst, $state, $upfx, $node->child, $level+1);
@@ -775,6 +776,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;
@@ -797,9 +799,12 @@ sub add_topic {
                my $u = $x->header('X-PI-From');
                my $ts = $x->header('X-PI-TS');
                $state->{latest}->{$topic} = [ $mid, $u, $ts ];
-       } # else { } # ghost ignored...
+       } 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);
 }
 
@@ -838,7 +843,8 @@ sub dump_topics {
                        $n = " ($n)\n";
                }
                if ($level == 0 || $attr ne $prev_attr) {
-                       $dst .= "$pfx - ". $attr . $n;
+                       $pfx .= INDENT if $level > 0;
+                       $dst .= "$pfx- ". $attr . $n;
                        $prev_attr = $attr;
                }
        }