Skip Menu |

This queue is for tickets about the AnyEvent-SMTP CPAN distribution.

Report information
The Basics
Id: 133046
Status: new
Priority: 0/
Queue: AnyEvent-SMTP

People
Owner: Nobody in particular
Requestors: felix.ostmann [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: new keyworld tls and auth
I have patched AnyEvent::SMTP::Client and ::Conn to send emails via amazon SES. Currently only AUTH LOGIN and AUTH PLAIN are supported i guess. A patch for CRAM-MD5 should easily possible. Also there is a small Bugfix when used with the Guard from sendmail. The $end-callback will be executed two times.
Subject: AnyEvent-SMTP-0.11.patch
--- lib/AnyEvent/SMTP.pm.orig 2020-07-24 19:13:42.816923565 +0200 +++ lib/AnyEvent/SMTP.pm 2020-07-24 18:03:41.528291429 +0200 @@ -33,7 +33,7 @@ =cut -our $VERSION = '0.10'; +our $VERSION = '0.11'; =head1 SYNOPSIS --- lib/AnyEvent/SMTP/Client.pm.orig 2013-10-24 22:44:54.000000000 +0200 +++ lib/AnyEvent/SMTP/Client.pm 2020-07-24 19:10:10.929089546 +0200 @@ -22,6 +22,7 @@ use Sys::Hostname; use Mail::Address; +use MIME::Base64; use AnyEvent::SMTP::Conn; @@ -130,10 +131,18 @@ SMTP server. The same as pair of host:port +=item tls => 'connect' + +Enable tls via Net::SSLeay. Optional. + =item helo => 'hostname' HELO message. Optional. By default = hostname() +=item auth => [ 'LOGIN|PLAIN', ... ] + +AUTH settings. Optional. + =item from => 'mail@addr.ess' =item to => 'mail@addr.ess' @@ -252,8 +261,10 @@ $args{cv}->begin if $args{cv}; $cv = AnyEvent->condvar; my $end = sub{ + return if not $cv; undef $run; undef $cv; + $args{cb}( $res, defined $err ? $err : () ); $args{cv}->end if $args{cv}; %args = (); @@ -289,7 +300,7 @@ $slot_guard = pop; my $fh = shift or return $cb->(undef, "$!"); - $con = AnyEvent::SMTP::Conn->new( fh => $fh, debug => $args{debug}, timeout => $args{timeout} ); + $con = AnyEvent::SMTP::Conn->new( fh => $fh, debug => $args{debug}, timeout => $args{timeout}, tls => $args{tls} ); $exc = $con->reg_cb( disconnect => sub { $con or return; @@ -300,33 +311,57 @@ shift or return $cb->(undef, @_); $con->command("HELO $args{helo}", ok => 250, cb => sub { shift or return $cb->(undef, @_); - $con->command("MAIL FROM:<$args{from}>", ok => 250, cb => sub { - shift or return $cb->(undef, @_); - my $cv1 = AnyEvent->condvar; - $cv1->begin(sub { - undef $cv1; - $con->command("DATA", ok => 354, cb => sub { - shift or return $cb->(undef, @_); - $con->reply("$args{data}"); - $con->command(".", ok => 250, cb => sub { - my $reply = shift or return $cb->(undef, @_); - $cb->($reply); + my $cv0 = AnyEvent->condvar; + $cv0->begin(sub { + undef $cv0; + + $con->command("MAIL FROM:<$args{from}>", ok => 250, cb => sub { + shift or return $cb->(undef, @_); + + my $cv1 = AnyEvent->condvar; + $cv1->begin(sub { + undef $cv1; + $con->command("DATA", ok => 354, cb => sub { + shift or return $cb->(undef, @_); + $con->reply("$args{data}"); + $con->command(".", ok => 250, cb => sub { + my $reply = shift or return $cb->(undef, @_); + $cb->($reply); + }); }); }); - }); - for ( @to ) { - $cv1->begin; - $con->command("RCPT TO:<$_>", ok => 250, cb => sub { - shift or return $cb->(undef, @_); - $cv1->end; - }); - } + for ( @to ) { + $cv1->begin; + $con->command("RCPT TO:<$_>", ok => 250, cb => sub { + shift or return $cb->(undef, @_); + $cv1->end; + }); + } - $cv1->end; + $cv1->end; + }); }); + for ( my $idx = 0 ; $idx <= $#{ $args{auth} // [] } ; $idx++ ) { + my $auth_cmd = $idx == 0 + ? "AUTH \U$args{auth}[$idx]" + : encode_base64($args{auth}[$idx], "") + ; + my $auth_ok = $idx == $#{ $args{auth} } + ? 235 + : 334 + ; + + $cv0->begin; + $con->command($auth_cmd, ok => $auth_ok, cb => sub { + shift or return $cb->(undef, @_); + $cv0->end; + }); + } + + $cv0->end; }); }); }, sub { $args{timeout} || 30 }; --- lib/AnyEvent/SMTP/Conn.pm.orig 2020-07-24 17:25:38.750117623 +0200 +++ lib/AnyEvent/SMTP/Conn.pm 2020-07-24 17:27:27.030029130 +0200 @@ -19,6 +19,7 @@ my $self = bless { @_ }, $pkg; $self->{h} = AnyEvent::Handle->new( fh => $self->{fh}, + tls => $self->{tls}, on_eof => sub { local *__ANON__ = 'conn.on_eof'; warn "eof on handle";