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;

In reply to (dkubb) Re: (2) Evaluation of Simple Pop3 Client by dkubb
in thread Evaluation of Simple Pop3 Client by Jamnet

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.