Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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:

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:

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 (I assume) 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.


In reply to UTF8 issue with Net::POP3 by chuntuk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-28 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found