]> Sergey Matveev's repositories - public-inbox.git/commitdiff
view: inline shorter quotes
authorEric Wong <e@80x24.org>
Thu, 17 Apr 2014 21:49:52 +0000 (21:49 +0000)
committerEric Wong <e@80x24.org>
Thu, 17 Apr 2014 21:55:38 +0000 (21:55 +0000)
Breaking up short quote messages at 1 line is too disconcerting,
try 5 lines as proper quotes shouldn't be too long.

lib/PublicInbox/View.pm
t/feed.t
t/view.t

index 84c7393b197131ee01c4ba94935578c0ef51bf29..17aca94e63e1fbfb5aa4668f33be3b2d6e03960f 100644 (file)
@@ -8,6 +8,7 @@ use CGI qw/escapeHTML/;
 use Encode qw/find_encoding/;
 use Encode::MIME::Header;
 use Email::MIME::ContentType qw/parse_content_type/;
+use constant MAX_INLINE_QUOTED => 5;
 
 my $enc_utf8 = find_encoding('utf8');
 my $enc_ascii = find_encoding('us-ascii');
@@ -88,10 +89,10 @@ sub add_text_body_short {
        my ($enc, $part, $part_nr, $full_pfx) = @_;
        my $n = 0;
        my $s = ascii_html($enc->decode($part->body));
-       $s =~ s!^((?:(?:&gt;[^\n]+)\n)+)!
+       $s =~ s!^((?:(?:&gt;[^\n]*)\n)+)!
                my $cur = $1;
                my @lines = split(/\n/, $cur);
-               if (@lines > 1) {
+               if (@lines > MAX_INLINE_QUOTED) {
                        # show a short snippet of quoted text
                        $cur = join(' ', @lines);
                        $cur =~ s/&gt; ?//g;
@@ -100,10 +101,10 @@ sub add_text_body_short {
                        $cur = '';
                        do {
                                $cur .= shift(@sum) . ' ';
-                       } while (@sum && length($cur) < 68);
+                       } while (@sum && length($cur) < 64);
                        $cur=~ s/ \z/ .../;
                        "&gt; &lt;<a href=\"${full_pfx}#q${part_nr}_" . $n++ .
-                               "\">$cur<\/a>&gt;";
+                               "\">$cur<\/a>&gt;\n";
                } else {
                        $cur;
                }
@@ -115,10 +116,10 @@ sub add_text_body_full {
        my ($enc, $part, $part_nr) = @_;
        my $n = 0;
        my $s = ascii_html($enc->decode($part->body));
-       $s =~ s!^((?:(?:&gt;[^\n]+)\n)+)!
+       $s =~ s!^((?:(?:&gt;[^\n]*)\n)+)!
                my $cur = $1;
                my @lines = split(/\n/, $cur);
-               if (@lines > 1) {
+               if (@lines > MAX_INLINE_QUOTED) {
                        "<a name=q${part_nr}_" . $n++ . ">$cur</a>";
                } else {
                        $cur;
index 63fcc443143f1f40e7e5463f5181da495c8fbc85..125490d630528cc2b944e88d0bfc92ca21912fe7 100644 (file)
--- a/t/feed.t
+++ b/t/feed.t
@@ -31,10 +31,15 @@ Date: Thu, 01 Jan 1970 00:00:00 +0000
 
 > This is a long multi line quote so it should not be allowed to
 > show up in its entirty in the Atom feed.  drop me
+> I quote to much
+> I quote to much
+> I quote to much
+> I quote to much
 
 msg $i
 
-> inline me here, short quote
+> inline me here
+> this is a short quote
 
 keep me
 EOF
index ef1b74c940c5dc747a677598ec94daefe7d7f6d8..067f9890cc271abc0d1e7195b5d0e823ce677f6d 100644 (file)
--- a/t/view.t
+++ b/t/view.t
@@ -16,6 +16,10 @@ OK
 
 > Long and wordy reply goes here and it is split across multiple lines.
 > We generate links to a separate full page where quoted-text is inline.
+> This is
+>
+> Currently 5 lines
+> See MAX_INLINE_QUOTED
 
 hello world
 EOF