Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UTF8 Issue with Net::POP3

Status
Not open for further replies.

ChrisHunt

Programmer
Jul 12, 2002
4,056
GB
I'm trying to read the "from" and "subject" fields from the messages in a POP3 mailbox (I don't care about the content of the messages), and have cobbled together the following code from online examples:
Code:
use Net::POP3;

# $MAILSERVER,$MAILUSER,$MAILPASS defined here!

# Constructors
$pop = Net::POP3->new($MAILSERVER);

if ($pop->login($MAILUSER, $MAILPASS) > 0) {
   my $msgnums = $pop->list; # hashref of msgnum => size
   foreach my $msgnum (keys %$msgnums) {
     my $head = $pop->top($msgnum,0);
     my ($subject, $from) = analyze_header($head);

     print "From: $from ; Subject: $subject \n";
   }
}
$pop->quit;
print "done.\n";

sub analyze_header {
  my $header_array_ref = shift;

  my $header = join "", @$header_array_ref;

  my ($subject) = $header =~ /Subject: (.*)/m;
  my ($from   ) = $header =~ /From: (.*)/m;

  return ($subject, $from);
}
It works, insofar as it successfully logs in and reads the (two identical) messages, but this is the output I get:
Code:
starting...
From: "=?utf-8?B?Q2hyaXMgSHVudA==?=" <chris@example.com> ; Subject: =?utf-8?B?VGVzdA==?= 
From: "=?utf-8?B?Q2hyaXMgSHVudA==?=" <chris@example.com> ; Subject: =?utf-8?B?VGVzdA==?= 
done.
The contents of the header fields appear to be encoded somehow into utf-8, but how do I decode it into something I can make sense of? I assume there must be some standard method of doing this, but none of the documentation I could find gives me any help.


-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
The part between =?utf-8?B? and ?= is base64 encoded. You can use the MIME::Base64 module to decode it.

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top