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

Hi,

I'm trying to decode an email body, with stuff like:

=C2=A0 *Email:*=C2=A0 =C2=A0=C2=A0

I'm trying to use this module:

https://metacpan.org/pod/MIME::Words

But it doesn't seem to want to work for me :(

my $message = q|testing a reply *Do it as *html=C2= =A0I guess Andy Newby=C2=A0 *Email:*=C2=A0 =C2=A0=C2=A0 andy@xx.co.u +k =C2=A0 * WWW: =C2=A0 =C2=A0=C2=A0 * http://www.xx.co.= uk =C2=A0 Mobile:=C2=A0* = =C2=A002269 201 576 =C2=A0=C2=A0 |; use MIME::Words qw(:all); my $test = decode_mimewords($message); print "FOO: $test \n";


All I get outputted, is the exact same input. Could someone please advise on how I can do this? (I've never really dabbled with reading emails before, so this is a bit new to me)

Thanks

Andy

Replies are listed 'Best First'.
Re: Decoding an email body, into utf8
by hippo (Archbishop) on Jul 22, 2016 at 13:29 UTC

    I think what you might be after is MIME::QuotedPrint. Here's your test re-written with that in mind:

    #!/usr/bin/env perl use strict; use warnings; use MIME::QuotedPrint; my $message = q|testing a reply *Do it as *html=C2= =A0I guess Andy Newby=C2=A0 *Email:*=C2=A0 =C2=A0=C2=A0 andy@xx.co.u +k =C2=A0 * WWW: =C2=A0 =C2=A0=C2=A0 * http://www.xx.co.= uk =C2=A0 Mobile:=C2=A0* = =C2=A002269 201 576 =C2=A0=C2=A0 |; my $test = decode_qp($message); print "FOO: $test \n";

    Does this give the output you were after?

      Hi,

      Thanks - that kinda works :)

      The output I'm getting now in SSH, is:

      FOO: testing a reply *Do it as *html     I guess Andy Newby  *Email:*     andy@xx.co.uk   * WWW:      * http://www.xx.co.    uk   Mobile: *      07769 201 576    Thanks

      Andy

        And what output do you expect? It would help to see this in the form of a test eg. How to ask better questions using Test::More and sample data

        Note that you will need a utf-8 capable terminal and have the correct locale set in order to view utf-8 data (which the output appears like it might be).

        (updated: added link to test example)