about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-03-01 02:45:34 +0000
committerEric Wong <e@80x24.org>2016-03-01 02:45:34 +0000
commitf5eb6bb83558f3dabdb2fbbf7c1c926a726bfed9 (patch)
tree00d27bb68dcd0b72ab43a44dde2536137c43d87e /lib
parentcb6cb8a6146c1f7a51b6eb0fe777311c9cc6a245 (diff)
downloadpublic-inbox-f5eb6bb83558f3dabdb2fbbf7c1c926a726bfed9.tar.gz
We now keep intermediate blank lines in messages, since it
could be used to denote logical gaps in the message
(such as giving readers a chance to opt out of "spoiler"
information).

However leading blank lines, trailing blank lines, and
trailing whitespace have no useful value we can discern;
so drop those entirely to prevent clients from eating up
vertical whitespace.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/View.pm20
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index de7bdf9c..61eb890f 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -254,15 +254,10 @@ sub index_walk {
         my ($fh, $part, $enc, $part_nr, $fhref, $more) = @_;
         my $s = add_text_body($enc, $part, $part_nr, $fhref);
 
-        # kill any leading or trailing whitespace lines
-        $s =~ s/^\s*$//sgm;
-        $s =~ s/\s+\z//s;
+        return if $s eq '';
+
+        $s .= "\n"; # ensure there's a trailing newline
 
-        if ($s ne '') {
-                # kill per-line trailing whitespace
-                $s =~ s/[ \t]+$//sgm;
-                $s .= "\n" unless $s =~ /\n\z/s;
-        }
         $fh->write($s);
 }
 
@@ -289,7 +284,9 @@ sub multipart_text_as_html {
         # scan through all parts, looking for displayable text
         $mime->walk_parts(sub {
                 my ($part) = @_;
-                $rv .= add_text_body($enc, $part, \$part_nr, $full_pfx, 1);
+                $part = add_text_body($enc, $part, \$part_nr, $full_pfx, 1);
+                $rv .= $part;
+                $rv .= "\n" if $part ne '';
         });
         $mime->body_set('');
         $rv;
@@ -435,8 +432,11 @@ sub add_text_body {
                 $s .= flush_quote(\@quot, \$n, $$part_nr, $full_pfx, 1,
                                   $do_anchor);
         }
-        $s .= "\n" unless $s =~ /\n\z/s;
         ++$$part_nr;
+
+        $s =~ s/[ \t]+$//sgm; # kill per-line trailing whitespace
+        $s =~ s/\A\n+//s; # kill leading blank lines
+        $s =~ s/\s+\z//s; # kill all trailing spaces (final "\n" added if ne '')
         $s;
 }