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 편안한 가&#44396 +;에서 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.


  1. #!/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"; }
  2. #!/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


In reply to Putting a utf-8 subject into a mail header by talexb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.