talexb has asked for the wisdom of the Perl Monks concerning the following question:
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
When I try to encode the same thing at the command line using my encode script (1), I getSubject: XYZ =?UTF-8?B?7Y647JWI7ZWcIOqwgOq1rOyXkOyEnCBCTkMg6rOE7KCVIO2 +ZnOyEsQ==?= =?UTF-8?B?7ZmU?=
Different. That's puzzling.talexb@foo:~/bin$ encode "XYZ 편안한 가구 +;에서 BNC 계정 활성화" =?UTF-8?B?WFlaIMOtwo7CuMOswpXCiMOtwpXCnCDDqsKwwoDDqsK1wqzDrMKXwpDDrMK +EwpwgQk5DIMOqwrPChMOswqDClSDDrcKZwpzDrMKEwrHDrcKZwpQ=?=
Using the decode (2) script on these two strings, first the Thunderbird encoding ..
.. I can see that Thunderbird's encoded string decodes nicely, but my encoded string does not:talexb@foo:~/bin$ decode =?UTF-8?B?7Y647JWI7ZWcIOqwgOq1rOyXkOyEnCBCTkM +g6rOE7KCVIO2ZnOyEsQ==?= =?UTF-8?B?7ZmU?= 편안한 가구에서 BNC 계 +정 활성 화
Please help me to understand why Thunderbird's encoding works but my version using Encode does not.talexb@foo:~/bin$ decode =?UTF-8?B?WFlaIMOtwo7CuMOswpXCiMOtwpXCnCDDqsK +wwoDDqsK1wqzDrMKXwpDDrMKEwpwgQk5DIMOqwrPChMOswqDClSDDrcKZwpzDrMKEwrHD +rcKZwpQ=?= XYZ í¸ìí ê°êµ¬ìì BNC ê³ì íì±í
#!/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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Putting a utf-8 subject into a mail header
by Anonymous Monk on Feb 27, 2009 at 15:23 UTC | |
by talexb (Chancellor) on Feb 27, 2009 at 15:27 UTC | |
by Anonymous Monk on Feb 27, 2009 at 15:45 UTC | |
by talexb (Chancellor) on Feb 27, 2009 at 16:00 UTC | |
by mr_mischief (Monsignor) on Feb 27, 2009 at 18:13 UTC | |
by almut (Canon) on Feb 27, 2009 at 15:57 UTC | |
by talexb (Chancellor) on Feb 27, 2009 at 16:09 UTC | |
by Anonymous Monk on Feb 27, 2009 at 16:00 UTC |