From fefea3d7d2484ffbf433aec0dd80026aa7120e07 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 17 Apr 2014 22:41:57 +0000 Subject: ensure per-message short quotes do not get too long Sometimes a single long word or URL can lengthen the line too much. --- lib/PublicInbox/View.pm | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'lib') 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!^((?:(?:>[^\n]*)\n)+)! my $cur = $1; - my @lines = split(/\n/, $cur); + my @lines = split(/\n(?:>\s*)?/, $cur); if (@lines > MAX_INLINE_QUOTED) { # show a short snippet of quoted text $cur = join(' ', @lines); - $cur =~ s/> ?//g; + $cur =~ s/^>\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/ .../; "> <$cur<\/a>>\n"; } else { -- cgit v1.2.3-24-ge0c7