user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH 04/13] smsg: use capitalization for header retrieval
Date: Thu,  7 May 2020 21:05:47 +0000	[thread overview]
Message-ID: <20200507210556.22995-5-e@yhbt.net> (raw)
In-Reply-To: <20200507210556.22995-1-e@yhbt.net>

PublicInbox::Eml will have case-sensitive memoization to
avoid the need to call `lc' to retrieve common headers,
so ensure we call $mime->header() with the common
capitalization.

Unfortunately, we need to continue using lowercase for field
names for smsg, since NNTP requires case-insensitivity when
matching headers and method dispatch is expensive.
---
 lib/PublicInbox/Smsg.pm | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/lib/PublicInbox/Smsg.pm b/lib/PublicInbox/Smsg.pm
index 7c90b92d..7a2766d8 100644
--- a/lib/PublicInbox/Smsg.pm
+++ b/lib/PublicInbox/Smsg.pm
@@ -106,20 +106,18 @@ sub lines ($) { $_[0]->{lines} }
 
 sub __hdr ($$) {
 	my ($self, $field) = @_;
-	my $val = $self->{$field};
-	return $val if defined $val;
-
-	my $mime = $self->{mime} or return;
-	my @raw = $mime->header($field);
-	$val = join(', ', @raw);
-	$val =~ tr/\t\n/  /;
-	$val =~ tr/\r//d;
-	$self->{$field} = $val;
+	$self->{lc($field)} //= do {
+		my $mime = $self->{mime} or return;
+		my $val = join(', ', $mime->header($field));
+		$val =~ tr/\r//d;
+		$val =~ tr/\t\n/  /;
+		$val;
+	};
 }
 
-sub subject ($) { __hdr($_[0], 'subject') }
-sub to ($) { __hdr($_[0], 'to') }
-sub cc ($) { __hdr($_[0], 'cc') }
+sub subject ($) { __hdr($_[0], 'Subject') }
+sub to ($) { __hdr($_[0], 'To') }
+sub cc ($) { __hdr($_[0], 'Cc') }
 
 # no strftime, that is locale-dependent and not for RFC822
 my @DoW = qw(Sun Mon Tue Wed Thu Fri Sat);
@@ -137,7 +135,7 @@ sub date ($) {
 
 sub from ($) {
 	my ($self) = @_;
-	my $from = __hdr($self, 'from');
+	my $from = __hdr($self, 'From');
 	if (defined $from && !defined $self->{from_name}) {
 		my @n = PublicInbox::Address::names($from);
 		$self->{from_name} = join(', ', @n);

  parent reply	other threads:[~2020-05-07 21:05 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-07 21:05 [PATCH 00/13] eml: pure-Perl replacement for Email::MIME Eric Wong
2020-05-07 21:05 ` [PATCH 01/13] msg_iter: make ->each_part method for PublicInbox::MIME Eric Wong
2020-05-07 21:05 ` [PATCH 02/13] msg_iter: pass $idx as a scalar, not array Eric Wong
2020-05-07 21:05 ` [PATCH 03/13] filter/rubylang: avoid recursing subparts to strip trailers Eric Wong
2020-05-07 21:05 ` Eric Wong [this message]
2020-05-07 21:05 ` [PATCH 05/13] eml: pure-Perl replacement for Email::MIME Eric Wong
2020-05-07 21:05 ` [PATCH 06/13] switch read-only Email::Simple users to Eml Eric Wong
2020-05-07 21:05 ` [PATCH 07/13] replace most uses of PublicInbox::MIME with Eml Eric Wong
2020-05-07 21:05 ` [PATCH 08/13] EmlContentFoo: Email::MIME::ContentType replacement Eric Wong
2020-05-07 21:05 ` [PATCH 09/13] EmlContentFoo: relax Encode version requirement Eric Wong
2020-05-07 21:05 ` [PATCH 10/13] eml: remove dependency on Email::MIME::Encodings Eric Wong
2020-05-07 21:05 ` [PATCH 11/13] xt: eml comparison tests Eric Wong
2020-05-08  4:47   ` Eric Wong
2020-05-07 21:05 ` [PATCH 12/13] remove most internal Email::MIME usage Eric Wong
2020-05-07 21:05 ` [PATCH 13/13] eml: drop trailing blank line on missing epilogue 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: https://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=20200507210556.22995-5-e@yhbt.net \
    --to=e@yhbt.net \
    --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).