summaryrefslogtreecommitdiff
path: root/lib/Net/POP3.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Net/POP3.pm')
-rw-r--r--lib/Net/POP3.pm120
1 files changed, 70 insertions, 50 deletions
diff --git a/lib/Net/POP3.pm b/lib/Net/POP3.pm
index 89f0313912..146041624e 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#20 $
+$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<new> 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<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 ] )
@@ -459,6 +473,12 @@ then get returns a reference to an array which contains the lines of
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.
@@ -505,7 +525,7 @@ means that any messages marked to be deleted will not be.
=head1 SEE ALSO
-L<Net::Netrc>
+L<Net::Netrc>,
L<Net::Cmd>
=head1 AUTHOR
@@ -520,6 +540,6 @@ it under the same terms as Perl itself.
=for html <hr>
-I<$Id: //depot/libnet/Net/POP3.pm#20 $>
+I<$Id: //depot/libnet/Net/POP3.pm#22 $>
=cut