user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/3] view: untangle loop when showing message headers
Date: Mon, 23 Apr 2018 04:16:52 +0000	[thread overview]
Message-ID: <20180423041654.4152-2-e@80x24.org> (raw)
In-Reply-To: <20180423041654.4152-1-e@80x24.org>

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 | 51 ++++++++++++++++++++++++++---------------
 1 file changed, 32 insertions(+), 19 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index af287b9..add3dfc 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -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($_) ;
-- 
EW


  reply	other threads:[~2018-04-23  4:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-23  4:16 [PATCH 0/3] view: wrap long To:/Cc: lists Eric Wong
2018-04-23  4:16 ` Eric Wong [this message]
2018-04-23  4:16 ` [PATCH 2/3] view: wrap To: and Cc: headers in HTML display Eric Wong
2018-04-23  4:16 ` [PATCH 3/3] view: drop redundant References: display code Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180423041654.4152-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).