Changeset 43
- Timestamp:
- 02/07/06 18:42:50
- Files:
-
- trunk/plagger/lib/Plagger/Plugin/Publish/Gmail.pm (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/plagger/lib/Plagger/Plugin/Publish/Gmail.pm
r42 r43 10 10 use Encode::MIME::Header; 11 11 use MIME::Lite; 12 13 our %TLSConn; 12 14 13 15 sub register { … … 49 51 my $route = $cfg->{mailroute} || { via => 'smtp', host => 'localhost' }; 50 52 if ($route->{via} eq 'smtp_tls') { 51 $ msg->send_by_smtp_tls(53 $self->{tls_args} = [ 52 54 $route->{host}, 53 55 User => $route->{username}, 54 56 Password => $route->{password}, 55 57 Port => $route->{port} || 587, 56 ); 58 ]; 59 $msg->send_by_smtp_tls(@{ $self->{tls_args} }); 57 60 } else { 58 61 my @args = $route->{host} ? ($route->{host}) : (); … … 70 73 } 71 74 75 sub DESTORY { 76 my $self = shift; 77 return unless $self->{tls_args}; 78 79 my $conn_key = join "|", @{ $self->{tls_args} }; 80 eval { 81 local $SIG{__WARN__} = sub { }; 82 $TLSConn{$conn_key} && $TLSConn{$conn_key}->quit; 83 }; 84 85 # known error from Gmail SMTP 86 if ($@ && $@ !~ /An error occurred disconnecting from the mail server/) { 87 warn $@; 88 } 89 } 72 90 73 91 # hack MIME::Lite to support TLS Authentication … … 96 114 ### Create SMTP TLS client: 97 115 require Net::SMTP::TLS; 116 117 my $conn_key = join "|", @args; 98 118 my $smtp; 99 unless ($self->{__smtp}) { 100 $smtp = MIME::Lite::SMTP::TLS->new(@args) 101 or Carp::croak("Failed to connect to mail server: $!\n"); 102 $self->{__smtp} = $smtp; 119 unless ($smtp = $TLSConn{$conn_key}) { 120 $smtp = $TLSConn{$conn_key} = MIME::Lite::SMTP::TLS->new(@args) 121 or Carp::croak("Failed to connect to mail server: $!\n"); 103 122 } 104 123 $smtp->mail($from); … … 112 131 1; 113 132 } 114 sub DESTORY {115 my $self = shift;116 eval {117 local $SIG{__WARN__} = sub { };118 $self->{__smtp}->quit;119 };120 # known error from Gmail SMTP121 if ($@ && $@ !~ /An error occurred disconnecting from the mail server/) {122 warn $@;123 }124 }125 133 126 134 package MIME::Lite::SMTP::TLS;
