Decoding UTF-8 in an e-mail

Posted on 2009-02-12
Last Modified: 2012-05-06
I am trying to extract data from an e-mail which is utf-8 encoded in perl

In particular I need to read the subject line:
Subject: =?utf-8?B?SU5WRU5UT1JZIERFUExFVEVE?=

I'm pretty sure that I need to use the module but I just can't get it to work.
Question by:inscribble82
    LVL 39

    Accepted Solution

    Your string doesn't look like utf-8.  It looks like base64, but with some extra stuff.  Here is a script that'll convert it.

    use MIME::Base64::Perl;
    my $Subject = '=?utf-8?B?SU5WRU5UT1JZIERFUExFVEVE?=';
    print "Subject: $Subject\n";
    $Subject = DecodeSubject($Subject);
    print "Subject: $Subject\n";
    sub DecodeSubject {
    	my $s=shift;
    	$s =~ s/^=\?utf-8\?B\?(.*)\?=$/$1/s;
    	return decode_base64($s);

    Open in new window


    Author Comment

    Works a treat. Thank you very much.

    I think I'm a bit confused between Character Sets and Encoding. I need to o a bit more reading!

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
    In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now