| 1 | package Net::Async::SMTP::Connection; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use parent qw(IO::Async::Stream); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | our $VERSION = '0.004'; ## VERSION | |||||||||
| 8 | ## AUTHORITY | ||||||||||
| 9 | |||||||||||
| 10 | =head1 NAME | ||||||||||
| 11 | |||||||||||
| 12 | Net::Async::SMTP::Connection - stream subclass for dealing with SMTP connections | ||||||||||
| 13 | |||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||
| 15 | |||||||||||
| 16 | Used internally by L<Net::Async::SMTP>. No user-serviceable parts inside. | ||||||||||
| 17 | |||||||||||
| 18 | Timeouts: | ||||||||||
| 19 | |||||||||||
| 20 | RFC821 4.5.3.2 - An SMTP client MUST provide a timeout mechanism | ||||||||||
| 21 | |||||||||||
| 22 | greeting_timeout => 300, | ||||||||||
| 23 | mail_timeout => 300, | ||||||||||
| 24 | rcpt_timeout => 300, | ||||||||||
| 25 | data_timeout => 120, | ||||||||||
| 26 | data_block_timeout => 180, | ||||||||||
| 27 | data_finish_timeout => 600, | ||||||||||
| 28 | |||||||||||
| 29 | =cut | ||||||||||
| 30 | |||||||||||
| 31 | 2 | ▶ | use IO::Socket::SSL qw(SSL_VERIFY_NONE); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 2 | ▶ | use Protocol::SMTP::Client; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | |||||||||||
| 34 | 0 | ▶ | sub configure { | ||||||||
|
Subroutine
configure: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 35 | 0 | my $self = shift; | |||||||||
| 36 | 0 | my %args = @_; | |||||||||
| 37 | 0 | ▶ | $self->{auth} = delete $args{auth} if exists $args{auth}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | $self->SUPER::configure(%args) | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | sub _add_to_loop { | ||||||||
|
Subroutine
_add_to_loop: not called CC=1 SCAR=6.9
| |||||||||||
| 42 | 0 | my ($self, $loop) = @_; | |||||||||
| 43 | $self->{protocol} = Protocol::SMTP::Client->new( | ||||||||||
| 44 | 0 | ▶ | future_factory => sub { $loop->new_future }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 45 | 0 | ▶ | writer => sub { $self->write(@_) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 46 | 0 | auth_mechanism_override => $self->auth, | |||||||||
| 47 | ); | ||||||||||
| 48 | 0 | $self->protocol->startup; | |||||||||
| 49 | 0 | $self->SUPER::_add_to_loop($loop); | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | sub _remove_from_loop { | ||||||||
|
Subroutine
_remove_from_loop: not called CC=1 SCAR=6.9
| |||||||||||
| 53 | 0 | my ($self, $loop) = @_; | |||||||||
| 54 | 0 | delete $self->{protocol}; | |||||||||
| 55 | 0 | $self->SUPER::_remove_from_loop($loop); | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 0 | ▶ | sub auth { shift->{auth} } | ||||||||
|
Subroutine
auth: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 59 | 0 | ▶ | sub protocol { shift->{protocol} } | ||||||||
|
Subroutine
protocol: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 60 | |||||||||||
| 61 | 0 | ▶ | sub send_greeting { | ||||||||
|
Subroutine
send_greeting: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 62 | 0 | my $self = shift; | |||||||||
| 63 | # Start with our greeting, which should receive back a nice list of features | ||||||||||
| 64 | 0 | $self->protocol->send_greeting; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 0 | ▶ | sub starttls { | ||||||||
|
Subroutine
starttls: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 68 | 0 | my $self = shift; | |||||||||
| 69 | 0 | my %args = @_; | |||||||||
| 70 | 0 | $self->debug_printf("STARTTLS"); | |||||||||
| 71 | 0 | ▶ | die "This server does not support TLS" unless $self->has_feature('STARTTLS'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | |||||||||||
| 73 | 0 | require IO::Async::SSL; | |||||||||
| 74 | 0 | ▶ | $self->protocol->starttls->then(sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 75 | $self->loop->SSL_upgrade( | ||||||||||
| 76 | handle => $self, | ||||||||||
| 77 | # SSL_verify_mode => SSL_VERIFY_NONE, | ||||||||||
| 78 | %args, | ||||||||||
| 79 | 0 | ▶ | )->on_done(sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 80 | 0 | $self->debug_printf("STARTTLS successful"); | |||||||||
| 81 | }) | ||||||||||
| 82 | ->then($self->curry::send_greeting) | ||||||||||
| 83 | 0 | ▶ | ->transform(done => sub { $self }); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 84 | 0 | }); | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | 0 | ▶ | sub on_read { | ||||||||
|
Subroutine
on_read: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 88 | 0 | my ($self, $buffref) = @_; | |||||||||
| 89 | 0 | ▶ | while( $$buffref =~ s/^(.*)\x0D\x0A// ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | 0 | my $line = $1; | |||||||||
| 91 | 0 | ▶ | if($self->{sending_content}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | 0 | warn "- this is awkward; we shouldn't have anything because we're in the middle of sending: $1"; | |||||||||
| 93 | } else { | ||||||||||
| 94 | 0 | $self->protocol->handle_line($line); | |||||||||
| 95 | } | ||||||||||
| 96 | } | ||||||||||
| 97 | 0 | return 0; | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 0 | ▶ | sub has_feature { my $self = shift; $self->protocol->has_feature(@_) } | ||||||||
|
Subroutine
has_feature: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 101 | 0 | ▶ | sub send { my $self = shift; $self->protocol->send(@_) } | ||||||||
|
Subroutine
send: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 102 | 0 | ▶ | sub login { my $self = shift; $self->protocol->login(@_) } | ||||||||
|
Subroutine
login: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 103 | 0 | ▶ | sub quit { my $self = shift; $self->protocol->quit(@_) } | ||||||||
|
Subroutine
quit: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 104 | |||||||||||
| 105 | 2 | 1; | |||||||||
| 106 | |||||||||||
| 107 | =head1 AUTHOR | ||||||||||
| 108 | |||||||||||
| 109 | Tom Molesworth <TEAM@cpan.org> | ||||||||||
| 110 | |||||||||||
| 111 | =head1 LICENSE | ||||||||||
| 112 | |||||||||||
| 113 | Copyright Tom Molesworth 2012-2024. Licensed under the same terms as Perl itself. | ||||||||||
| 114 | |||||||||||