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