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/
-# 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
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;
$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
if (!defined($v)) {
'NIL';
} elsif ($v =~ /[{"\r\n%*\\\[]/) { # literal string
+ utf8::encode($v);
'{' . length($v) . "}\r\n" . $v;
} else { # quoted string
+ utf8::encode($v);
qq{"$v"}
}
}
# to protect git and NNTP clients
$val =~ tr/\0\t\n/ /;
- # rare: in case headers have wide chars (not RFC2047-encoded)
- utf8::decode($val);
-
# lower-case fields for read-only stuff
$self->{lc($f)} = $val;
}
}
+{
+ ok(my $ic = $imap_client->new(%mic_opt), 'logged in');
+ my $mb = "$ibx[0]->{newsgroup}.$first_range";
+ ok($ic->examine($mb), "EXAMINE $mb");
+ my $uidnext = $ic->uidnext($mb); # we'll fetch BODYSTRUCTURE on this
+ my $im = $ibx[0]->importer(0);
+ $im->add(PublicInbox::Eml->new(<<EOF)) or BAIL_OUT;
+Subject: test Ævar
+Message-ID: <smtputf8-delivered-mess\@age>
+From: Ævar Arnfjörð Bjarmason <avarab\@example>
+To: git\@vger.kernel.org
+
+EOF
+ $im->done;
+ my $envl = $ic->get_envelope($uidnext);
+ is($envl->{subject}, 'test Ævar', 'UTF-8 subject');
+ is($envl->{sender}->[0]->{personalname}, 'Ævar Arnfjörð Bjarmason',
+ 'UTF-8 sender[0].personalname');
+ SKIP: {
+ skip 'need compress for comparisons', 1 if !$can_compress;
+ ok($ic = $imap_client->new(%mic_opt), 'uncompressed logged in');
+ ok($ic && $ic->compress, 'compress enabled');
+ ok($ic->examine($mb), "EXAMINE $mb");
+ my $raw = $ic->get_envelope($uidnext);
+ is_deeply($envl, $raw, 'raw and compressed match');
+ }
+}
+
$td->kill;
$td->join;
is($?, 0, 'no error in exited process') if !$ENV{TEST_KILL_IMAPD};
#!perl -w
-# Copyright (C) 2017-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>
use strict;
use v5.10.1;
like($res->content, $mid_re, 'found mid in response');
chop($digits);
}
+ $res = $cb->(GET("/test/$mid/"));
+ $html = $res->content;
+ like($html, qr/\bFrom: Ævar /,
+ "displayed Ævar's name properly in permalink From:");
+ unlike($html, qr/Ã/, 'no raw octets in permalink HTML');
$res = $cb->(GET('/test/'));
$html = $res->content;