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
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.