]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/View.pm
view: remove pointless self-linkage
[public-inbox.git] / lib / PublicInbox / View.pm
index 84c7393b197131ee01c4ba94935578c0ef51bf29..1a912a6edf6694d44860dedbc1153796c9ca5bb6 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!^((?:(?:>[^\n]+)\n)+)!
+       $s =~ s!^((?:(?:>[^\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/> ?//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;
@@ -152,18 +153,27 @@ sub headers_to_html_header {
                defined $v or next;
                $v =~ tr/\n/ /s;
                $v =~ tr/\r//d;
-               $v = ascii_html($enc_mime->decode($v));
+               my $raw = $enc_mime->decode($v);
+               $v = ascii_html($raw);
                $rv .= "$h: $v\n";
 
-               if ($h eq "From" || $h eq "Subject") {
-                       push @title, $v;
+               if ($h eq 'From') {
+                       my @from = Email::Address->parse($raw);
+                       $raw = $from[0]->name;
+                       unless (defined($raw) && length($raw)) {
+                               $raw = '<' . $from[0]->address . '>';
+                       }
+                       $title[1] = ascii_html($raw);
+
+               } elsif ($h eq 'Subject') {
+                       $title[0] = $v;
                }
        }
 
        my $mid = $simple->header('Message-ID');
        if (defined $mid) {
                my ($html, $href) = trim_message_id($mid);
-               $rv .= "Message-ID: &lt;<a href=\"$href.html\">$html</a>&gt; ";
+               $rv .= "Message-ID: &lt;$html&gt; ";
                $rv .= "(<a href=\"$href.txt\">original</a>)\n";
        }