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

Seems like the problem is that the server after getting the wrong password closes the connection and this way $pop gets undefined?

No, you forget to quit and close the connection, which should be done even if there is a login failure. If you do quit and close the connection, the error message will be gone :) (just move it outside the if-statement)

# print number of msg or complain about failed login if (defined $a[0]) { print "Messages: $a[0]\n"; } else { print "Login failed.\n"; } $pop->quit();
--
b10m

Replies are listed 'Best First'.
Re: Re: How to check number of messages using Net::POP3?
by BjoernD (Initiate) on Dec 23, 2003 at 22:18 UTC
    This is unfortunately not the solution. Still get this error message when login fails. The message disappears if I do not use diagnostics;

      Ok, I have tested it on 3 machines now:

      1. Linux Debian
        • Perl v5.8.0
        • Net::POP3 v2.24

      2. Linux Slackware
        • Perl v5.6.0
        • Net::POP3 v2.23

      3. FreeBSD
        • Perl v5.8.0
        • Net::POP3 v2.24
      And got the following results:

      Machine Result
      1 Initially gave the same error message, but that got solved after moving $pop->quit() outside the if-statement.
      2 Initially gave the same error message, but that got solved after moving $pop->quit() outside the if-statement.
      3 Initially gave the same error message, but that got solved after moving $pop->quit() outside the if-statement.

      I tested your posted code verbatim first, and with my slight alteration afterwards. I did not take out the "use diagnostics;". So I am now curious what Perl and Net:POP3 versions you use. Oh, maybe it has anything to do with it, but I tested the script on a qpopper POP3 daemon, first with one line in "./addresses" and later with multiple lines.

      Update: now also tested with the "POP3 Server (Version 1.006d)" daemon, same result.

      --
      b10m
        My configuration:

        Linux Debian
        Perl v5.8.2
        Net::POP3 v2.24

        I still think that the problem is that the server disconnects after the failed login and I need a way to find out whether the connection is still alive before I quit.
Re: Re: How to check number of messages using Net::POP3?
by Roger (Parson) on Dec 23, 2003 at 22:55 UTC
    The quit method in Net::POP3 calls sub _QUIT, which is going to fail if the login fails. So calling quit on a failed login is a bad idea.

      Could you please explain this, for I don't understand it. quit works pretty good if you manually emulate a POP3 client:

      $ telnet *host* 110 Trying *host*... Connected to *host*. Escape character is '^]'. +OK *host* POP3 Server (Version 1.006d) ready at <Wed Dec 24 00:29:42 +2003> user *user* +OK please send PASS command pass invalidpass -ERR invalid usercode or password, please try again quit +OK *host* POP3 Server (Version 1.006d) shutdown. Connection closed by foreign host.
      --
      b10m
        This depends on how the POP3 server is configured though. If the server disconnects after invalid user/password is passed (as indicated by OP), then calling QUIT on a dropped connection is not going to do any good.