xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/Net/POP3.pm (revision 0:68f95e015346)
1*0Sstevel@tonic-gate# Net::POP3.pm
2*0Sstevel@tonic-gate#
3*0Sstevel@tonic-gate# Copyright (c) 1995-1997 Graham Barr <gbarr@pobox.com>. All rights reserved.
4*0Sstevel@tonic-gate# This program is free software; you can redistribute it and/or
5*0Sstevel@tonic-gate# modify it under the same terms as Perl itself.
6*0Sstevel@tonic-gate
7*0Sstevel@tonic-gatepackage Net::POP3;
8*0Sstevel@tonic-gate
9*0Sstevel@tonic-gateuse strict;
10*0Sstevel@tonic-gateuse IO::Socket;
11*0Sstevel@tonic-gateuse vars qw(@ISA $VERSION $debug);
12*0Sstevel@tonic-gateuse Net::Cmd;
13*0Sstevel@tonic-gateuse Carp;
14*0Sstevel@tonic-gateuse Net::Config;
15*0Sstevel@tonic-gate
16*0Sstevel@tonic-gate$VERSION = "2.24"; # $Id: //depot/libnet/Net/POP3.pm#24 $
17*0Sstevel@tonic-gate
18*0Sstevel@tonic-gate@ISA = qw(Net::Cmd IO::Socket::INET);
19*0Sstevel@tonic-gate
20*0Sstevel@tonic-gatesub new
21*0Sstevel@tonic-gate{
22*0Sstevel@tonic-gate my $self = shift;
23*0Sstevel@tonic-gate my $type = ref($self) || $self;
24*0Sstevel@tonic-gate my $host = shift if @_ % 2;
25*0Sstevel@tonic-gate my %arg  = @_;
26*0Sstevel@tonic-gate my $hosts = defined $host ? [ $host ] : $NetConfig{pop3_hosts};
27*0Sstevel@tonic-gate my $obj;
28*0Sstevel@tonic-gate my @localport = exists $arg{ResvPort} ? ( LocalPort => $arg{ResvPort} ): ();
29*0Sstevel@tonic-gate
30*0Sstevel@tonic-gate my $h;
31*0Sstevel@tonic-gate foreach $h (@{$hosts})
32*0Sstevel@tonic-gate  {
33*0Sstevel@tonic-gate   $obj = $type->SUPER::new(PeerAddr => ($host = $h),
34*0Sstevel@tonic-gate			    PeerPort => $arg{Port} || 'pop3(110)',
35*0Sstevel@tonic-gate			    Proto    => 'tcp',
36*0Sstevel@tonic-gate			    @localport,
37*0Sstevel@tonic-gate			    Timeout  => defined $arg{Timeout}
38*0Sstevel@tonic-gate						? $arg{Timeout}
39*0Sstevel@tonic-gate						: 120
40*0Sstevel@tonic-gate			   ) and last;
41*0Sstevel@tonic-gate  }
42*0Sstevel@tonic-gate
43*0Sstevel@tonic-gate return undef
44*0Sstevel@tonic-gate	unless defined $obj;
45*0Sstevel@tonic-gate
46*0Sstevel@tonic-gate ${*$obj}{'net_pop3_host'} = $host;
47*0Sstevel@tonic-gate
48*0Sstevel@tonic-gate $obj->autoflush(1);
49*0Sstevel@tonic-gate $obj->debug(exists $arg{Debug} ? $arg{Debug} : undef);
50*0Sstevel@tonic-gate
51*0Sstevel@tonic-gate unless ($obj->response() == CMD_OK)
52*0Sstevel@tonic-gate  {
53*0Sstevel@tonic-gate   $obj->close();
54*0Sstevel@tonic-gate   return undef;
55*0Sstevel@tonic-gate  }
56*0Sstevel@tonic-gate
57*0Sstevel@tonic-gate ${*$obj}{'net_pop3_banner'} = $obj->message;
58*0Sstevel@tonic-gate
59*0Sstevel@tonic-gate $obj;
60*0Sstevel@tonic-gate}
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gate##
63*0Sstevel@tonic-gate## We don't want people sending me their passwords when they report problems
64*0Sstevel@tonic-gate## now do we :-)
65*0Sstevel@tonic-gate##
66*0Sstevel@tonic-gate
67*0Sstevel@tonic-gatesub debug_text { $_[2] =~ /^(pass|rpop)/i ? "$1 ....\n" : $_[2]; }
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gatesub login
70*0Sstevel@tonic-gate{
71*0Sstevel@tonic-gate @_ >= 1 && @_ <= 3 or croak 'usage: $pop3->login( USER, PASS )';
72*0Sstevel@tonic-gate my($me,$user,$pass) = @_;
73*0Sstevel@tonic-gate
74*0Sstevel@tonic-gate if (@_ <= 2) {
75*0Sstevel@tonic-gate   ($user, $pass) = $me->_lookup_credentials($user);
76*0Sstevel@tonic-gate }
77*0Sstevel@tonic-gate
78*0Sstevel@tonic-gate $me->user($user) and
79*0Sstevel@tonic-gate    $me->pass($pass);
80*0Sstevel@tonic-gate}
81*0Sstevel@tonic-gate
82*0Sstevel@tonic-gatesub apop
83*0Sstevel@tonic-gate{
84*0Sstevel@tonic-gate @_ >= 1 && @_ <= 3 or croak 'usage: $pop3->apop( USER, PASS )';
85*0Sstevel@tonic-gate my($me,$user,$pass) = @_;
86*0Sstevel@tonic-gate my $banner;
87*0Sstevel@tonic-gate my $md;
88*0Sstevel@tonic-gate
89*0Sstevel@tonic-gate if (eval { local $SIG{__DIE__}; require Digest::MD5 }) {
90*0Sstevel@tonic-gate   $md = Digest::MD5->new();
91*0Sstevel@tonic-gate } elsif (eval { local $SIG{__DIE__}; require MD5 }) {
92*0Sstevel@tonic-gate   $md = MD5->new();
93*0Sstevel@tonic-gate } else {
94*0Sstevel@tonic-gate   carp "You need to install Digest::MD5 or MD5 to use the APOP command";
95*0Sstevel@tonic-gate   return undef;
96*0Sstevel@tonic-gate }
97*0Sstevel@tonic-gate
98*0Sstevel@tonic-gate return undef
99*0Sstevel@tonic-gate   unless ( $banner = (${*$me}{'net_pop3_banner'} =~ /(<.*>)/)[0] );
100*0Sstevel@tonic-gate
101*0Sstevel@tonic-gate if (@_ <= 2) {
102*0Sstevel@tonic-gate   ($user, $pass) = $me->_lookup_credentials($user);
103*0Sstevel@tonic-gate }
104*0Sstevel@tonic-gate
105*0Sstevel@tonic-gate $md->add($banner,$pass);
106*0Sstevel@tonic-gate
107*0Sstevel@tonic-gate return undef
108*0Sstevel@tonic-gate    unless($me->_APOP($user,$md->hexdigest));
109*0Sstevel@tonic-gate
110*0Sstevel@tonic-gate $me->_get_mailbox_count();
111*0Sstevel@tonic-gate}
112*0Sstevel@tonic-gate
113*0Sstevel@tonic-gatesub user
114*0Sstevel@tonic-gate{
115*0Sstevel@tonic-gate @_ == 2 or croak 'usage: $pop3->user( USER )';
116*0Sstevel@tonic-gate $_[0]->_USER($_[1]) ? 1 : undef;
117*0Sstevel@tonic-gate}
118*0Sstevel@tonic-gate
119*0Sstevel@tonic-gatesub pass
120*0Sstevel@tonic-gate{
121*0Sstevel@tonic-gate @_ == 2 or croak 'usage: $pop3->pass( PASS )';
122*0Sstevel@tonic-gate
123*0Sstevel@tonic-gate my($me,$pass) = @_;
124*0Sstevel@tonic-gate
125*0Sstevel@tonic-gate return undef
126*0Sstevel@tonic-gate   unless($me->_PASS($pass));
127*0Sstevel@tonic-gate
128*0Sstevel@tonic-gate $me->_get_mailbox_count();
129*0Sstevel@tonic-gate}
130*0Sstevel@tonic-gate
131*0Sstevel@tonic-gatesub reset
132*0Sstevel@tonic-gate{
133*0Sstevel@tonic-gate @_ == 1 or croak 'usage: $obj->reset()';
134*0Sstevel@tonic-gate
135*0Sstevel@tonic-gate my $me = shift;
136*0Sstevel@tonic-gate
137*0Sstevel@tonic-gate return 0
138*0Sstevel@tonic-gate   unless($me->_RSET);
139*0Sstevel@tonic-gate
140*0Sstevel@tonic-gate if(defined ${*$me}{'net_pop3_mail'})
141*0Sstevel@tonic-gate  {
142*0Sstevel@tonic-gate   local $_;
143*0Sstevel@tonic-gate   foreach (@{${*$me}{'net_pop3_mail'}})
144*0Sstevel@tonic-gate    {
145*0Sstevel@tonic-gate     delete $_->{'net_pop3_deleted'};
146*0Sstevel@tonic-gate    }
147*0Sstevel@tonic-gate  }
148*0Sstevel@tonic-gate}
149*0Sstevel@tonic-gate
150*0Sstevel@tonic-gatesub last
151*0Sstevel@tonic-gate{
152*0Sstevel@tonic-gate @_ == 1 or croak 'usage: $obj->last()';
153*0Sstevel@tonic-gate
154*0Sstevel@tonic-gate return undef
155*0Sstevel@tonic-gate    unless $_[0]->_LAST && $_[0]->message =~ /(\d+)/;
156*0Sstevel@tonic-gate
157*0Sstevel@tonic-gate return $1;
158*0Sstevel@tonic-gate}
159*0Sstevel@tonic-gate
160*0Sstevel@tonic-gatesub top
161*0Sstevel@tonic-gate{
162*0Sstevel@tonic-gate @_ == 2 || @_ == 3 or croak 'usage: $pop3->top( MSGNUM [, NUMLINES ])';
163*0Sstevel@tonic-gate my $me = shift;
164*0Sstevel@tonic-gate
165*0Sstevel@tonic-gate return undef
166*0Sstevel@tonic-gate    unless $me->_TOP($_[0], $_[1] || 0);
167*0Sstevel@tonic-gate
168*0Sstevel@tonic-gate $me->read_until_dot;
169*0Sstevel@tonic-gate}
170*0Sstevel@tonic-gate
171*0Sstevel@tonic-gatesub popstat
172*0Sstevel@tonic-gate{
173*0Sstevel@tonic-gate @_ == 1 or croak 'usage: $pop3->popstat()';
174*0Sstevel@tonic-gate my $me = shift;
175*0Sstevel@tonic-gate
176*0Sstevel@tonic-gate return ()
177*0Sstevel@tonic-gate    unless $me->_STAT && $me->message =~ /(\d+)\D+(\d+)/;
178*0Sstevel@tonic-gate
179*0Sstevel@tonic-gate ($1 || 0, $2 || 0);
180*0Sstevel@tonic-gate}
181*0Sstevel@tonic-gate
182*0Sstevel@tonic-gatesub list
183*0Sstevel@tonic-gate{
184*0Sstevel@tonic-gate @_ == 1 || @_ == 2 or croak 'usage: $pop3->list( [ MSGNUM ] )';
185*0Sstevel@tonic-gate my $me = shift;
186*0Sstevel@tonic-gate
187*0Sstevel@tonic-gate return undef
188*0Sstevel@tonic-gate    unless $me->_LIST(@_);
189*0Sstevel@tonic-gate
190*0Sstevel@tonic-gate if(@_)
191*0Sstevel@tonic-gate  {
192*0Sstevel@tonic-gate   $me->message =~ /\d+\D+(\d+)/;
193*0Sstevel@tonic-gate   return $1 || undef;
194*0Sstevel@tonic-gate  }
195*0Sstevel@tonic-gate
196*0Sstevel@tonic-gate my $info = $me->read_until_dot
197*0Sstevel@tonic-gate	or return undef;
198*0Sstevel@tonic-gate
199*0Sstevel@tonic-gate my %hash = map { (/(\d+)\D+(\d+)/) } @$info;
200*0Sstevel@tonic-gate
201*0Sstevel@tonic-gate return \%hash;
202*0Sstevel@tonic-gate}
203*0Sstevel@tonic-gate
204*0Sstevel@tonic-gatesub get
205*0Sstevel@tonic-gate{
206*0Sstevel@tonic-gate @_ == 2 or @_ == 3 or croak 'usage: $pop3->get( MSGNUM [, FH ])';
207*0Sstevel@tonic-gate my $me = shift;
208*0Sstevel@tonic-gate
209*0Sstevel@tonic-gate return undef
210*0Sstevel@tonic-gate    unless $me->_RETR(shift);
211*0Sstevel@tonic-gate
212*0Sstevel@tonic-gate $me->read_until_dot(@_);
213*0Sstevel@tonic-gate}
214*0Sstevel@tonic-gate
215*0Sstevel@tonic-gatesub getfh
216*0Sstevel@tonic-gate{
217*0Sstevel@tonic-gate @_ == 2 or croak 'usage: $pop3->getfh( MSGNUM )';
218*0Sstevel@tonic-gate my $me = shift;
219*0Sstevel@tonic-gate
220*0Sstevel@tonic-gate return unless $me->_RETR(shift);
221*0Sstevel@tonic-gate return        $me->tied_fh;
222*0Sstevel@tonic-gate}
223*0Sstevel@tonic-gate
224*0Sstevel@tonic-gate
225*0Sstevel@tonic-gate
226*0Sstevel@tonic-gatesub delete
227*0Sstevel@tonic-gate{
228*0Sstevel@tonic-gate @_ == 2 or croak 'usage: $pop3->delete( MSGNUM )';
229*0Sstevel@tonic-gate $_[0]->_DELE($_[1]);
230*0Sstevel@tonic-gate}
231*0Sstevel@tonic-gate
232*0Sstevel@tonic-gatesub uidl
233*0Sstevel@tonic-gate{
234*0Sstevel@tonic-gate @_ == 1 || @_ == 2 or croak 'usage: $pop3->uidl( [ MSGNUM ] )';
235*0Sstevel@tonic-gate my $me = shift;
236*0Sstevel@tonic-gate my $uidl;
237*0Sstevel@tonic-gate
238*0Sstevel@tonic-gate $me->_UIDL(@_) or
239*0Sstevel@tonic-gate    return undef;
240*0Sstevel@tonic-gate if(@_)
241*0Sstevel@tonic-gate  {
242*0Sstevel@tonic-gate   $uidl = ($me->message =~ /\d+\s+([\041-\176]+)/)[0];
243*0Sstevel@tonic-gate  }
244*0Sstevel@tonic-gate else
245*0Sstevel@tonic-gate  {
246*0Sstevel@tonic-gate   my $ref = $me->read_until_dot
247*0Sstevel@tonic-gate	or return undef;
248*0Sstevel@tonic-gate   my $ln;
249*0Sstevel@tonic-gate   $uidl = {};
250*0Sstevel@tonic-gate   foreach $ln (@$ref) {
251*0Sstevel@tonic-gate     my($msg,$uid) = $ln =~ /^\s*(\d+)\s+([\041-\176]+)/;
252*0Sstevel@tonic-gate     $uidl->{$msg} = $uid;
253*0Sstevel@tonic-gate   }
254*0Sstevel@tonic-gate  }
255*0Sstevel@tonic-gate return $uidl;
256*0Sstevel@tonic-gate}
257*0Sstevel@tonic-gate
258*0Sstevel@tonic-gatesub ping
259*0Sstevel@tonic-gate{
260*0Sstevel@tonic-gate @_ == 2 or croak 'usage: $pop3->ping( USER )';
261*0Sstevel@tonic-gate my $me = shift;
262*0Sstevel@tonic-gate
263*0Sstevel@tonic-gate return () unless $me->_PING(@_) && $me->message =~ /(\d+)\D+(\d+)/;
264*0Sstevel@tonic-gate
265*0Sstevel@tonic-gate ($1 || 0, $2 || 0);
266*0Sstevel@tonic-gate}
267*0Sstevel@tonic-gate
268*0Sstevel@tonic-gatesub _lookup_credentials
269*0Sstevel@tonic-gate{
270*0Sstevel@tonic-gate  my ($me, $user) = @_;
271*0Sstevel@tonic-gate
272*0Sstevel@tonic-gate  require Net::Netrc;
273*0Sstevel@tonic-gate
274*0Sstevel@tonic-gate  $user ||= eval { local $SIG{__DIE__}; (getpwuid($>))[0] } ||
275*0Sstevel@tonic-gate    $ENV{NAME} || $ENV{USER} || $ENV{LOGNAME};
276*0Sstevel@tonic-gate
277*0Sstevel@tonic-gate  my $m = Net::Netrc->lookup(${*$me}{'net_pop3_host'},$user);
278*0Sstevel@tonic-gate  $m ||= Net::Netrc->lookup(${*$me}{'net_pop3_host'});
279*0Sstevel@tonic-gate
280*0Sstevel@tonic-gate  my $pass = $m ? $m->password || ""
281*0Sstevel@tonic-gate                : "";
282*0Sstevel@tonic-gate
283*0Sstevel@tonic-gate  ($user, $pass);
284*0Sstevel@tonic-gate}
285*0Sstevel@tonic-gate
286*0Sstevel@tonic-gatesub _get_mailbox_count
287*0Sstevel@tonic-gate{
288*0Sstevel@tonic-gate  my ($me) = @_;
289*0Sstevel@tonic-gate  my $ret = ${*$me}{'net_pop3_count'} = ($me->message =~ /(\d+)\s+message/io)
290*0Sstevel@tonic-gate	  ? $1 : ($me->popstat)[0];
291*0Sstevel@tonic-gate
292*0Sstevel@tonic-gate  $ret ? $ret : "0E0";
293*0Sstevel@tonic-gate}
294*0Sstevel@tonic-gate
295*0Sstevel@tonic-gate
296*0Sstevel@tonic-gatesub _STAT { shift->command('STAT')->response() == CMD_OK }
297*0Sstevel@tonic-gatesub _LIST { shift->command('LIST',@_)->response() == CMD_OK }
298*0Sstevel@tonic-gatesub _RETR { shift->command('RETR',$_[0])->response() == CMD_OK }
299*0Sstevel@tonic-gatesub _DELE { shift->command('DELE',$_[0])->response() == CMD_OK }
300*0Sstevel@tonic-gatesub _NOOP { shift->command('NOOP')->response() == CMD_OK }
301*0Sstevel@tonic-gatesub _RSET { shift->command('RSET')->response() == CMD_OK }
302*0Sstevel@tonic-gatesub _QUIT { shift->command('QUIT')->response() == CMD_OK }
303*0Sstevel@tonic-gatesub _TOP  { shift->command('TOP', @_)->response() == CMD_OK }
304*0Sstevel@tonic-gatesub _UIDL { shift->command('UIDL',@_)->response() == CMD_OK }
305*0Sstevel@tonic-gatesub _USER { shift->command('USER',$_[0])->response() == CMD_OK }
306*0Sstevel@tonic-gatesub _PASS { shift->command('PASS',$_[0])->response() == CMD_OK }
307*0Sstevel@tonic-gatesub _APOP { shift->command('APOP',@_)->response() == CMD_OK }
308*0Sstevel@tonic-gatesub _PING { shift->command('PING',$_[0])->response() == CMD_OK }
309*0Sstevel@tonic-gate
310*0Sstevel@tonic-gatesub _RPOP { shift->command('RPOP',$_[0])->response() == CMD_OK }
311*0Sstevel@tonic-gatesub _LAST { shift->command('LAST')->response() == CMD_OK }
312*0Sstevel@tonic-gate
313*0Sstevel@tonic-gatesub quit
314*0Sstevel@tonic-gate{
315*0Sstevel@tonic-gate my $me = shift;
316*0Sstevel@tonic-gate
317*0Sstevel@tonic-gate $me->_QUIT;
318*0Sstevel@tonic-gate $me->close;
319*0Sstevel@tonic-gate}
320*0Sstevel@tonic-gate
321*0Sstevel@tonic-gatesub DESTROY
322*0Sstevel@tonic-gate{
323*0Sstevel@tonic-gate my $me = shift;
324*0Sstevel@tonic-gate
325*0Sstevel@tonic-gate if(defined fileno($me))
326*0Sstevel@tonic-gate  {
327*0Sstevel@tonic-gate   $me->reset;
328*0Sstevel@tonic-gate   $me->quit;
329*0Sstevel@tonic-gate  }
330*0Sstevel@tonic-gate}
331*0Sstevel@tonic-gate
332*0Sstevel@tonic-gate##
333*0Sstevel@tonic-gate## POP3 has weird responses, so we emulate them to look the same :-)
334*0Sstevel@tonic-gate##
335*0Sstevel@tonic-gate
336*0Sstevel@tonic-gatesub response
337*0Sstevel@tonic-gate{
338*0Sstevel@tonic-gate my $cmd = shift;
339*0Sstevel@tonic-gate my $str = $cmd->getline() || return undef;
340*0Sstevel@tonic-gate my $code = "500";
341*0Sstevel@tonic-gate
342*0Sstevel@tonic-gate $cmd->debug_print(0,$str)
343*0Sstevel@tonic-gate   if ($cmd->debug);
344*0Sstevel@tonic-gate
345*0Sstevel@tonic-gate if($str =~ s/^\+OK\s*//io)
346*0Sstevel@tonic-gate  {
347*0Sstevel@tonic-gate   $code = "200"
348*0Sstevel@tonic-gate  }
349*0Sstevel@tonic-gate else
350*0Sstevel@tonic-gate  {
351*0Sstevel@tonic-gate   $str =~ s/^-ERR\s*//io;
352*0Sstevel@tonic-gate  }
353*0Sstevel@tonic-gate
354*0Sstevel@tonic-gate ${*$cmd}{'net_cmd_resp'} = [ $str ];
355*0Sstevel@tonic-gate ${*$cmd}{'net_cmd_code'} = $code;
356*0Sstevel@tonic-gate
357*0Sstevel@tonic-gate substr($code,0,1);
358*0Sstevel@tonic-gate}
359*0Sstevel@tonic-gate
360*0Sstevel@tonic-gate1;
361*0Sstevel@tonic-gate
362*0Sstevel@tonic-gate__END__
363*0Sstevel@tonic-gate
364*0Sstevel@tonic-gate=head1 NAME
365*0Sstevel@tonic-gate
366*0Sstevel@tonic-gateNet::POP3 - Post Office Protocol 3 Client class (RFC1939)
367*0Sstevel@tonic-gate
368*0Sstevel@tonic-gate=head1 SYNOPSIS
369*0Sstevel@tonic-gate
370*0Sstevel@tonic-gate    use Net::POP3;
371*0Sstevel@tonic-gate
372*0Sstevel@tonic-gate    # Constructors
373*0Sstevel@tonic-gate    $pop = Net::POP3->new('pop3host');
374*0Sstevel@tonic-gate    $pop = Net::POP3->new('pop3host', Timeout => 60);
375*0Sstevel@tonic-gate
376*0Sstevel@tonic-gate    if ($pop->login($username, $password) > 0) {
377*0Sstevel@tonic-gate      my $msgnums = $pop->list; # hashref of msgnum => size
378*0Sstevel@tonic-gate      foreach my $msgnum (keys %$msgnums) {
379*0Sstevel@tonic-gate        my $msg = $pop->get($msgnum);
380*0Sstevel@tonic-gate        print @$msg;
381*0Sstevel@tonic-gate        $pop->delete($msgnum);
382*0Sstevel@tonic-gate      }
383*0Sstevel@tonic-gate    }
384*0Sstevel@tonic-gate
385*0Sstevel@tonic-gate    $pop->quit;
386*0Sstevel@tonic-gate
387*0Sstevel@tonic-gate=head1 DESCRIPTION
388*0Sstevel@tonic-gate
389*0Sstevel@tonic-gateThis module implements a client interface to the POP3 protocol, enabling
390*0Sstevel@tonic-gatea perl5 application to talk to POP3 servers. This documentation assumes
391*0Sstevel@tonic-gatethat you are familiar with the POP3 protocol described in RFC1939.
392*0Sstevel@tonic-gate
393*0Sstevel@tonic-gateA new Net::POP3 object must be created with the I<new> method. Once
394*0Sstevel@tonic-gatethis has been done, all POP3 commands are accessed via method calls
395*0Sstevel@tonic-gateon the object.
396*0Sstevel@tonic-gate
397*0Sstevel@tonic-gate=head1 CONSTRUCTOR
398*0Sstevel@tonic-gate
399*0Sstevel@tonic-gate=over 4
400*0Sstevel@tonic-gate
401*0Sstevel@tonic-gate=item new ( [ HOST, ] [ OPTIONS ] )
402*0Sstevel@tonic-gate
403*0Sstevel@tonic-gateThis is the constructor for a new Net::POP3 object. C<HOST> is the
404*0Sstevel@tonic-gatename of the remote host to which a POP3 connection is required.
405*0Sstevel@tonic-gate
406*0Sstevel@tonic-gateIf C<HOST> is not given, then the C<POP3_Host> specified in C<Net::Config>
407*0Sstevel@tonic-gatewill be used.
408*0Sstevel@tonic-gate
409*0Sstevel@tonic-gateC<OPTIONS> are passed in a hash like fashion, using key and value pairs.
410*0Sstevel@tonic-gatePossible options are:
411*0Sstevel@tonic-gate
412*0Sstevel@tonic-gateB<ResvPort> - If given then the socket for the C<Net::POP3> object
413*0Sstevel@tonic-gatewill be bound to the local port given using C<bind> when the socket is
414*0Sstevel@tonic-gatecreated.
415*0Sstevel@tonic-gate
416*0Sstevel@tonic-gateB<Timeout> - Maximum time, in seconds, to wait for a response from the
417*0Sstevel@tonic-gatePOP3 server (default: 120)
418*0Sstevel@tonic-gate
419*0Sstevel@tonic-gateB<Debug> - Enable debugging information
420*0Sstevel@tonic-gate
421*0Sstevel@tonic-gate=back
422*0Sstevel@tonic-gate
423*0Sstevel@tonic-gate=head1 METHODS
424*0Sstevel@tonic-gate
425*0Sstevel@tonic-gateUnless otherwise stated all methods return either a I<true> or I<false>
426*0Sstevel@tonic-gatevalue, with I<true> meaning that the operation was a success. When a method
427*0Sstevel@tonic-gatestates that it returns a value, failure will be returned as I<undef> or an
428*0Sstevel@tonic-gateempty list.
429*0Sstevel@tonic-gate
430*0Sstevel@tonic-gate=over 4
431*0Sstevel@tonic-gate
432*0Sstevel@tonic-gate=item user ( USER )
433*0Sstevel@tonic-gate
434*0Sstevel@tonic-gateSend the USER command.
435*0Sstevel@tonic-gate
436*0Sstevel@tonic-gate=item pass ( PASS )
437*0Sstevel@tonic-gate
438*0Sstevel@tonic-gateSend the PASS command. Returns the number of messages in the mailbox.
439*0Sstevel@tonic-gate
440*0Sstevel@tonic-gate=item login ( [ USER [, PASS ]] )
441*0Sstevel@tonic-gate
442*0Sstevel@tonic-gateSend both the USER and PASS commands. If C<PASS> is not given the
443*0Sstevel@tonic-gateC<Net::POP3> uses C<Net::Netrc> to lookup the password using the host
444*0Sstevel@tonic-gateand username. If the username is not specified then the current user name
445*0Sstevel@tonic-gatewill be used.
446*0Sstevel@tonic-gate
447*0Sstevel@tonic-gateReturns the number of messages in the mailbox. However if there are no
448*0Sstevel@tonic-gatemessages on the server the string C<"0E0"> will be returned. This is
449*0Sstevel@tonic-gatewill give a true value in a boolean context, but zero in a numeric context.
450*0Sstevel@tonic-gate
451*0Sstevel@tonic-gateIf there was an error authenticating the user then I<undef> will be returned.
452*0Sstevel@tonic-gate
453*0Sstevel@tonic-gate=item apop ( [ USER [, PASS ]] )
454*0Sstevel@tonic-gate
455*0Sstevel@tonic-gateAuthenticate with the server identifying as C<USER> with password C<PASS>.
456*0Sstevel@tonic-gateSimilar to L</login>, but the password is not sent in clear text.
457*0Sstevel@tonic-gate
458*0Sstevel@tonic-gateTo use this method you must have the Digest::MD5 or the MD5 module installed,
459*0Sstevel@tonic-gateotherwise this method will return I<undef>.
460*0Sstevel@tonic-gate
461*0Sstevel@tonic-gate=item top ( MSGNUM [, NUMLINES ] )
462*0Sstevel@tonic-gate
463*0Sstevel@tonic-gateGet the header and the first C<NUMLINES> of the body for the message
464*0Sstevel@tonic-gateC<MSGNUM>. Returns a reference to an array which contains the lines of text
465*0Sstevel@tonic-gateread from the server.
466*0Sstevel@tonic-gate
467*0Sstevel@tonic-gate=item list ( [ MSGNUM ] )
468*0Sstevel@tonic-gate
469*0Sstevel@tonic-gateIf called with an argument the C<list> returns the size of the message
470*0Sstevel@tonic-gatein octets.
471*0Sstevel@tonic-gate
472*0Sstevel@tonic-gateIf called without arguments a reference to a hash is returned. The
473*0Sstevel@tonic-gatekeys will be the C<MSGNUM>'s of all undeleted messages and the values will
474*0Sstevel@tonic-gatebe their size in octets.
475*0Sstevel@tonic-gate
476*0Sstevel@tonic-gate=item get ( MSGNUM [, FH ] )
477*0Sstevel@tonic-gate
478*0Sstevel@tonic-gateGet the message C<MSGNUM> from the remote mailbox. If C<FH> is not given
479*0Sstevel@tonic-gatethen get returns a reference to an array which contains the lines of
480*0Sstevel@tonic-gatetext read from the server. If C<FH> is given then the lines returned
481*0Sstevel@tonic-gatefrom the server are printed to the filehandle C<FH>.
482*0Sstevel@tonic-gate
483*0Sstevel@tonic-gate=item getfh ( MSGNUM )
484*0Sstevel@tonic-gate
485*0Sstevel@tonic-gateAs per get(), but returns a tied filehandle.  Reading from this
486*0Sstevel@tonic-gatefilehandle returns the requested message.  The filehandle will return
487*0Sstevel@tonic-gateEOF at the end of the message and should not be reused.
488*0Sstevel@tonic-gate
489*0Sstevel@tonic-gate=item last ()
490*0Sstevel@tonic-gate
491*0Sstevel@tonic-gateReturns the highest C<MSGNUM> of all the messages accessed.
492*0Sstevel@tonic-gate
493*0Sstevel@tonic-gate=item popstat ()
494*0Sstevel@tonic-gate
495*0Sstevel@tonic-gateReturns a list of two elements. These are the number of undeleted
496*0Sstevel@tonic-gateelements and the size of the mbox in octets.
497*0Sstevel@tonic-gate
498*0Sstevel@tonic-gate=item ping ( USER )
499*0Sstevel@tonic-gate
500*0Sstevel@tonic-gateReturns a list of two elements. These are the number of new messages
501*0Sstevel@tonic-gateand the total number of messages for C<USER>.
502*0Sstevel@tonic-gate
503*0Sstevel@tonic-gate=item uidl ( [ MSGNUM ] )
504*0Sstevel@tonic-gate
505*0Sstevel@tonic-gateReturns a unique identifier for C<MSGNUM> if given. If C<MSGNUM> is not
506*0Sstevel@tonic-gategiven C<uidl> returns a reference to a hash where the keys are the
507*0Sstevel@tonic-gatemessage numbers and the values are the unique identifiers.
508*0Sstevel@tonic-gate
509*0Sstevel@tonic-gate=item delete ( MSGNUM )
510*0Sstevel@tonic-gate
511*0Sstevel@tonic-gateMark message C<MSGNUM> to be deleted from the remote mailbox. All messages
512*0Sstevel@tonic-gatethat are marked to be deleted will be removed from the remote mailbox
513*0Sstevel@tonic-gatewhen the server connection closed.
514*0Sstevel@tonic-gate
515*0Sstevel@tonic-gate=item reset ()
516*0Sstevel@tonic-gate
517*0Sstevel@tonic-gateReset the status of the remote POP3 server. This includes reseting the
518*0Sstevel@tonic-gatestatus of all messages to not be deleted.
519*0Sstevel@tonic-gate
520*0Sstevel@tonic-gate=item quit ()
521*0Sstevel@tonic-gate
522*0Sstevel@tonic-gateQuit and close the connection to the remote POP3 server. Any messages marked
523*0Sstevel@tonic-gateas deleted will be deleted from the remote mailbox.
524*0Sstevel@tonic-gate
525*0Sstevel@tonic-gate=back
526*0Sstevel@tonic-gate
527*0Sstevel@tonic-gate=head1 NOTES
528*0Sstevel@tonic-gate
529*0Sstevel@tonic-gateIf a C<Net::POP3> object goes out of scope before C<quit> method is called
530*0Sstevel@tonic-gatethen the C<reset> method will called before the connection is closed. This
531*0Sstevel@tonic-gatemeans that any messages marked to be deleted will not be.
532*0Sstevel@tonic-gate
533*0Sstevel@tonic-gate=head1 SEE ALSO
534*0Sstevel@tonic-gate
535*0Sstevel@tonic-gateL<Net::Netrc>,
536*0Sstevel@tonic-gateL<Net::Cmd>
537*0Sstevel@tonic-gate
538*0Sstevel@tonic-gate=head1 AUTHOR
539*0Sstevel@tonic-gate
540*0Sstevel@tonic-gateGraham Barr <gbarr@pobox.com>
541*0Sstevel@tonic-gate
542*0Sstevel@tonic-gate=head1 COPYRIGHT
543*0Sstevel@tonic-gate
544*0Sstevel@tonic-gateCopyright (c) 1995-1997 Graham Barr. All rights reserved.
545*0Sstevel@tonic-gateThis program is free software; you can redistribute it and/or modify
546*0Sstevel@tonic-gateit under the same terms as Perl itself.
547*0Sstevel@tonic-gate
548*0Sstevel@tonic-gate=for html <hr>
549*0Sstevel@tonic-gate
550*0Sstevel@tonic-gateI<$Id: //depot/libnet/Net/POP3.pm#24 $>
551*0Sstevel@tonic-gate
552*0Sstevel@tonic-gate=cut
553