?
Solved

Decoding UTF-8 in an e-mail

Posted on 2009-02-12
2
Medium Priority
?
786 Views
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 Encode.pm module but I just can't get it to work.
Help!
0
Comment
Question by:inscribble82
2 Comments
 
LVL 39

Accepted Solution

by:
Adam314 earned 2000 total points
ID: 23624948
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

0
 

Author Comment

by:inscribble82
ID: 23630748
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!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Six Sigma Control Plans
Suggested Courses

839 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