Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.6 KiB

  1. # ======================================================================
  2. #
  3. # Copyright (C) 2000-2001 Paul Kulchenko ([email protected])
  4. # SOAP::Lite is free software; you can redistribute it
  5. # and/or modify it under the same terms as Perl itself.
  6. #
  7. # $Id: SOAP::Transport::POP3.pm,v 0.51 2001/07/18 15:15:14 $
  8. #
  9. # ======================================================================
  10. package SOAP::Transport::POP3;
  11. use strict;
  12. use vars qw($VERSION);
  13. $VERSION = '0.51';
  14. use Net::POP3;
  15. use URI;
  16. use SOAP::Lite;
  17. # ======================================================================
  18. package SOAP::Transport::POP3::Server;
  19. use Carp ();
  20. use vars qw(@ISA $AUTOLOAD);
  21. @ISA = qw(SOAP::Server);
  22. sub DESTROY { my $self = shift; $self->quit if $self->{_pop3server} }
  23. sub new {
  24. my $self = shift;
  25. unless (ref $self) {
  26. my $class = ref($self) || $self;
  27. my $address = shift;
  28. Carp::carp "URLs without 'pop://' scheme are deprecated. Still continue"
  29. if $address =~ s!^(pop://)?!pop://!i && !$1;
  30. my $server = URI->new($address);
  31. $self = $class->SUPER::new(@_);
  32. $self->{_pop3server} = Net::POP3->new($server->host_port) or Carp::croak "Can't connect to '@{[$server->host_port]}': $!";
  33. my $method = !$server->auth || $server->auth eq '*' ? 'login' :
  34. $server->auth eq '+APOP' ? 'apop' :
  35. Carp::croak "Unsupported authentication scheme '@{[$server->auth]}'";
  36. $self->{_pop3server}->$method(split /:/, $server->user) or Carp::croak "Can't authenticate to '@{[$server->host_port]}' with '$method' method"
  37. if defined $server->user;
  38. }
  39. return $self;
  40. }
  41. sub AUTOLOAD {
  42. my $method = substr($AUTOLOAD, rindex($AUTOLOAD, '::') + 2);
  43. return if $method eq 'DESTROY';
  44. no strict 'refs';
  45. *$AUTOLOAD = sub { shift->{_pop3server}->$method(@_) };
  46. goto &$AUTOLOAD;
  47. }
  48. sub handle {
  49. my $self = shift->new;
  50. my $messages = $self->list or return;
  51. foreach my $msgid (keys %$messages) {
  52. $self->SUPER::handle(join '', @{$self->get($msgid)});
  53. } continue {
  54. $self->delete($msgid);
  55. }
  56. return scalar keys %$messages;
  57. }
  58. sub make_fault { return }
  59. # ======================================================================
  60. 1;
  61. __END__
  62. =head1 NAME
  63. SOAP::Transport::POP3 - Server side POP3 support for SOAP::Lite
  64. =head1 SYNOPSIS
  65. use SOAP::Transport::POP3;
  66. my $server = SOAP::Transport::POP3::Server
  67. -> new('pop://pop.mail.server')
  68. # if you want to have all in one place
  69. # -> new('pop://user:[email protected]')
  70. # or, if you have server that supports MD5 protected passwords
  71. # -> new('pop://user:password;[email protected]')
  72. # specify list of objects-by-reference here
  73. -> objects_by_reference(qw(My::PersistentIterator My::SessionIterator My::Chat))
  74. # specify path to My/Examples.pm here
  75. -> dispatch_to('/Your/Path/To/Deployed/Modules', 'Module::Name', 'Module::method')
  76. ;
  77. # you don't need to use next line if you specified your password in new()
  78. $server->login('user' => 'password') or die "Can't authenticate to POP3 server\n";
  79. # handle will return number of processed mails
  80. # you can organize loop if you want
  81. do { $server->handle } while sleep 10;
  82. # you may also call $server->quit explicitly to purge deleted messages
  83. =head1 DESCRIPTION
  84. =head1 COPYRIGHT
  85. Copyright (C) 2000-2001 Paul Kulchenko. All rights reserved.
  86. This library is free software; you can redistribute it and/or modify
  87. it under the same terms as Perl itself.
  88. =head1 AUTHOR
  89. Paul Kulchenko (paulclinger@yahoo.com)
  90. =cut