I tried to decode a MIME-encoded message with MIME::Tools, and got the body decoded from quoted-printable to bytes and accessible via MIME::Body methods. To get the unicode characters I needed to do one more decoding step and decode my message body from bytes to characters using Encode module.

Approaching your example,

use MIME::Decoder; use Encode 'decode'; # only for this particular case I will decode QP manually my $d = new MIME::Decoder 'quoted-printable'; # usual way of obtaining bytes decoded from # QP/Base64/7bit/other content-transfer-encodings # is to use MIME::Body methods # encode unicode characters to UTF-8 on printing binmode STDOUT, ":utf8"; # open an in-memory filehandle # since MIME::Decoder only supports filehandles open my $fh, ">", \(my $bytes); # decode the quoted-printable $d->decode(\*DATA, $fh); # decode the bytes my $characters = decode 'utf-8' => $bytes; # prove having 1 character, not 4 bytes while ($characters =~ /(.)/g) { printf "%s is unicode character %x\n",$1,(unpack"W",$1); } __DATA__ =F0=9F=98=B3
� is unicode character 1f633
my terminal font doesn't have emoji, so it showed � instead

More info at perlopen, Encode, perlunitut, perluniintro, perlunifaq.


In reply to Re^3: Quoted Printable to Unicode or something by aitap
in thread Quoted Printable to Unicode or something by rethaew

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.