in reply to How to check number of messages using Net::POP3?

Have you tried to use the login method to login to your POP3 Mail account. The return value is the number of messages in the mailbox, and undef if login fails.

#!/usr/bin/perl use strict; use warnings; use diagnostics; use Net::POP3; use Term::ReadKey; # Read the mail accounts from a file called addresses # which resides in the script's directory open ADDRESSES, "./addresses"; # read all the lines my @addys = <ADDRESSES>; # close address file close ADDRESSES; # do the following for every address foreach my $address (@addys) { # split address into username and hostname my ($user, $host) = $address =~ /(\S+)\s(\S+)/; # let the user enter his password print "Please enter the password for $user\@$host\:"; ReadMode( "noecho" ); my $pass = ReadLine(); ReadMode( "normal" ); print "\n"; # connect to host my $pop = Net::POP3->new( $host ) or do { print "Could not initialize connection.\n"; next; }; print "Connected to $host.\n"; # send USER my $msg_count = $pop->login( $user, $pass ) or do { print "Could not login.\n"; next; }; # print number of msg or complain about failed login if (defined $msg_count) { $pop->quit(); print "Messages: $msg_count\n"; } else { print "Login failed.\n"; } }

Replies are listed 'Best First'.
Re: Re: How to check number of messages using Net::POP3?
by BjoernD (Initiate) on Dec 23, 2003 at 23:19 UTC
    Yes I did. Didn't improve either. If you have a look in Net/POP3.pm you see that login only calls user() and pass() after each other.
      You could use the Data::Dumper module to do some inspection for you...

      use Data::Dumper; ... my $msg_count = $pop->login( $user, $pass ) or do { print "Could not login.\n"; next; }; print Dumper($msg_count);
      and see if the returned value is truly undef or not.