×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

UTF8 Issue with Net::POP3

UTF8 Issue with Net::POP3

UTF8 Issue with Net::POP3

(OP)
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

RE: UTF8 Issue with Net::POP3

The part between =?utf-8?B? and ?= is base64 encoded. You can use the MIME::Base64 module to decode it.

Annihilannic
tgmlify - code syntax highlighting for your tek-tips posts

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close