# Net::POP3.pm
#
# Copyright (c) 1995-1997 Graham Barr <gbarr@pobox.com>. All rights reserved.
# modify it under the same terms as Perl itself.
use strict;
use Carp;
sub new
{
my $self = shift;
my $host = shift if @_ % 2;
my %arg = @_;
my $obj;
my $h;
foreach $h (@{$hosts})
{
Proto => 'tcp',
: 120
) and last;
}
return undef
unless defined $obj;
{
$obj->close();
return undef;
}
$obj;
}
##
## We don't want people sending me their passwords when they report problems
## now do we :-)
##
sub login
{
@_ >= 1 && @_ <= 3 or croak 'usage: $pop3->login( USER, PASS )';
if (@_ <= 2) {
}
}
sub apop
{
@_ >= 1 && @_ <= 3 or croak 'usage: $pop3->apop( USER, PASS )';
my $banner;
my $md;
} else {
carp "You need to install Digest::MD5 or MD5 to use the APOP command";
return undef;
}
return undef
if (@_ <= 2) {
}
return undef
$me->_get_mailbox_count();
}
sub user
{
@_ == 2 or croak 'usage: $pop3->user( USER )';
}
sub pass
{
@_ == 2 or croak 'usage: $pop3->pass( PASS )';
return undef
$me->_get_mailbox_count();
}
sub reset
{
@_ == 1 or croak 'usage: $obj->reset()';
my $me = shift;
return 0
if(defined ${*$me}{'net_pop3_mail'})
{
local $_;
foreach (@{${*$me}{'net_pop3_mail'}})
{
delete $_->{'net_pop3_deleted'};
}
}
}
sub last
{
@_ == 1 or croak 'usage: $obj->last()';
return undef
return $1;
}
sub top
{
@_ == 2 || @_ == 3 or croak 'usage: $pop3->top( MSGNUM [, NUMLINES ])';
my $me = shift;
return undef
$me->read_until_dot;
}
sub popstat
{
@_ == 1 or croak 'usage: $pop3->popstat()';
my $me = shift;
return ()
($1 || 0, $2 || 0);
}
sub list
{
@_ == 1 || @_ == 2 or croak 'usage: $pop3->list( [ MSGNUM ] )';
my $me = shift;
return undef
if(@_)
{
return $1 || undef;
}
or return undef;
return \%hash;
}
sub get
{
@_ == 2 or @_ == 3 or croak 'usage: $pop3->get( MSGNUM [, FH ])';
my $me = shift;
return undef
$me->read_until_dot(@_);
}
sub getfh
{
@_ == 2 or croak 'usage: $pop3->getfh( MSGNUM )';
my $me = shift;
}
sub delete
{
@_ == 2 or croak 'usage: $pop3->delete( MSGNUM )';
}
sub uidl
{
@_ == 1 || @_ == 2 or croak 'usage: $pop3->uidl( [ MSGNUM ] )';
my $me = shift;
my $uidl;
return undef;
if(@_)
{
}
else
{
or return undef;
my $ln;
$uidl = {};
}
}
return $uidl;
}
sub ping
{
@_ == 2 or croak 'usage: $pop3->ping( USER )';
my $me = shift;
($1 || 0, $2 || 0);
}
{
: "";
}
{
my ($me) = @_;
}
sub quit
{
my $me = shift;
$me->close;
}
sub DESTROY
{
my $me = shift;
if(defined fileno($me))
{
$me->reset;
}
}
##
## POP3 has weird responses, so we emulate them to look the same :-)
##
sub response
{
my $cmd = shift;
my $code = "500";
{
$code = "200"
}
else
{
}
}
1;
=head1 NAME
Net::POP3 - Post Office Protocol 3 Client class (RFC1939)
=head1 SYNOPSIS
use Net::POP3;
# Constructors
$pop = Net::POP3->new('pop3host');
$pop = Net::POP3->new('pop3host', Timeout => 60);
if ($pop->login($username, $password) > 0) {
my $msgnums = $pop->list; # hashref of msgnum => size
foreach my $msgnum (keys %$msgnums) {
my $msg = $pop->get($msgnum);
print @$msg;
$pop->delete($msgnum);
}
}
$pop->quit;
=head1 DESCRIPTION
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 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
on the object.
=head1 CONSTRUCTOR
=over 4
=item new ( [ HOST, ] [ OPTIONS ] )
This is the constructor for a new Net::POP3 object. C<HOST> is the
name of the remote host to which a POP3 connection is required.
If C<HOST> is not given, then the C<POP3_Host> specified in C<Net::Config>
will be used.
C<OPTIONS> are passed in a hash like fashion, using key and value pairs.
Possible options are:
B<ResvPort> - If given then the socket for the C<Net::POP3> object
will be bound to the local port given using C<bind> when the socket is
created.
B<Timeout> - Maximum time, in seconds, to wait for a response from the
POP3 server (default: 120)
B<Debug> - Enable debugging information
=back
=head1 METHODS
Unless otherwise stated all methods return either a I<true> or I<false>
value, with I<true> meaning that the operation was a success. When a method
states that it returns a value, failure will be returned as I<undef> or an
empty list.
=over 4
=item user ( USER )
Send the USER command.
=item pass ( PASS )
Send the PASS command. Returns the number of messages in the mailbox.
=item login ( [ USER [, PASS ]] )
Send both the USER and PASS commands. If C<PASS> is not given the
C<Net::POP3> uses C<Net::Netrc> to lookup the password using the host
and username. If the username is not specified then the current user name
will be used.
Returns the number of messages in the mailbox. However if there are no
messages on the server the string C<"0E0"> will be returned. This is
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 ]] )
Authenticate with the server identifying as C<USER> with password C<PASS>.
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 ] )
Get the header and the first C<NUMLINES> of the body for the message
C<MSGNUM>. Returns a reference to an array which contains the lines of text
read from the server.
=item list ( [ MSGNUM ] )
If called with an argument the C<list> returns the size of the message
in octets.
If called without arguments a reference to a hash is returned. The
keys will be the C<MSGNUM>'s of all undeleted messages and the values will
be their size in octets.
=item get ( MSGNUM [, FH ] )
Get the message C<MSGNUM> from the remote mailbox. If C<FH> is not given
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.
=item popstat ()
Returns a list of two elements. These are the number of undeleted
elements and the size of the mbox in octets.
=item ping ( USER )
Returns a list of two elements. These are the number of new messages
and the total number of messages for C<USER>.
=item uidl ( [ MSGNUM ] )
Returns a unique identifier for C<MSGNUM> if given. If C<MSGNUM> is not
given C<uidl> returns a reference to a hash where the keys are the
message numbers and the values are the unique identifiers.
=item delete ( MSGNUM )
Mark message C<MSGNUM> to be deleted from the remote mailbox. All messages
that are marked to be deleted will be removed from the remote mailbox
when the server connection closed.
=item reset ()
Reset the status of the remote POP3 server. This includes reseting the
status of all messages to not be deleted.
=item quit ()
Quit and close the connection to the remote POP3 server. Any messages marked
as deleted will be deleted from the remote mailbox.
=back
=head1 NOTES
If a C<Net::POP3> object goes out of scope before C<quit> method is called
then the C<reset> method will called before the connection is closed. This
means that any messages marked to be deleted will not be.
=head1 SEE ALSO
L<Net::Netrc>,
L<Net::Cmd>
=head1 AUTHOR
Graham Barr <gbarr@pobox.com>
=head1 COPYRIGHT
Copyright (c) 1995-1997 Graham Barr. All rights reserved.
it under the same terms as Perl itself.
=for html <hr>
=cut