On Fri 2010. May 14 15:06:20, RJBS wrote:
Show quoted text> my $json = q[{"subject":"Les Cr\u00e9ations de La Plata VOUS invite
> \u00e0 l'exposition de
> design Puro Dise\u00f1o"}];
We’ve had a patch for this in UHU-Linux in our Perl package for a while,
I think. I’ve just ported it to 5.12.2 and I hope it still does what it
should. I took your string as an example and here’s the result:
$ perl -MEncode -Mutf8 -e 'print encode("MIME-Q", "Les Cr\x{00e9}ations
de La Plata VOUS invite \x{00e0} l'"'"'exposition de design Puro
Dise\x{00f1}o"), "\n"'
=?UTF-8?Q?Les=20Cr=C3=A9ations=20de=20La=20P?=
=?UTF-8?Q?lata=20VOUS=20invite=20=C3=A0=20l?='
=?UTF-8?Q?exposition=20de=20design=20?= =?UTF-8?Q?Puro=20Dise=C3=B1o?=
(Gotta love shell escapes for that apostrophe.)
I’ll attach the patch, and I hope it’s of some use.
diff -Naurdp perl-5.12.2/cpan/Encode/lib/Encode/MIME/Header.pm perl-5.12.2-ืmime-header/cpan/Encode/lib/Encode/MIME/Header.pm
--- perl-5.12.2/cpan/Encode/lib/Encode/MIME/Header.pm 2010-09-05 17:14:32.000000000 +0200
+++ perl-5.12.2-ืmime-header/cpan/Encode/lib/Encode/MIME/Header.pm 2010-09-15 22:29:54.000000000 +0200
@@ -127,11 +127,12 @@ sub encode($$;$) {
for my $word (@word) {
use bytes ();
if ( bytes::length($subline) + bytes::length($word) >
- $obj->{bpl} )
+ $obj->{bpl} - 1 )
{
push @subline, $subline;
$subline = '';
}
+ $subline .= ' ' if ($subline =~ /\?=$/ and $word =~ /^=\?/);
$subline .= $word;
}
$subline and push @subline, $subline;
diff -Naurdp perl-5.12.2/cpan/Encode/t/mime-header.t perl-5.12.2-ืmime-header/cpan/Encode/t/mime-header.t
--- perl-5.12.2/cpan/Encode/t/mime-header.t 2010-09-05 17:14:32.000000000 +0200
+++ perl-5.12.2-ืmime-header/cpan/Encode/t/mime-header.t 2010-09-15 22:31:58.000000000 +0200
@@ -74,8 +74,8 @@ EOS
my $bheader =<<'EOS';
From:=?UTF-8?B?IOWwj+mjvCDlvL4g?=<dankogai@dan.co.jp>
-To: dankogai@dan.co.jp (=?UTF-8?B?5bCP6aO8?==Kogai,=?UTF-8?B?IOW8vg==?==Dan
- )
+To: dankogai@dan.co.jp (=?UTF-8?B?5bCP6aO8?==Kogai,=?UTF-8?B?IOW8vg==?==
+ Dan)
Subject:
=?UTF-8?B?IOa8ouWtl+OAgeOCq+OCv+OCq+ODiuOAgeOBsuOCieOBjOOBquOCkuWQq+OCgA==?=
=?UTF-8?B?44CB6Z2e5bi444Gr6ZW344GE44K/44Kk44OI44Or6KGM44GM5LiA5L2T5YWo?=
@@ -123,6 +123,6 @@ is(Encode::encode('MIME-Q', "\x{fc}"), '
my $rt42627 = Encode::decode_utf8("\x{c2}\x{a3}xxxxxxxxxxxxxxxxxxx0");
is(Encode::encode('MIME-Q', $rt42627),
- '=?UTF-8?Q?=C2=A3xxxxxxxxxxxxxxxxxxx?==?UTF-8?Q?0?=',
+ '=?UTF-8?Q?=C2=A3xxxxxxxxxxxxxxxxxxx?= =?UTF-8?Q?0?=',
'MIME-Q encoding does not truncate trailing zeros');
__END__;