I am close to getting all of the messages in the mailbox listed with their message number, who the message is from and the subject but it is messing up and giving me ALL the header information of the message even though I only want the message number defined in the program as well as the "From" and "Subject" fields. It also seems to be only displaying the header info for one of the messages which means something is faulty with the "for" loop that I created that should work because someone else showed me how to arrange that. Here is my updated code for Option 1 "List Messages":
if ($choice =~ /^1$/) { print $socket "STAT",CRLF; $answer = <$socket>; print "$answer\n\n"; if ($answer =~ /^\+OK\s(\d{1,}).*/) { $msgcount = $1; print "You have " . $msgcount . " messages"; } if ($msgcount > 0) { for (my $i = 0; $i < $msgcount; $i++) { print $socket "STAT",CRLF; $answer = <$socket>; print "$answer\n\n"; $msgnum = $i; print "Message Number: " . $msgnum; print $socket "RETR " . $msgnum,CRLF; $answer = <$socket>; if ($answer =~ /^\-ERR/) { print "ERROR"; } else { # these are regular expressions to parse # out and display only the From and Subject # fields from the message header # information which I get using the RFC # 1939 protocol and I backreference the # expressions with "$1" and "$2" scalar # variables if ( $answer =~ /^From:(.*)/ ) { print "From: $1\n"; } if ( $answer =~ /^Subject:(.*)/ ) { print "Subject: $2\n"; } } print "\n"; } } else { print "\n\nYou currently have no messages."; <STDIN>; next; } next; }
If anyone has any suggestions for how to fix this or attempt to clean it up, it would be greatly appreciated. I DO NOT expect people to start writing the code for me. I just want a few snippets here and there of things that any of you think I may be missing or things that I need to include. Once, I get one part working with the regular expressions, I can easily get the others going because Option 2 is similar to Option 1 except I parse out the body of the message using a regular expression and Option 3 is just displaying both header and body which is everything I parsed out in Option 1 for the header (message number, from, subject) and Option 2 (body of the message). I'm also gambling on the fact that people actually know a lot about socket programming and communicating with a POP3 server using the RFC 1939 protocol but it's a chance I am willing to take. I printed out the RFC 1939 protocol and understand how the RFC commands work but it's just parsing it to display just a particular portion that is throwing the program off.

Thanks.

In reply to Re: POP3 Mail Client using IO::Socket module only by bobano
in thread POP3 Mail Client using IO::Socket module only by bobano

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.