I'm trying to put a Korean subject line into an E-Mail that I sending using a Perl module, and I'm not having much success. The body of the E-Mail is Korean, and it's coming out just fine, but I am stuck on getting the Korean subject line to come out right.
I'm running Kubuntu 8.10, and I have Perl 5.8.8, so it's a relatively recent build. Brother clinton was kind enough to point me towards the Encode module, and it seemed to do the right type of thing, but after some further testing, isn't really.
My Sample string is 'XYZ Comfortable Furniture BNC account activation' which Google Translate assures me translates to 'XYZ 편안한 가구에서 BNC 계정 활성화'. When I put this is a subject line of an E-Mail in Thunderbird and send it to myself, it gets encoded into
Subject: XYZ =?UTF-8?B?7Y647JWI7ZWcIOqwgOq1rOyXkOyEnCBCTkMg6rOE7KCVIO2
+ZnOyEsQ==?=
=?UTF-8?B?7ZmU?=
When I try to encode the same thing at the command line using my encode script (1), I get
talexb@foo:~/bin$ encode "XYZ 편안한 가구
+;에서 BNC 계정 활성화"
=?UTF-8?B?WFlaIMOtwo7CuMOswpXCiMOtwpXCnCDDqsKwwoDDqsK1wqzDrMKXwpDDrMK
+EwpwgQk5DIMOqwrPChMOswqDClSDDrcKZwpzDrMKEwrHDrcKZwpQ=?=
Different. That's puzzling.
Using the decode (2) script on these two strings, first the Thunderbird encoding ..
talexb@foo:~/bin$ decode =?UTF-8?B?7Y647JWI7ZWcIOqwgOq1rOyXkOyEnCBCTkM
+g6rOE7KCVIO2ZnOyEsQ==?= =?UTF-8?B?7ZmU?=
편안한 가구에서 BNC 계
+정 활성 화
.. I can see that Thunderbird's encoded string decodes nicely, but my encoded string does not:
talexb@foo:~/bin$ decode =?UTF-8?B?WFlaIMOtwo7CuMOswpXCiMOtwpXCnCDDqsK
+wwoDDqsK1wqzDrMKXwpDDrMKEwpwgQk5DIMOqwrPChMOswqDClSDDrcKZwpzDrMKEwrHD
+rcKZwpQ=?=
XYZ í¸ìí ê°êµ¬ìì BNC ê³ì íì±í
Please help me to understand why Thunderbird's encoding works but my version using
Encode does not.
-
#!/usr/bin/perl -wC
# Encode to utf-8.
use Encode qw/encode/;
{
my @out;
foreach my $arg (@ARGV) {
push(@out, encode("MIME-Header",$arg));
}
print join(' ',@out) . "\n";
}
-
#!/usr/bin/perl -w
# Decode from utf-8.
use Encode qw/decode/;
{
my @out;
foreach my $arg (@ARGV) {
push(@out, decode("MIME-Header",$arg));
}
# See http://www.perlmonks.org/?node_id=742727 for why I've used
+binmode
# here.
binmode STDOUT, ':utf8';
print join(' ',@out) . "\n";
}
Alex / talexb / Toronto
"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds