about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-05-07 21:05:47 +0000
committerEric Wong <e@yhbt.net>2020-05-09 08:59:10 +0000
commit93e3d34ff8d5f981fe4bdd4a6cddb96af6785008 (patch)
tree632d889e2e917e75ea4f8f55bec084d1b0c8aede
parenta6814118856da197b909d68721d461a3936a085b (diff)
downloadpublic-inbox-93e3d34ff8d5f981fe4bdd4a6cddb96af6785008.tar.gz
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.
-rw-r--r--lib/PublicInbox/Smsg.pm24
1 files 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);