⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pop3.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 2 页
字号:
  ${*$cmd}{'net_cmd_code'} = $code;  substr($code, 0, 1);}sub capa {  my $this = shift;  my ($capa, %capabilities);  # Fake a capability here  $capabilities{APOP} = '' if ($this->banner() =~ /<.*>/);  if ($this->_CAPA()) {    $capabilities{CAPA} = 1;    $capa = $this->read_until_dot();    %capabilities = (%capabilities, map {/^\s*(\S+)\s*(.*)/} @$capa);  }  else {    # Check AUTH for SASL capabilities    if ($this->command('AUTH')->response() == CMD_OK) {      my $mechanism = $this->read_until_dot();      $capabilities{SASL} = join " ", map {m/([A-Z0-9_-]+)/} @{$mechanism};    }  }  return ${*$this}{'net_pop3e_capabilities'} = \%capabilities;}sub capabilities {  my $this = shift;  ${*$this}{'net_pop3e_capabilities'} || $this->capa;}sub auth {  my ($self, $username, $password) = @_;  eval {    require MIME::Base64;    require Authen::SASL;  } or $self->set_status(500, ["Need MIME::Base64 and Authen::SASL todo auth"]), return 0;  my $capa       = $self->capa;  my $mechanisms = $capa->{SASL} || 'CRAM-MD5';  my $sasl;  if (ref($username) and UNIVERSAL::isa($username, 'Authen::SASL')) {    $sasl = $username;    my $user_mech = $sasl->mechanism || '';    my @user_mech = split(/\s+/, $user_mech);    my %user_mech;    @user_mech{@user_mech} = ();    my @server_mech = split(/\s+/, $mechanisms);    my @mech = @user_mech      ? grep { exists $user_mech{$_} } @server_mech      : @server_mech;    unless (@mech) {      $self->set_status(        500,        [ 'Client SASL mechanisms (',          join(', ', @user_mech),          ') do not match the SASL mechnism the server announces (',          join(', ', @server_mech), ')',        ]      );      return 0;    }    $sasl->mechanism(join(" ", @mech));  }  else {    die "auth(username, password)" if not length $username;    $sasl = Authen::SASL->new(      mechanism => $mechanisms,      callback  => {        user     => $username,        pass     => $password,        authname => $username,      }    );  }  # We should probably allow the user to pass the host, but I don't  # currently know and SASL mechanisms that are used by smtp that need it  my ($hostname) = split /:/, ${*$self}{'net_pop3_host'};  my $client = eval { $sasl->client_new('pop', $hostname, 0) };  unless ($client) {    my $mech = $sasl->mechanism;    $self->set_status(      500,      [ " Authen::SASL failure: $@",        '(please check if your local Authen::SASL installation',        "supports mechanism '$mech'"      ]    );    return 0;  }  my ($token) = $client->client_start    or do {    my $mech = $client->mechanism;    $self->set_status(      500,      [ ' Authen::SASL failure:  $client->client_start ',        "mechanism '$mech' hostname #$hostname#",        $client->error      ]    );    return 0;    };  # We dont support sasl mechanisms that encrypt the socket traffic.  # todo that we would really need to change the ISA hierarchy  # so we dont inherit from IO::Socket, but instead hold it in an attribute  my @cmd = ("AUTH", $client->mechanism);  my $code;  push @cmd, MIME::Base64::encode_base64($token, '')    if defined $token and length $token;  while (($code = $self->command(@cmd)->response()) == CMD_MORE) {    my ($token) = $client->client_step(MIME::Base64::decode_base64(($self->message)[0])) or do {      $self->set_status(        500,        [ ' Authen::SASL failure:  $client->client_step ',          "mechanism '", $client->mechanism, " hostname #$hostname#, ",          $client->error        ]      );      return 0;    };    @cmd = (MIME::Base64::encode_base64(defined $token ? $token : '', ''));  }  $code == CMD_OK;}sub banner {  my $this = shift;  return ${*$this}{'net_pop3_banner'};}1;__END__=head1 NAMENet::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 DESCRIPTIONThis module implements a client interface to the POP3 protocol, enablinga perl5 application to talk to POP3 servers. This documentation assumesthat you are familiar with the POP3 protocol described in RFC1939.A new Net::POP3 object must be created with the I<new> method. Oncethis has been done, all POP3 commands are accessed via method callson the object.=head1 CONSTRUCTOR=over 4=item new ( [ HOST ] [, OPTIONS ] 0This is the constructor for a new Net::POP3 object. C<HOST> is thename of the remote host to which an POP3 connection is required.C<HOST> is optional. If C<HOST> is not given then it may instead bepassed as the C<Host> option described below. If neither is given thenthe C<POP3_Hosts> 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<Host> - POP3 host to connect to. It may be a single scalar, as defined forthe C<PeerAddr> option in L<IO::Socket::INET>, or a reference toan array with hosts to try in turn. The L</host> method will return the valuewhich was used to connect to the host.B<ResvPort> - If given then the socket for the C<Net::POP3> objectwill be bound to the local port given using C<bind> when the socket iscreated.B<Timeout> - Maximum time, in seconds, to wait for a response from thePOP3 server (default: 120)B<Debug> - Enable debugging information=back=head1 METHODSUnless 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 methodstates that it returns a value, failure will be returned as I<undef> or anempty list.=over 4=item auth ( USERNAME, PASSWORD )Attempt SASL authentication.=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 theC<Net::POP3> uses C<Net::Netrc> to lookup the password using the hostand username. If the username is not specified then the current user namewill be used.Returns the number of messages in the mailbox. However if there are nomessages on the server the string C<"0E0"> will be returned. This iswill 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 banner ()Return the sever's connection banner=item capa ()Return a reference to a hash of the capabilities of the server.  APOPis added as a pseudo capability.  Note that I've been unable tofind a list of the standard capability values, and some appear tobe multi-word and some are not.  We make an attempt at intelligentlyparsing them, but it may not be correct.=item  capabilities ()Just like capa, but only uses a cache from the last time we askedthe server, so as to avoid asking more than once.=item top ( MSGNUM [, NUMLINES ] )Get the header and the first C<NUMLINES> of the body for the messageC<MSGNUM>. Returns a reference to an array which contains the lines of textread from the server.=item list ( [ MSGNUM ] )If called with an argument the C<list> returns the size of the messagein octets.If called without arguments a reference to a hash is returned. Thekeys will be the C<MSGNUM>'s of all undeleted messages and the values willbe their size in octets.=item get ( MSGNUM [, FH ] )Get the message C<MSGNUM> from the remote mailbox. If C<FH> is not giventhen get returns a reference to an array which contains the lines oftext read from the server. If C<FH> is given then the lines returnedfrom the server are printed to the filehandle C<FH>.=item getfh ( MSGNUM )As per get(), but returns a tied filehandle.  Reading from thisfilehandle returns the requested message.  The filehandle will returnEOF 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 undeletedelements and the size of the mbox in octets.=item ping ( USER )Returns a list of two elements. These are the number of new messagesand the total number of messages for C<USER>.=item uidl ( [ MSGNUM ] )Returns a unique identifier for C<MSGNUM> if given. If C<MSGNUM> is notgiven C<uidl> returns a reference to a hash where the keys are themessage numbers and the values are the unique identifiers.=item delete ( MSGNUM )Mark message C<MSGNUM> to be deleted from the remote mailbox. All messagesthat are marked to be deleted will be removed from the remote mailboxwhen the server connection closed.=item reset ()Reset the status of the remote POP3 server. This includes resetting thestatus of all messages to not be deleted.=item quit ()Quit and close the connection to the remote POP3 server. Any messages markedas deleted will be deleted from the remote mailbox.=back=head1 NOTESIf a C<Net::POP3> object goes out of scope before C<quit> method is calledthen the C<reset> method will called before the connection is closed. Thismeans that any messages marked to be deleted will not be.=head1 SEE ALSOL<Net::Netrc>,L<Net::Cmd>=head1 AUTHORGraham Barr <gbarr@pobox.com>=head1 COPYRIGHTCopyright (c) 1995-2003 Graham Barr. All rights reserved.This program is free software; you can redistribute it and/or modifyit under the same terms as Perl itself.=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -