perl-unicode

Re: Encode the subject line in MIME header using Perl 5.6

2005-12-29 17:13:09

At 11:44 am +0800 28/12/05, wing wrote:

> Thanks for your prompt reply. The subject line contains some Chinese or > Japanese characters in UTF8. Can they be encoded as UTF8 with MIME:Base64??

The script below creates a file containing the following 4 characters

      谷神不死

as utf8 bytes \xE8\xB0... etc. All you have to do is QP or Base64 encode those 12 bytes.

#!/usr/bin/perl
use utf8;
use MIME::Base64;
use MIME::QuotedPrint;
open FOUT, ">/tmp/f" or die $!;
print FOUT "\xE8\xB0\xB7\xE7\xA5\x9E\xE4\xB8\x8D\xE6\xAD\xBB";
close FOUT;
open FIN, "</tmp/f" or die $!;
$_ = <FIN>;
s~[\012\015]*~~;
$base64 = encode_base64 ($_, '');
$qp = encode_qp ($_, '');
print "=?UTF-8?B?$base64?=" . $/;
print "=?UTF-8?Q?$qp?=" . $/;

JD