about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2014-04-17 22:41:57 +0000
committerEric Wong <e@80x24.org>2014-04-17 22:42:54 +0000
commitfefea3d7d2484ffbf433aec0dd80026aa7120e07 (patch)
treeb693c111890e1f8bbae88a43c92a7193538c1b98 /lib
parent5a90d23bab2c917c08d73d51679c6aae9fb7d526 (diff)
downloadpublic-inbox-fefea3d7d2484ffbf433aec0dd80026aa7120e07.tar.gz
Sometimes a single long word or URL can lengthen the line
too much.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/View.pm17
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 1a912a6e..ed7d0b66 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -9,6 +9,7 @@ use Encode qw/find_encoding/;
 use Encode::MIME::Header;
 use Email::MIME::ContentType qw/parse_content_type/;
 use constant MAX_INLINE_QUOTED => 5;
+use constant MAX_TRUNC_LEN => 72;
 
 my $enc_utf8 = find_encoding('utf8');
 my $enc_ascii = find_encoding('us-ascii');
@@ -91,18 +92,24 @@ sub add_text_body_short {
         my $s = ascii_html($enc->decode($part->body));
         $s =~ s!^((?:(?:&gt;[^\n]*)\n)+)!
                 my $cur = $1;
-                my @lines = split(/\n/, $cur);
+                my @lines = split(/\n(?:&gt;\s*)?/, $cur);
                 if (@lines > MAX_INLINE_QUOTED) {
                         # show a short snippet of quoted text
                         $cur = join(' ', @lines);
-                        $cur =~ s/&gt; ?//g;
+                        $cur =~ s/^&gt;\s*//;
 
                         my @sum = split(/\s+/, $cur);
                         $cur = '';
                         do {
-                                $cur .= shift(@sum) . ' ';
-                        } while (@sum && length($cur) < 64);
-                        $cur=~ s/ \z/ .../;
+                                my $tmp = shift(@sum);
+                                my $len = length($tmp) + length($cur);
+                                if ($len > MAX_TRUNC_LEN) {
+                                        @sum = ();
+                                } else {
+                                        $cur .= $tmp . ' ';
+                                }
+                        } while (@sum && length($cur) < MAX_TRUNC_LEN);
+                        $cur =~ s/ \z/ .../;
                         "&gt; &lt;<a href=\"${full_pfx}#q${part_nr}_" . $n++ .
                                 "\">$cur<\/a>&gt;\n";
                 } else {