SeekerOfPerl has asked for the wisdom of the Perl Monks concerning the following question:

What is the correct way to implement the Net::POP3 ping() function?

I am trying to get the number of new / unread email messages.

The code below does not seem to work and results in the die message being returned.

use Net::POP3;

$pop = Net::POP3->new('mail.server.com');
$pop = Net::POP3->new('mail.server.com', Timeout => 60);

if ($pop->login('user@server.com', 'password') > 0) {

my @newmail = $pop->ping('user@server.com') || die "Couldn't Get Info\n";

print "POP PING RESULTS @newmail\n";

}
$pop->quit;


Thanks for the anticipated assistance.

Replies are listed 'Best First'.
Re: Net::POP3 ping() function
by marto (Cardinal) on Jun 17, 2008 at 15:32 UTC
    Is this your entire script? No use strict; or use warnings; Did you read the module documentation? Did you try the example that comes with the distribution (demos/pop3)? Why are you declaring $pop twice, once after the other, the difference being that the second declaration includes the Timeout option in the constructor? This looks like a copy and paste from the documentation, rather than reading the documentation and understanding what it is telling you. On this note, since you are having problems you could enable debugging:

    my $pop = Net::POP3->new('pop3host', Timeout => 60, Debug => 1);

    Are you sure the server in question supports pinging? Have you checked via the capabilities() method mentioned in the documentation?

    Perhaps taking a step back and rereading the documentation, and reading some of the basic tutorials here will help you.

    Please read How do I post a question effectively?, Writeup Formatting Tips and the PerlMonks FAQ.

    Martin
Re: Net::POP3 ping() function
by psini (Deacon) on Jun 17, 2008 at 15:25 UTC

    I think you are using it right, but you could want to add a call to $pop->capa() to see if your provider's POP3 supports ping (mine don't AFAICT).

    Careful with that hash Eugene.