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

When connecting to a pop3 server using Net::POP3, how do you determine whether a login failure is from a bad password or from an empty mailbox? Neither of these errors pass anything to "$!".

Replies are listed 'Best First'.
Re: Using POP3
by ChemBoy (Priest) on Jul 13, 2001 at 02:39 UTC

    In general, $! will not be set by routines that don't involve interaction with the local OS--hence the alternate name for it (if you use English;), $OS_ERROR. Many people do set $@ ($EVAL_ERROR) in subroutines where printing a warning to STDERR is not appropriate.

    However, in this case, you needed to read the documentation a little more closely:

    login ( [ USER [, PASS ]] )

    Send both the the USER and PASS commands. If PASS is not given the Net::POP3 uses Net::Netrc to lookup the password using the host and username. If the username is not specified then the current user name will be used. Returns the number of messages in the mailbox. However if there are no messages on the server the string "0E0" will be returned. This is will give a true value in a boolean context, but zero in a numeric context.

    If there was an error authenticating the user then undef will be returned.

    Testing to see if your call returned undef or 0E0 is left as an exercise to the reader. :-)



    If God had meant us to fly, he would *never* have give us the railroads.
        --Michael Flanders

Re: Using POP3
by Zaxo (Archbishop) on Jul 13, 2001 at 02:47 UTC

    From 'man Net::POP3':

    [login] Returns the number of messages in the mailbox. However if there are + no mes- sages on the server the string `"0E0"' will be returned. This is wi +ll give a true value in a boolean context, but zero in a numeric context. If there was an error authenticating the user then undef will be re +turned.

    After Compline,
    Zaxo

An Example...
by Anonymous Monk on Jul 13, 2001 at 02:46 UTC