The following should work, no matter what encoding was used by the source string.
MIME::WordDecoder->default(MIME::WordDecoder->supported("UTF-8"));
$subj = decode('UTF-8', unmime($subj));
Update: ug! Don't use MIME::WordDecoder. After looking at its guts, I'd recommend the snippet I presented earlier (packaged as a reusable function below). I think this toolkit predates the addition of UNICODE support to Perl. That would explain why the weird and convoluted interface.
use MIME::Words qw( decode_mimewords );
use Encode qw( decode );
sub mime_decode {
my $decoded = '';
foreach (decode_mimewords($_[0])) {
my ($data, $charset) = @$_;
if (defined($charset)) {
$decoded .= decode($charset, $data);
} else {
$decoded .= $data;
}
}
return $decoded;
}
$subj = mime_decode($subj);
Untested
|