Mar 12, 2011, 6:33 PM
Post #1 of 2
MAIL::IMAPClient slow or fails connect
I'm trying to write an email mailbox manager, using MAIL::IMAPClient.
This is new undertaking for me, so could be newbie question tho I couldn't find anything in forum, but here's the deal.
Writing in linux (MEPIS 8.5). I have the routine running, using examples I found online - but the connection step is either slow (~30 secs) but successful, or just hangs, then after more time than I ever waited around to see, returns with:
login() Socket closed while reading data from server
Here's pertinent code:
use AppConfig qw/:argcount/;
# Connect to the IMAP server via SSL and get rid of server greeting message
my $socket = IO::Socket::SSL->new(
PeerAddr => $config->HOST,
PeerPort => $config->PORT,
or die "socket(): $@";
my $greeting = <$socket>;
my ($id, $answer) = split /\s+/, $greeting;
die "problems logging in: $greeting" if $answer ne 'OK';
# Build up a client attached to the SSL socket and login
### Fails on the following step. Sometimes it works, but
### takes the 30 seconds. In this case, the program can
### successfully access the mailboxes
### Often, this step just hangs as described in intro above.
my $client = Mail::IMAPClient->new(
Socket => $socket,
User => $config->USER,
Password => $config->PASSWORD,
Port => $config->PORT,
or die "new(): $@";
$client->login() or die 'login(): ' . $client->LastError();
Any help or advice on better approach would be much appreciated.