use Carp;
use Net::Config;
-$VERSION = "2.22"; # $Id: //depot/libnet/Net/POP3.pm#19 $
+$VERSION = "2.23"; # $Id: //depot/libnet/Net/POP3.pm#22 $
@ISA = qw(Net::Cmd IO::Socket::INET);
@_ >= 1 && @_ <= 3 or croak 'usage: $pop3->login( USER, PASS )';
my($me,$user,$pass) = @_;
- if(@_ <= 2)
- {
- require Net::Netrc;
-
- $user ||= eval { (getpwuid($>))[0] } || $ENV{NAME};
-
- my $m = Net::Netrc->lookup(${*$me}{'net_pop3_host'},$user);
-
- $m ||= Net::Netrc->lookup(${*$me}{'net_pop3_host'});
-
- $pass = $m ? $m->password || ""
- : "";
- }
+ if (@_ <= 2) {
+ ($user, $pass) = $me->_lookup_credentials($user);
+ }
$me->user($user) and
$me->pass($pass);
@_ >= 1 && @_ <= 3 or croak 'usage: $pop3->apop( USER, PASS )';
my($me,$user,$pass) = @_;
my $banner;
-
- unless(eval { require MD5 })
- {
- carp "You need to install MD5 to use the APOP command";
+ my $md;
+
+ if (eval { local $SIG{__DIE__}; require Digest::MD5 }) {
+ $md = Digest::MD5->new();
+ } elsif (eval { local $SIG{__DIE__}; require MD5 }) {
+ $md = MD5->new();
+ } else {
+ carp "You need to install Digest::MD5 or MD5 to use the APOP command";
return undef;
- }
+ }
return undef
unless ( $banner = (${*$me}{'net_pop3_banner'} =~ /(<.*>)/)[0] );
- if(@_ <= 2)
- {
- require Net::Netrc;
-
- $user ||= eval { (getpwuid($>))[0] } || $ENV{NAME};
-
- my $m = Net::Netrc->lookup(${*$me}{'net_pop3_host'},$user);
-
- $m ||= Net::Netrc->lookup(${*$me}{'net_pop3_host'});
-
- $pass = $m ? $m->password || ""
- : "";
- }
+ if (@_ <= 2) {
+ ($user, $pass) = $me->_lookup_credentials($user);
+ }
- my $md = MD5->new;
$md->add($banner,$pass);
return undef
unless($me->_APOP($user,$md->hexdigest));
- my $ret = ${*$me}{'net_pop3_count'} = ($me->message =~ /(\d+)\s+message/io)
- ? $1 : ($me->popstat)[0];
-
- $ret ? $ret : "0E0";
+ $me->_get_mailbox_count();
}
sub user
return undef
unless($me->_PASS($pass));
- my $ret = ${*$me}{'net_pop3_count'} = ($me->message =~ /(\d+)\s+message/io)
- ? $1 : ($me->popstat)[0];
-
- $ret ? $ret : "0E0";
+ $me->_get_mailbox_count();
}
sub reset
$me->read_until_dot(@_);
}
+sub getfh
+{
+ @_ == 2 or croak 'usage: $pop3->getfh( MSGNUM )';
+ my $me = shift;
+
+ return unless $me->_RETR(shift);
+ return $me->tied_fh;
+}
+
+
+
sub delete
{
@_ == 2 or croak 'usage: $pop3->delete( MSGNUM )';
($1 || 0, $2 || 0);
}
+sub _lookup_credentials
+{
+ my ($me, $user) = @_;
+
+ require Net::Netrc;
+
+ $user ||= eval { local $SIG{__DIE__}; (getpwuid($>))[0] } ||
+ $ENV{NAME} || $ENV{USER} || $ENV{LOGNAME};
+
+ my $m = Net::Netrc->lookup(${*$me}{'net_pop3_host'},$user);
+ $m ||= Net::Netrc->lookup(${*$me}{'net_pop3_host'});
+
+ my $pass = $m ? $m->password || ""
+ : "";
+
+ ($user, $pass);
+}
+
+sub _get_mailbox_count
+{
+ my ($me) = @_;
+ my $ret = ${*$me}{'net_pop3_count'} = ($me->message =~ /(\d+)\s+message/io)
+ ? $1 : ($me->popstat)[0];
+
+ $ret ? $ret : "0E0";
+}
+
sub _STAT { shift->command('STAT')->response() == CMD_OK }
sub _LIST { shift->command('LIST',@_)->response() == CMD_OK }
=head1 NAME
-Net::POP3 - Post Office Protocol 3 Client class (RFC1081)
+Net::POP3 - Post Office Protocol 3 Client class (RFC1939)
=head1 SYNOPSIS
This module implements a client interface to the POP3 protocol, enabling
a perl5 application to talk to POP3 servers. This documentation assumes
-that you are familiar with the POP3 protocol described in RFC1081.
+that you are familiar with the POP3 protocol described in RFC1939.
A new Net::POP3 object must be created with the I<new> method. Once
this has been done, all POP3 commands are accessed via method calls
If there was an error authenticating the user then I<undef> will be returned.
-=item apop ( USER, PASS )
+=item apop ( [ USER [, PASS ]] )
Authenticate with the server identifying as C<USER> with password C<PASS>.
-Similar ti L<login>, but the password is not sent in clear text.
-
-To use this method you must have the MD5 package installed, if you do not
-this method will return I<undef>
+Similar to L</login>, but the password is not sent in clear text.
+To use this method you must have the Digest::MD5 or the MD5 module installed,
+otherwise this method will return I<undef>.
=item top ( MSGNUM [, NUMLINES ] )
text read from the server. If C<FH> is given then the lines returned
from the server are printed to the filehandle C<FH>.
+=item getfh ( MSGNUM )
+
+As per get(), but returns a tied filehandle. Reading from this
+filehandle returns the requested message. The filehandle will return
+EOF at the end of the message and should not be reused.
+
=item last ()
Returns the highest C<MSGNUM> of all the messages accessed.
=head1 SEE ALSO
-L<Net::Netrc>
+L<Net::Netrc>,
L<Net::Cmd>
=head1 AUTHOR
=for html <hr>
-I<$Id: //depot/libnet/Net/POP3.pm#19 $>
+I<$Id: //depot/libnet/Net/POP3.pm#22 $>
=cut