bobano has asked for the wisdom of the Perl Monks concerning the following question:
#!/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; } }
Edit: g0n - readmore tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: POP3 Mail Client using IO::Socket module only
by jdtoronto (Prior) on Apr 11, 2006 at 05:55 UTC | |
|
Re: POP3 Mail Client using IO::Socket module only
by nferraz (Monk) on Apr 11, 2006 at 08:45 UTC | |
|
Re: POP3 Mail Client using IO::Socket module only
by bobano (Novice) on Apr 11, 2006 at 18:54 UTC |