I am writing a POP3 Client program in Perl but can't figure out how to split up the e-mail messages required in "List Messages" in Menu Option 1 of my program to display a list of the messages displaying ONLY the message number, who the message is from and the subject. I am not displaying the entire text of the message in Option 1.

Here is the code for the program so far:
#!/usr/bin/perl -w use strict; use IO::Socket qw(:DEFAULT :crlf); my $host = shift || 'pop3.isp.ca'; my $port = shift || '110'; # port 110 for POP3 my $socket = IO::Socket::INET->new(PeerAddr => $host, PeerPort => $port) or die "no sock $!"; my $choice; # line 10 my $answer; my $username; my $mypass; my $msgnum; my $msgcount = 0; $username = "x9xxxx99"; # format masks for user name $mypass = "99xxx9x9"; # and password of ISP log-in print $mypass; $answer = <$socket>; print "$answer\n"; # send username, pass print $socket "user " . $username,CRLF; $answer = <$socket>; print $socket "pass " . $mypass,CRLF; $answer .= <$socket>; print "$answer\n"; #line 30 system("cls"); print "=======================================================\n"; print "POP3 Mail Client you have " . $msgcount. "messages waiting.\n"; print "======================================================="\n; while (1) { # menu print " 1 List Messages\n"; print " 2 Display body\n"; print " 3 Display header and body\n"; print " 4 Write message to a file\n"; print " 5 Delete message on the server\n"; print " 6 Quit\n\n"; print "Enter choice: "; chomp ($choice = <STDIN>); # option 1 selected- List all messages (message # number, who it is from and subject of the message) if ($choice =~ /^1$/) { print $socket "LIST",CRLF; $answer = <$socket>; print "$answer\n\n"; if ($msgcount > 0) { for (my $i = 0; $i < $msgcount; $i++) { print "\n\n"; $msgnum = $i; print $socket "RETR ".$msgnum,CRLF; $answer = <$socket>; if ($answer =~ /^\-ERR/) { print "Messages could not be displayed"; } else { while (1) { # regular expression to list messages # with message number, from and subject /^(From|Subject):\s+/i and print $_, "\n"; } print "\n"; } else { print "\n\nYou currently have no messages."; <STDIN>; next; } next; } if ($choice =~ /^2$/) { # print "\nPlease enter message number: "; # chomp($msgnum = <STDIN>); # print $socket "RETR ".$msgnum,CRLF; # $answer = <$socket>; # if ($answer =~ /^\-ERR/) { # print "Error: invalid message number"; # <STDIN>; # next; # } # else { # } next; } if ($choice =~ /^6$/) { print $socket "QUIT",CRLF; $answer = <$socket>; print "$answer\n"; print "exiting\n" and last; } }
Can someone also tell me for Option 3 where I need to display the header and body of the e-mail based on the message number typed in by the user how I can differentiate between the header and body of each message using regular expressions? I should also point out that I am prohibted from using any of the Net::POP3 Perl modules or POP3Mail Perl modules to complete this so I need to use regular expressions and the IO::Socket Perl module only.

Anyone who can give me some assistance on this problem would be greatly appreciated by me. Thanks.

Edit: g0n - readmore tags


In reply to 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.