From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id C0B9E1F8C5 for ; Thu, 7 May 2020 21:05:57 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 04/13] smsg: use capitalization for header retrieval Date: Thu, 7 May 2020 21:05:47 +0000 Message-Id: <20200507210556.22995-5-e@yhbt.net> In-Reply-To: <20200507210556.22995-1-e@yhbt.net> References: <20200507210556.22995-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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);