Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

(dkubb) Re: (2) Evaluation of Simple Pop3 Client

by dkubb (Deacon)
on Mar 25, 2001 at 01:52 UTC ( [id://66909]=note: print w/replies, xml ) Need Help??


in reply to Evaluation of Simple Pop3 Client

Had your question been regarding "how do I parse HTML using a regular expression?", you would have been bombarded with a chorus of people saying "don't do that, use a module like HTML::Parser or it's derivatives". And in most cases they would be right. =) Why bother to reinvent parsing routines that someone else has done, and thousands of people use, and test, every day?

I'm going to give you the same advice for your project, don't parse an email message using a regex. Instead, use some of MailTools's CPAN modules to parse the message headers and body for you.

Here's your example re-worked to use the Mail::Internet module:

#!/usr/bin/perl -w use strict; use Net::POP3; use Mail::Internet; use constant POP3_SERVER => '10.10.10.10'; use constant USERNAME => 'username'; use constant PASSWORD => 'password'; my $pop3 = Net::POP3->new(POP3_SERVER) or die 'Could not open a POP3 connection'; $pop3->login(USERNAME, PASSWORD) or die 'Could not login'; my $messages = $pop3->list; foreach my $msg_num (keys %$messages) { my $mail = Mail::Internet->new( $pop3->get($msg_num) ); foreach my $header (qw(Date Message-Id From To Cc Subject)) { print "$header: ", $mail->get($header) if defined $mail->get($header); } #Get the message body, and possibly do something with it my $body = join '', @{$mail->body}; } $pop3->quit;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://66909]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-24 11:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found