about summary refs log tree commit homepage
path: root/lib/PublicInbox/Feed.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/Feed.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/Feed.pm')
-rw-r--r--lib/PublicInbox/Feed.pm20
1 files changed, 8 insertions, 12 deletions
diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 47408535..e4831f6a 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -8,7 +8,7 @@ use warnings;
 use Email::Address;
 use Email::MIME;
 use Date::Parse qw(strptime);
-use PublicInbox::Hval;
+use PublicInbox::Hval qw/ascii_html/;
 use PublicInbox::Git;
 use PublicInbox::View;
 use PublicInbox::MID qw/mid_clean mid2path/;
@@ -38,8 +38,9 @@ sub generate_html_index {
 
 sub title_tag {
         my ($title) = @_;
+        $title =~ tr/\t\n / /s; # squeeze spaces
         # try to avoid the type attribute in title:
-        $title = PublicInbox::Hval->new_oneline($title)->as_html;
+        $title =~ ascii_html($title);
         my $type = index($title, '&') >= 0 ? "\ntype=\"html\"" : '';
         "<title$type>$title</title>";
 }
@@ -117,7 +118,6 @@ sub emit_html_index {
         my $feed_opts = get_feedopts($ctx);
 
         my $title = $feed_opts->{description} || '';
-        $title = PublicInbox::Hval->new_oneline($title)->as_html;
         my ($footer, $param, $last);
         my $state = { ctx => $ctx, seen => {}, anchor_idx => 0 };
         my $srch = $ctx->{srch};
@@ -295,11 +295,6 @@ sub get_feedopts {
         \%rv;
 }
 
-sub mime_header {
-        my ($mime, $name) = @_;
-        PublicInbox::Hval->new_oneline($mime->header($name))->raw;
-}
-
 sub feed_updated {
         my ($date, $ts) = @_;
         my @t = eval { strptime($date) } if defined $date;
@@ -328,14 +323,15 @@ sub add_to_feed {
         my $date = $header_obj->header('Date');
         my $updated = feed_updated($date);
 
-        my $title = mime_header($header_obj, 'Subject') or return 0;
+        my $title = $header_obj->header('Subject');
+        defined $title or return 0;
         $title = title_tag($title);
 
-        my $from = mime_header($header_obj, 'From') or return 0;
+        my $from = $header_obj->header('From') or return 0;
         my @from = Email::Address->parse($from) or return 0;
-        my $name = PublicInbox::Hval->new_oneline($from[0]->name)->as_html;
+        my $name = ascii_html($from[0]->name);
         my $email = $from[0]->address;
-        $email = PublicInbox::Hval->new_oneline($email)->as_html;
+        $email = ascii_html($email);
 
         if (delete $feed_opts->{emit_header}) {
                 $fh->write(atom_header($feed_opts, $title) . $updated);