about summary refs log tree commit homepage
path: root/lib/PublicInbox/View.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-03-12 06:42:04 +0000
committerEric Wong <e@80x24.org>2016-03-12 06:49:52 +0000
commit476fc666c223f0fbe98ee1f66f7e282abf8adb56 (patch)
treeaa1c5e4afff648f22906a6fc0a0beb365194f967 /lib/PublicInbox/View.pm
parent7dd78012da81d48e5e73e56c3255895dfa9de1f5 (diff)
downloadpublic-inbox-476fc666c223f0fbe98ee1f66f7e282abf8adb56.tar.gz
reduce "PublicInbox::Hval->new_oneline" use
It's probably a bad idea to strip extraneous whitespace
from some headers as an extra space may convey useful
information.

Newlines don't seem to be preserved by Email::MIME or
Email::Simple anyways, so there's no danger in breaking
formatting.
Diffstat (limited to 'lib/PublicInbox/View.pm')
-rw-r--r--lib/PublicInbox/View.pm23
1 files changed, 9 insertions, 14 deletions
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 3522bf44..4058bee7 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -11,7 +11,7 @@ use Date::Parse qw/str2time/;
 use Encode qw/find_encoding/;
 use Encode::MIME::Header;
 use Email::MIME::ContentType qw/parse_content_type/;
-use PublicInbox::Hval;
+use PublicInbox::Hval qw/ascii_html/;
 use PublicInbox::Linkify;
 use PublicInbox::MID qw/mid_clean id_compress mid2path mid_mime/;
 require POSIX;
@@ -22,8 +22,6 @@ use constant MAX_TRUNC_LEN => 72;
 use constant T_ANCHOR => '#u';
 use constant INDENT => '  ';
 
-*ascii_html = *PublicInbox::Hval::ascii_html;
-
 my $enc_utf8 = find_encoding('UTF-8');
 
 # public functions:
@@ -50,10 +48,9 @@ sub msg_reply {
         $s = '(no subject)' if (!defined $s) || ($s eq '');
         my $f = $hdr->header('From');
         $f = '' unless defined $f;
-        $s = PublicInbox::Hval->new_oneline($s);
         my $mid = $hdr->header_raw('Message-ID');
         $mid = PublicInbox::Hval->new_msgid($mid);
-        my $t = $s->as_html;
+        my $t = ascii_html($s);
         my $se_url =
          'https://kernel.org/pub/software/scm/git/docs/git-send-email.html';
 
@@ -121,18 +118,18 @@ sub index_entry {
         $seen->{$id} = "#$id"; # save the anchor for children, later
 
         my $mid = PublicInbox::Hval->new_msgid($mid_raw);
-        my $from = PublicInbox::Hval->new_oneline($hdr->header('From'))->raw;
+        my $from = $hdr->header('From');
         my @from = Email::Address->parse($from);
         $from = $from[0]->name;
 
-        $from = PublicInbox::Hval->new_oneline($from)->as_html;
-        $subj = PublicInbox::Hval->new_oneline($subj)->as_html;
         my $root_anchor = $state->{root_anchor} || '';
         my $path = $root_anchor ? '../../' : '';
         my $href = $mid->as_href;
         my $irt = in_reply_to($hdr);
         my $parent_anchor = $seen->{anchor_for($irt)} if defined $irt;
 
+        $from = ascii_html($from);
+        $subj = ascii_html($subj);
         if ($srch) {
                 my $t = $ctx->{flat} ? 'T' : 't';
                 $subj = "<a\nhref=\"${path}$href/$t/#u\">$subj</a>";
@@ -414,7 +411,7 @@ sub headers_to_html_header {
         foreach my $h (qw(From To Cc Subject Date)) {
                 my $v = $hdr->header($h);
                 defined($v) && ($v ne '') or next;
-                $v = PublicInbox::Hval->new_oneline($v);
+                $v = PublicInbox::Hval->new($v);
 
                 if ($h eq 'From') {
                         my @from = Email::Address->parse($v->raw);
@@ -582,7 +579,7 @@ sub html_footer {
                 my $p = $ctx->{parent_msg};
                 my $next = $ctx->{next_msg};
                 if ($p) {
-                        $p = PublicInbox::Hval->new_oneline($p);
+                        $p = PublicInbox::Hval->new_msgid($p);
                         $p = $p->as_href;
                         $irt = "<a\nhref=\"$upfx$p/\">parent</a> ";
                 } else {
@@ -626,8 +623,7 @@ sub thread_html_head {
         my ($cb, $header, $state) = @_;
         $$cb = $$cb->([200, ['Content-Type'=> 'text/html; charset=UTF-8']]);
 
-        my $s = PublicInbox::Hval->new_oneline($header->header('Subject'));
-        $s = $s->as_html;
+        my $s = ascii_html($header->header('Subject'));
         $$cb->write("<html><head><title>$s</title>".
                 qq{<link\nrel=alternate\ntitle="Atom feed"\n} .
                 qq!href="../t.atom"\ntype="application/atom+xml"/>! .
@@ -781,9 +777,8 @@ sub _inline_header {
 
         my $cur = $state->{cur};
         my $mid = mid_clean($hdr->header_raw('Message-ID'));
-        my $f = $hdr->header('X-PI-From');
+        my $f = ascii_html($hdr->header('X-PI-From'));
         my $d = _msg_date($hdr);
-        $f = PublicInbox::Hval->new_oneline($f)->as_html;
         my $pfx = ' ' . $d . ' ' . indent_for($level);
         my $attr = $f;
         $state->{first_level} ||= $level;