I'm trying to write a a perl program to login to a pop3 server and do a RETR for my messages and return each individual message into a file. Example..Message 1 would go in the file message1, message 2 would go in the file message2,etc...What I have working so far is to authenticate, get the number of messages I have and that's it. I have no clue how to return the messages to me properly...here is my code..
#!/usr/bin/perl -w
use IO::Socket;
use strict;
my $EOL = "\015\012";
my $BLANK = $EOL x 1;
my $username = "brice";
my $password = "mypassword";
my $count = 0;
my @mailstat;
my $remote = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => "localhost",
PeerPort => "pop3(110)",
)
or die "cannot connect to daytime port at localhost";
$remote->autoflush(1);
print $remote "USER $username" . $BLANK;
print $remote "PASS $password" . $BLANK;
print $remote "QUIT" . $BLANK;
while ( <$remote> ) {
if (/lock busy/) {
die "Session already in use!\n";
}
if (/OK $username has/) {
@mailstat = split(/ /);
}
}
if ($mailstat[3] eq "0") {
print "You have no messages.\n";
}
The thing that I have figured out as a start to getting the messages would be...
for ($count = $mailstat[3]; $count > 0; $count--) {
print $remote "RETR $count" . $BLANK;
#then do something with the data here. ????
}
I would appriciate any help. Thanks to all the monks.
Ben Rice