Changeset 42

Show
Ignore:
Timestamp:
02/07/06 18:27:52
Author:
sekimura
Message:

support Persistent SMTP connection with TLS mode. Fixes #15

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin/Publish/Gmail.pm

    r37 r42  
    5353            User     => $route->{username}, 
    5454            Password => $route->{password}, 
     55            Port     => $route->{port} || 587, 
    5556        ); 
    5657    } else { 
     
    6869    $out; 
    6970} 
     71 
    7072 
    7173# hack MIME::Lite to support TLS Authentication 
     
    9496    ### Create SMTP TLS client: 
    9597    require Net::SMTP::TLS; 
    96     my $smtp = MIME::Lite::SMTP::TLS->new(@args) 
    97         or Carp::croak("Failed to connect to mail server: $!\n"); 
     98    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; 
     103    } 
    98104    $smtp->mail($from); 
    99105    $smtp->to(@to_all); 
     
    103109    $self->print_for_smtp($smtp); 
    104110    $smtp->dataend(); 
     111 
     112    1; 
     113} 
     114sub DESTORY { 
     115    my $self = shift; 
    105116    eval { 
    106117        local $SIG{__WARN__} = sub { }; 
    107         $smtp->quit; 
     118        $self->{__smtp}->quit; 
    108119    }; 
    109  
    110120    # known error from Gmail SMTP 
    111121    if ($@ && $@ !~ /An error occurred disconnecting from the mail server/) { 
    112122        warn $@; 
    113123    } 
    114  
    115     1; 
    116124} 
    117125