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

Hi I have access to my email account using net::pop3 and it works fine. I would like to use mail::pop3client instead, but I get a -1 returned from the count function.
my $pop3 = new Mail::POP3Client( USER => 'xx', PASSWORD => 'xx', HOST +=> 'xx' ) or die "$!"; $num = $pop3 -> Count(); print $num;
Is there a logic reason for this? Regards kristian@detandetfirma.dk

edited: Wed Jun 25 13:33:04 2003 by jeffa - code tags

Replies are listed 'Best First'.
Re: Strange result using Mail::POP3Client
by BrowserUk (Patriarch) on Jun 25, 2003 at 08:14 UTC

    Your or die "$!" clause on your call to new is a waste of time as the module returns an object regardless of whether the attempt to connect was successful or not.

    You need to call $pop3->Message to find out if any errors occured.

    -1 is the initial value of Count. If the connection failed to occur, it would still have that value.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


Re: Strange result using Mail::POP3Client
by tachyon (Chancellor) on Jun 25, 2003 at 10:26 UTC

    Webmail::vPOP3 is a superclass of Mail::POP3Client in this example which shows the error handling you need as pointed out by BrowserUK ie check $obj->Message for either OK or ERR...

    sub open_pop3_connection { my $pop = new Webmail::vPOP3 ( mailroot => $USE_MAILROOT, pop3_init => { USER => $global{username}, PASSWORD => $global{password}, HOST => $POP_SERVER, AUTH_MODE => $POP_AUTH_MODE }, cwd => $global{cwd}, default_folders => { inbox => $INBOX, drafts => $DRAFTS, deleted => $DELETED, sent => $SENT, }, delim => $DELIM, debug => 0, folder_icons => "$IMAGE_LOCATION/folder_icons", Lplus => \&Webmail::Lplus, Lminus => \&Webmail::Lminus, Tplus => \&Webmail::Tplus, Tminus => \&Webmail::Tminus, folder_msg_text => \&Webmail::folder_msg_text, file_msg_text => \&Webmail::file_msg_text, ); unless($pop->Message =~ m/^\+OK/){ ($pop->Message =~ m/ERR(.*)/) ? show_login("$CONNECTION_FAILED: $1") : show_login("$CONNECTION_FAILED:" . $pop->Message); } # reset the session time after a vaild login $global{last_active} = time(); return $pop; }

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      not really a solution to her problem, more like an advertisement for your own module.

        1) It is a solution ie check $obj->Msg as shown for either OK or ERR. Simply the explicit step required as alluded to by BrowserUK

        2) The module (actually an app wrapped around a lot of modules) is not publicly available either free or for sale, it is in house company code for our webmail system :-)

        So, not much of an ad but definitely a solution. Sure I cut and pasted the code and noted why it did not say Mail::POP3Client->new

        And?

        cheers

        tachyon

        s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print