http://www.perlmonks.org?node_id=11117506

nysus has asked for the wisdom of the Perl Monks concerning the following question:

I'm using the Mail::IMAPClient module to fetch emails from my inbox. It works well, but after getting a good way through writing a wrapper for it, I discovered that it doesn't seem to handle UTF-8 encoded email headers that look something like this:

=?UTF-8?B?VHJ1ZUJsdWU=?= <jetblueairways@email.jetblue.com>

This example is a "From" header.

Maybe it's because the module didn't know about such things in 2003. At any rate, I tried the Encode::Simple module like this to try to clean things up:

$sender =~ s/^=\?utf-8//i; $sender =~ s/\?=//i; use Encode::Simple qw (decode_utf8); $sender = decode_utf8($sender);

My approach did not work, however. The string was unchanged. Further confusing me is that some headers look more like url encoding than utf8 encoding:

=?utf-8?Q?rePurpose=20Global?= <hello@repurpose.global>

So how do I properly handle these encoded headers?

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks