diff options
author | Eric Wong <e@80x24.org> | 2022-11-24 21:31:55 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2022-11-26 08:09:58 +0000 |
commit | 5198c976ce8b1954f0f76a0da152cc434411f147 (patch) | |
tree | 4ebf02230520d7526a14f194e50793ff07d3e32e /lib/PublicInbox/Eml.pm | |
parent | 2bd8f48268ac24a4d3cac326a89099639ae1d170 (diff) | |
download | public-inbox-5198c976ce8b1954f0f76a0da152cc434411f147.tar.gz |
This fixes the display of raw (non-RFC 2047) names and subjects in HTML message views. SMTPUTF8 (RFC 6531) allows raw UTF-8 in headers without RFC 2047 encoding, so let Perl handle it as a character sequence for the rest of our consumers. Thus, the old special case in PublicInbox::Smsg->populate is no longer necessary and gone. The one regression notice so far (and fixed here) is compressed IMAP envelope responses still needs raw bytes since the zlib wrapper is designed for octets, not Perl UTF-8 chars. Thus we reverse utf8::decode with utf8::encode in PublicInbox::IMAP::_esc. ->header_set also forces encoding to bytes, since all existing callers would either be dealing with ->header_raw results or be RFC-2047-encoded anyways. Reindexing is not necessary with this change due to the prior PublicInbox::Smsg->populate special case. Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org> Link: https://public-inbox.org/meta/20221124153715.3nenjpjzj43vqxr2@meerkat.local/
Diffstat (limited to 'lib/PublicInbox/Eml.pm')
-rw-r--r-- | lib/PublicInbox/Eml.pm | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/PublicInbox/Eml.pm b/lib/PublicInbox/Eml.pm index 485f637a..8b999e1a 100644 --- a/lib/PublicInbox/Eml.pm +++ b/lib/PublicInbox/Eml.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org> +# Copyright (C) all contributors <meta@public-inbox.org> # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> # # Lazy MIME parser, it still slurps the full message but keeps short @@ -144,6 +144,7 @@ sub header_raw { my $re = re_memo($_[1]); my @v = (${ $_[0]->{hdr} } =~ /$re/g); for (@v) { + utf8::decode($_); # SMTPUTF8 # for compatibility w/ Email::Simple::Header, s/\s+\z//s; s/\A\s+//s; @@ -359,14 +360,15 @@ sub header_set { $pfx .= ': '; my $len = 78 - length($pfx); @vals = map {; + utf8::encode(my $v = $_); # to bytes, support SMTPUTF8 # folding differs from Email::Simple::Header, # we favor tabs for visibility (and space savings :P) if (length($_) >= $len && (/\n[^ \t]/s || !/\n/s)) { local $Text::Wrap::columns = $len; local $Text::Wrap::huge = 'overflow'; - $pfx . wrap('', "\t", $_) . $self->{crlf}; + $pfx . wrap('', "\t", $v) . $self->{crlf}; } else { - $pfx . $_ . $self->{crlf}; + $pfx . $v . $self->{crlf}; } } @vals; $$hdr =~ s!$re!shift(@vals) // ''!ge; # replace current headers, first |