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

Monks,

I'm having trouble with both Net::POP3 and Mail::POP3Client.

I think I'm doing everything "right" - see code at bottom. However...

With Net::POP3 I get strange errors in $!. As far as I could tell from available online docs, that's where it's putting error messages. For connection errors it seems fine, but on authentication errors I get weirdness: for example, when the POP3 server returns the error "-ERR Username/Password Mismatch perhaps foo@yourdomain.com ?" I get "Bad file descriptor" in $!.

I really need to capture this info.

Does anyone know a better/more reliable way to access the *actual* error return value from the POP3 server in Net::POP3?

Hoping it would be easier with Mail::POP3Client, which at least has Message(), I tried that... and found that I get a "Broken pipe" error if I try to connect to my *local* POP3 server, while it works fine if the server is remote.

I can work around that, since in this case I'm only checking external servers, but it seems very inelegant... and who knows, maybe I've even found a bug in Mail::POP3Client ;-)

Any pointers are much appreciated. For now I'm going to just have to use a workaround. :-(

(I'm running Perl 5.6.1 on RedHat7.2, and CPAN-installed these modules a few days ago.)

CODE SAMPLES:

Mail::POP3Client:

# POP3Client dies with "Broken pipe" and nothing else. # (works fine with external server) use strict; use Mail::POP3Client; my $pop3 = new Mail::POP3Client( HOST => "localhost" ); $pop3->User( "somebody" ); $pop3->Pass( "doublesecret" ); $pop3->Connect() || die "failed: " . $pop3->Message() . "\n"; $pop3->Close();

Net::POP3:

# Host is valid, user/pass are not. use strict; use Net::POP3; my $host = 'biztos.com'; # valid POP3 host, feel free to test against +it. my $user = 'foobar'; # nonexistent user my $pass = 'badpass'; # dummy password my $pop3 = Net::POP3->new($host,Timeout => 30,Debug => 1); die "connect failed: $!\n" unless $pop3; # this works fine. # try apop first: my $apop_messages = $pop3->apop($user,$pass); if ($apop_messages) { $pop3->quit(); print "apop ok.\n"; } else { print "apop didn't work, trying login ($!)\n"; # the above $! is "No such file or directory" # ...and debug didn't show anything, so I'm assuming # apop() just skipped it due to presumed incompatibility. # on my localhost it shows the apop transaction. my $pop_message = $pop3->login($user,$pass); if ($pop_message) { $pop3->quit(); print "login ok.\n"; } else { $pop3->quit(); die "login failed: $!\n"; # the above $! is "Bad file descriptor" but the # POP3 server said: # "-ERR Username/Password Mismatch perhaps foobar@yourdomain.c +om ?" } }

Replies are listed 'Best First'.
Re: Net::POP3 and Mail::POP3Client Weirdness - argh!
by Mr. Muskrat (Canon) on Apr 17, 2003 at 17:18 UTC

    What about this?

    use strict; use Mail::POP3Client; my $pop3 = new Mail::POP3Client(); # default is localhost $pop3->User( "somebody" ); $pop3->Pass( "doublesecret" ); $pop3->Connect() || die "failed: $pop3->Message()\n"; $pop3->Close();
    or this:
    use strict; use Mail::POP3Client; my $pop3 = new Mail::POP3Client( HOST => 'biztos.com' ); $pop3->User( "somebody" ); $pop3->Pass( "doublesecret" ); $pop3->Connect() || die "failed: $pop3->Message()\n"; $pop3->Close();

    Update: I seem to recall having issues with the Connect method. Another thing you might try is:

    use strict; use Mail::POP3Client; my $pop3 = new Mail::POP3Client(); # with & without the host $pop3->User( "somebody" ); $pop3->Pass( "doublesecret" ); $pop3->Connect(); if ($pop3->Alive()) { # connection established } else { # no connection } $pop3->Close();

    2nd Update: The first two fail for me but the third works. I think that Mail::POP3Client has a bug in the Connect method now.

    3rd Update: I downloaded the latest version of Mail::POP3Client from CPAN (AS had a very old version). Now all three work for me.

      using any of the above examples where the Connect() is called gives me an Use of uninitialized value in concatenation (.) or string at /usr/lib/perl5/site_perl/Mail/POP3Client.pm line 425 error. Have downloaded and am using the latest from CPAN. HELP Please...

        What version of Mail::POP3Client do you have?
        On Windows: perl -le "eval \"require $ARGV[0]\" and print $ARGV[0]->VERSION" Mail::POP3Client
        On *nix: perl -le 'eval "require $ARGV[0]" and print $ARGV[0]->VERSION' Mail::POP3Client

Re: Net::POP3 and Mail::POP3Client Weirdness - argh!
by zentara (Cardinal) on Apr 18, 2003 at 15:30 UTC
    This just worked for me: linux, perl5.8
    #!/usr/bin/perl use Mail::POP3Client; $pop = new Mail::POP3Client(USER => "zentara", PASSWORD => "bigsecret", HOST => "mail.whereever.com" ); for( $i = 1; $i <= $pop->Count(); $i++ ) { foreach( $pop->Head( $i ) ) { /^(From|Subject):\s+/i && print $_, "\n"; } } $pop->Close();