view raw
kagali-san kagali-san - 8 months ago 42
Perl Question

Perl/MIME encoded text trouble

I have a MIME-encoded messages (in Maildir), that are having both base64-encoded headers (solved by lurking for related question ( ), decode('MIME-Header', $val), main body in plain text and a text/plain base64 encoded data in the body;

It is said, that base64 data is encoded in utf-8.
However, when I do:

use MIME::Base4;
$decoded = decode_base64($block_from_line_array); # MIME body extracted from message's
$msgtext .= $decoded;
print decode('utf-8', $msgtext);

It seems that the block is decoded incorrectly.

print decode('utf-8', $msgtext); works ok, when message body is in utf-8


X-Priority: 3
X-Mailer: PHPMailer ( [version 2.0.4]
X-MessageID: 140
MIME-Version: 1.0
Content-Type: multipart/alternative;

<Here the body begins -- mhambra>
Content-Type: text/plain; charset = "utf-8"
Content-Transfer-Encoding: base64

Message is known to be displayed correctly in GMail.


Use a module like Email::MIME to do the hard work.

use strict;
use warnings;
use Email::MIME;

my $msg = Email::MIME->new($message_text);
print $msg->body;