]> Sergey Matveev's repositories - public-inbox.git/commitdiff
view: untangle loop when showing message headers
authorEric Wong <e@80x24.org>
Mon, 23 Apr 2018 04:16:52 +0000 (04:16 +0000)
committerEric Wong <e@80x24.org>
Mon, 23 Apr 2018 04:17:04 +0000 (04:17 +0000)
The old loop did not help with code clarity with the various
conditional statements.  It also hid a bug where we forgot to
(optionally) obfuscate email addresses in Subject: lines if
search was enabled.

lib/PublicInbox/View.pm

index af287b96852be66b708bd0eff86d6064ee1773c6..add3dfc2738f17cb3357b511d467cb51fb6507ad 100644 (file)
@@ -591,29 +591,42 @@ sub _msg_html_prepare {
                $ctx->{-upfx} = '../';
        }
        my @title;
-       foreach my $h (qw(From To Cc Subject Date)) {
-               my $v = $hdr->header($h);
-               defined($v) && ($v ne '') or next;
+       my $v;
+       if (defined($v = $hdr->header('From'))) {
                $v = PublicInbox::Hval->new($v);
-
-               if ($h eq 'From') {
-                       my @n = PublicInbox::Address::names($v->raw);
-                       $title[1] = ascii_html(join(', ', @n));
-                       obfuscate_addrs($obfs_ibx, $title[1]) if $obfs_ibx;
-               } elsif ($h eq 'Subject') {
-                       $title[0] = $v->as_html;
-                       if ($srch) {
-                               $rv .= qq($h: <a\nhref="#r"\nid=t>);
-                               $rv .= $v->as_html . "</a>\n";
-                               next;
-                       }
-               }
+               my @n = PublicInbox::Address::names($v->raw);
+               $title[1] = ascii_html(join(', ', @n));
                $v = $v->as_html;
+               if ($obfs_ibx) {
+                       obfuscate_addrs($obfs_ibx, $v);
+                       obfuscate_addrs($obfs_ibx, $title[1]);
+               }
+               $rv .= "From: $v\n" if $v ne '';
+       }
+       foreach my $h (qw(To Cc)) {
+               defined($v = $hdr->header($h)) or next;
+               $v = ascii_html($v);
                obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx;
-               $rv .= "$h: $v\n";
-
+               $rv .= "$h: $v\n" if $v ne '';
+       }
+       if (defined($v = $hdr->header('Subject')) && ($v ne '')) {
+               $v = ascii_html($v);
+               obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx;
+               if ($srch) {
+                       $rv .= qq(Subject: <a\nhref="#r"\nid=t>$v</a>\n);
+               } else {
+                       $rv .= "Subject: $v\n";
+               }
+               $title[0] = $v;
+       } else { # dummy anchor for thread skeleton at bottom of page
+               $rv .= qq(<a\nhref="#r"\nid=t></a>) if $srch;
+               $title[0] = '(no subject)';
+       }
+       if (defined($v = $hdr->header('Date'))) {
+               $v = ascii_html($v);
+               obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx; # possible :P
+               $rv .= "Date: $v\n";
        }
-       $title[0] ||= '(no subject)';
        $ctx->{-title_html} = join(' - ', @title);
        foreach (@$mids) {
                my $mid = PublicInbox::Hval->new_msgid($_) ;