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 ?" } }


In reply to Net::POP3 and Mail::POP3Client Weirdness - argh! by frostman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.