in reply to Re^3: Decoding an email body, into utf8
in thread Decoding an email body, into utf8

Mmmm actually, that doesn't work in some cases:

my $name = "From: =?UTF-8?B?QW5keSBOZXdieSDDrcOpw7M=?= <andy\@cham +bresdhotesfrance.com>"; use MIME::QuotedPrint; if ($name =~ /utf-8|utf8/i) { $name= decode_qp($name); $name =~ s/([\200-\377]+)/from_utf8({ -string => $1, -charset +=> 'ISO-8859-1'})/eg; } print $IN->header; print "NOW: $name";

Prints out:

NOW: From: =?UTF-8?B?QW5keSBOZXdieSDDrcOpw7M=?= 
...instead of what I was expecting:

Andy Newby νσι

This is a valid email header passed through from Thunderbird. Any ideas why it won't decode?

Cheers

Andy

Replies are listed 'Best First'.
Re^5: Decoding an email body, into utf8
by ultranerds (Hermit) on Jul 27, 2016 at 05:42 UTC

    Interesting. Just found a post on StackOverflow, where someone suggested using decode_base64 to decode it. And that seems to work:

    my $name = "=?UTF-8?B?QW5keSBOZXdieSDDrcOpw7M=?="; use MIME::Base64; $name =~ s|\Q=?UTF-8?B?||i; $name = decode_base64($name); $name =~ s/([\200-\377]+)/from_utf8({ -string => $1, -charset => ' +ISO-8859-1'})/eg;

    I wonder why the other module doesn't work?

    Cheers

    Andy
      RFC 2047, section 4 says it. The "?B?" part tells you to use base 64, while "?q?" means "quoted-printable".

      Since you already know CPAN: search term is rfc 2047