X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FNet%2FPOP3.pm;h=146041624e73fac748f4e759e222c8c9eeefd0fa;hb=564e2e78a483fb2c19eb2fe907d0dd36ce81fddb;hp=f23157cccafc74ab4191a3fb86671caa1be64c29;hpb=d1be9408a3c14848d30728674452e191ba5fffaa;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Net/POP3.pm b/lib/Net/POP3.pm index f23157c..1460416 100644 --- a/lib/Net/POP3.pm +++ b/lib/Net/POP3.pm @@ -13,7 +13,7 @@ use Net::Cmd; 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); @@ -71,19 +71,9 @@ sub login @_ >= 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); @@ -94,40 +84,30 @@ sub apop @_ >= 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 @@ -145,10 +125,7 @@ sub pass 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 @@ -235,6 +212,17 @@ sub get $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 )'; @@ -277,6 +265,33 @@ sub ping ($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 } @@ -348,7 +363,7 @@ __END__ =head1 NAME -Net::POP3 - Post Office Protocol 3 Client class (RFC1081) +Net::POP3 - Post Office Protocol 3 Client class (RFC1939) =head1 SYNOPSIS @@ -362,7 +377,7 @@ Net::POP3 - Post Office Protocol 3 Client class (RFC1081) 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 method. Once this has been done, all POP3 commands are accessed via method calls @@ -428,14 +443,13 @@ will give a true value in a boolean context, but zero in a numeric context. If there was an error authenticating the user then I will be returned. -=item apop ( USER, PASS ) +=item apop ( [ USER [, PASS ]] ) Authenticate with the server identifying as C with password C. -Similar ti L, 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 +Similar to L, 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. =item top ( MSGNUM [, NUMLINES ] ) @@ -459,6 +473,12 @@ then get returns a reference to an array which contains the lines of text read from the server. If C is given then the lines returned from the server are printed to the filehandle C. +=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 of all the messages accessed. @@ -505,7 +525,7 @@ means that any messages marked to be deleted will not be. =head1 SEE ALSO -L +L, L =head1 AUTHOR @@ -520,6 +540,6 @@ it under the same terms as Perl itself. =for html
-I<$Id: //depot/libnet/Net/POP3.pm#19 $> +I<$Id: //depot/libnet/Net/POP3.pm#22 $> =cut