| 1 | package Email::Sender::Transport::SMTP 2.603; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: send email over SMTP | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Email::Sender::Failure::Multi; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Email::Sender::Success::Partial; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Email::Sender::Role::HasMessage (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Email::Sender::Util; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use MooX::Types::MooseLike::Base qw(Bool InstanceOf Int Str HashRef); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Net::SMTP 3.07; # SSL support, fixed datasend | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use utf8 (); # See below. -- rjbs, 2015-05-14 | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | #pod =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 16 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 17 | #pod This transport is used to send email over SMTP, either with or without secure | ||||||||||||||||||||||||||||||||||||||||||
| 18 | #pod sockets (SSL/TLS). It is one of the most complex transports available, capable | ||||||||||||||||||||||||||||||||||||||||||
| 19 | #pod of partial success. | ||||||||||||||||||||||||||||||||||||||||||
| 20 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 21 | #pod For a potentially more efficient version of this transport, see | ||||||||||||||||||||||||||||||||||||||||||
| 22 | #pod L<Email::Sender::Transport::SMTP::Persistent>. | ||||||||||||||||||||||||||||||||||||||||||
| 23 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 24 | #pod =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||||
| 25 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 26 | #pod The following attributes may be passed to the constructor: | ||||||||||||||||||||||||||||||||||||||||||
| 27 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 28 | #pod =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 29 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 30 | #pod =item C<hosts>: an arrayref of names of the host to try, in order; defaults to a single element array containing C<localhost> | ||||||||||||||||||||||||||||||||||||||||||
| 31 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 32 | #pod The attribute C<host> may be given, instead, which contains a single hostname. | ||||||||||||||||||||||||||||||||||||||||||
| 33 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 34 | #pod =item C<ssl>: if 'starttls', use STARTTLS; if 'ssl' (or 1), connect securely; | ||||||||||||||||||||||||||||||||||||||||||
| 35 | #pod if 'maybestarttls', use STARTTLS if available; otherwise, no security | ||||||||||||||||||||||||||||||||||||||||||
| 36 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 37 | #pod =item C<ssl_options>: passed to Net::SMTP constructor for 'ssl' connections or | ||||||||||||||||||||||||||||||||||||||||||
| 38 | #pod to starttls for 'starttls' or 'maybestarttls' connections; should contain extra | ||||||||||||||||||||||||||||||||||||||||||
| 39 | #pod options for IO::Socket::SSL | ||||||||||||||||||||||||||||||||||||||||||
| 40 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 41 | #pod =item C<port>: port to connect to; defaults to 25 for non-SSL, 465 for 'ssl', | ||||||||||||||||||||||||||||||||||||||||||
| 42 | #pod 587 for 'starttls' | ||||||||||||||||||||||||||||||||||||||||||
| 43 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 44 | #pod =item C<timeout>: maximum time in secs to wait for server; default is 120 | ||||||||||||||||||||||||||||||||||||||||||
| 45 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 46 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 50 | Carp::croak("do not pass port number to SMTP transport in host, use port parameter") | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if grep {; /:/ } $self->hosts; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ($self->sasl_username and not defined $self->sasl_password) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->sasl_username and not defined $self->sasl_password
MC/DC0%0/2
$self->sasl_username and not defined $self->sasl_password
$self->sasl_username
not defined $self->sasl_password
Truth table0%0/3
A and not(B)
A= $self->sasl_usernameB= not defined $self->sasl_password
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $self->_throw("sasl_username but no sasl_password"); | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my ($self, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $arg = $self->SUPER::BUILDARGS(@rest); | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if (exists $arg->{host}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | Carp::croak("can't pass both host and hosts to constructor") | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if exists $arg->{hosts}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $arg->{hosts} = [ delete $arg->{host} ]; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if (exists $arg->{sasl_authenticator} and exists $arg->{sasl_username}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $arg->{"sasl_authenticator"} and exists $arg->{"sasl_username"}
MC/DC0%0/2
exists $arg->{"sasl_authenticator"} and exists $arg->{"sasl_username"}
exists $arg->{"sasl_authenticator"}
exists $arg->{"sasl_username"}
Truth table0%0/3
A and B
A= exists $arg->{"sasl_authenticator"}B= exists $arg->{"sasl_username"}
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | Carp::croak("can't pass both sasl_authenticator and sasl_username to constructor"); | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | return $arg; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | has ssl => (is => 'ro', isa => Str, default => sub { 0 }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | has _hosts => ( | ||||||||||||||||||||||||||||||||||||||||||
| 79 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | isa => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | die "invalid hosts in Email::Sender::Transport::SMTP constructor" | ||||||||||||||||||||||||||||||||||||||||||
| 82 | unless defined $_[0] | ||||||||||||||||||||||||||||||||||||||||||
| 83 | && (ref $_[0] eq 'ARRAY') | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | && (grep {; length } @{ $_[0] }) > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $_[0] and ref $_[0] eq "ARRAY" and grep({length $_;} @{$_[0];}) > 0
defined $_[0] and ref $_[0] eq "ARRAY"
MC/DC0%0/3
defined $_[0] and ref $_[0] eq "ARRAY" and grep({length $_;} @{$_[0];}) > 0
defined $_[0]
ref $_[0] eq "ARRAY"
grep({length $_;} @{$_[0];}) > 0
Truth table0%0/4
A and B and C
A= defined $_[0]B= ref $_[0] eq "ARRAY"C= grep({length $_;} @{$_[0];}) > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | default => sub { [ 'localhost' ] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | init_arg => 'hosts', | |||||||||||||||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub hosts { @{ $_[0]->_hosts } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hosts: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub host { $_[0]->_hosts->[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
host: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | has _security => ( | ||||||||||||||||||||||||||||||||||||||||||
| 95 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 96 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 97 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $ssl = $_[0]->ssl; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | return '' unless $ssl; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $ssl = lc $ssl; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | return 'starttls' if 'starttls' eq $ssl; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | return 'maybestarttls' if 'maybestarttls' eq $ssl; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | return 'ssl' if $ssl eq 1 or $ssl eq 'ssl'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ssl eq 1 or $ssl eq "ssl"
MC/DC0%0/2
$ssl eq 1 or $ssl eq "ssl"
$ssl eq 1
$ssl eq "ssl"
Truth table0%0/3
A or B
A= $ssl eq 1B= $ssl eq "ssl"
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | Carp::cluck(qq{"ssl" argument to Email::Sender::Transport::SMTP was "$ssl" rather than one of the permitted values: maybestarttls, starttls, ssl}); | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 109 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | has ssl_options => (is => 'ro', isa => HashRef, default => sub { {} }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | has port => ( | ||||||||||||||||||||||||||||||||||||||||||
| 115 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 116 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||
| 117 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | return $_[0]->_security eq 'starttls' ? 587 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | : $_[0]->_security eq 'ssl' ? 465 | ||||||||||||||||||||||||||||||||||||||||||
| 121 | : 25 | ||||||||||||||||||||||||||||||||||||||||||
| 122 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | has timeout => (is => 'ro', isa => Int, default => sub { 120 }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | #pod =item C<sasl_username>: the username to use for auth; optional | ||||||||||||||||||||||||||||||||||||||||||
| 128 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 129 | #pod =item C<sasl_password>: the password to use for auth; required if C<sasl_username> is provided | ||||||||||||||||||||||||||||||||||||||||||
| 130 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 131 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 2 | has sasl_username => (is => 'ro', isa => Str); | |||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | has sasl_password => (is => 'ro', isa => Str); | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | #pod =item C<sasl_authenticator>: An C<Authen::SASL> instance to use for auth; optional | ||||||||||||||||||||||||||||||||||||||||||
| 137 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 138 | #pod The C<sasl_authenticator> and C<sasl_username> attributes are mutually exclusive. | ||||||||||||||||||||||||||||||||||||||||||
| 139 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 140 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | has sasl_authenticator => (is => 'ro', isa => InstanceOf['Authen::SASL']); | |||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | #pod =item C<allow_partial_success>: if true, will send data even if some recipients were rejected; defaults to false | ||||||||||||||||||||||||||||||||||||||||||
| 145 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 146 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | has allow_partial_success => (is => 'ro', isa => Bool, default => sub { 0 }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | #pod =item C<helo>: what to say when saying HELO; no default | ||||||||||||||||||||||||||||||||||||||||||
| 151 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 152 | #pod =item C<localaddr>: local address from which to connect | ||||||||||||||||||||||||||||||||||||||||||
| 153 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 154 | #pod =item C<localport>: local port from which to connect | ||||||||||||||||||||||||||||||||||||||||||
| 155 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 156 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | has helo => (is => 'ro', isa => Str); | |||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | has localaddr => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | has localport => (is => 'ro', isa => Int); | |||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | #pod =item C<debug>: if true, put the L<Net::SMTP> object in debug mode | ||||||||||||||||||||||||||||||||||||||||||
| 163 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 164 | #pod =back | ||||||||||||||||||||||||||||||||||||||||||
| 165 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 166 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | has debug => (is => 'ro', isa => Bool, default => sub { 0 }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | # I am basically -sure- that this is wrong, but sending hundreds of millions of | ||||||||||||||||||||||||||||||||||||||||||
| 171 | # messages has shown that it is right enough. I will try to make it textbook | ||||||||||||||||||||||||||||||||||||||||||
| 172 | # later. -- rjbs, 2008-12-05 | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | sub _quoteaddr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quoteaddr: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | my $addr = shift; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | my @localparts = split /\@/, $addr; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my $domain = pop @localparts; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | my $localpart = join q{@}, @localparts; | |||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | return $addr # The first regex here is RFC 821 "specials" excepting dot. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$localpart =~ /[\x00-\x1F\x7F<>\(\)\[\]\\,;:\@"]/ or $localpart =~ /^\./ or $localpart =~ /\.$/
$localpart =~ /[\x00-\x1F\x7F<>\(\)\[\]\\,;:\@"]/ or $localpart =~ /^\./
MC/DC0%0/3
$localpart =~ /[\x00-\x1F\x7F<>\(\)\[\]\\,;:\@"]/ or $localpart =~ /^\./ or $localpart =~ /\.$/
$localpart =~ /[\x00-\x1F\x7F<>\(\)\[\]\\,;:\@"]/
$localpart =~ /^\./
$localpart =~ /\.$/
Truth table0%0/4
A or B or C
A= $localpart =~ /[\x00-\x1F\x7F<>\(\)\[\]\\,;:\@"]/B= $localpart =~ /^\./C= $localpart =~ /\.$/
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | unless $localpart =~ /[\x00-\x1F\x7F<>\(\)\[\]\\,;:@"]/ | ||||||||||||||||||||||||||||||||||||||||||
| 181 | or $localpart =~ /^\./ | ||||||||||||||||||||||||||||||||||||||||||
| 182 | or $localpart =~ /\.$/; | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | return join q{@}, qq("$localpart"), $domain; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub _maybe_auth { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_maybe_auth: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my ($self, $smtp) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | if ($self->sasl_username) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | return $smtp->auth($self->sasl_username, $self->sasl_password); | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | if ($self->sasl_authenticator) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | return $smtp->auth($self->sasl_authenticator); | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | sub _smtp_client { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_smtp_client: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | my $class = "Net::SMTP"; | |||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my $smtp = $class->new( $self->_net_smtp_args ); | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | unless ($smtp) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | $self->_throw( | |||||||||||||||||||||||||||||||||||||||||
| 209 | sprintf "unable to establish SMTP connection to (%s) port %s", | ||||||||||||||||||||||||||||||||||||||||||
| 210 | (join q{, }, $self->hosts), | ||||||||||||||||||||||||||||||||||||||||||
| 211 | $self->port, | ||||||||||||||||||||||||||||||||||||||||||
| 212 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | if ($self->_security eq 'starttls') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | $self->_throw("can't STARTTLS: " . $smtp->message) | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | unless $smtp->starttls(%{ $self->ssl_options }); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | if ($self->_security eq 'maybestarttls') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | if ( $smtp->supports('STARTTLS', 500, ["Command unknown: 'STARTTLS'"]) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | $self->_throw("can't STARTTLS: " . $smtp->message) | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | unless $smtp->starttls(%{ $self->ssl_options }); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | unless ($self->_maybe_auth($smtp)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | if ($smtp->message =~ /MIME::Base64|Authen::SASL/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | Carp::confess("SMTP auth requires MIME::Base64 and Authen::SASL"); | |||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | $self->_throw('failed AUTH', $smtp); | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | return $smtp; | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | sub _net_smtp_args { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_net_smtp_args: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 242 | [ $self->hosts ], | ||||||||||||||||||||||||||||||||||||||||||
| 243 | Port => $self->port, | ||||||||||||||||||||||||||||||||||||||||||
| 244 | Timeout => $self->timeout, | ||||||||||||||||||||||||||||||||||||||||||
| 245 | Debug => $self->debug, | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | (($self->_security eq 'ssl') | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | ? (SSL => 1, %{ $self->ssl_options }) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | defined $self->helo ? (Hello => $self->helo) : (), | ||||||||||||||||||||||||||||||||||||||||||
| 252 | defined $self->localaddr ? (LocalAddr => $self->localaddr) : (), | ||||||||||||||||||||||||||||||||||||||||||
| 253 | defined $self->localport ? (LocalPort => $self->localport) : (), | ||||||||||||||||||||||||||||||||||||||||||
| 254 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | sub _throw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_throw: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | my ($self, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | Email::Sender::Util->_failure(@rest)->throw; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | sub send_email { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_email: not called CC=16 SCAR=56.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | my ($self, $email, $env) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | Email::Sender::Failure->throw("no valid addresses in recipient list") | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | unless my @to = grep { defined and length } @{ $env->{to} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $_ && length $_
MC/DC0%0/2
defined $_ && length $_
defined $_
length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | my $smtp = $self->_smtp_client; | |||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | my $FAULT = sub { $self->_throw($_[0], $smtp); }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | $smtp->mail(_quoteaddr($env->{from})) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | or $FAULT->("$env->{from} failed after MAIL FROM"); | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my @failures; | |||||||||||||||||||||||||||||||||||||||||
| 276 | my @ok_rcpts; | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | for my $addr (@to) { | |||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | if ($smtp->to(_quoteaddr($addr))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | push @ok_rcpts, $addr; | |||||||||||||||||||||||||||||||||||||||||
| 281 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 282 | # my ($self, $error, $smtp, $error_class, @rest) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | push @failures, Email::Sender::Util->_failure( | |||||||||||||||||||||||||||||||||||||||||
| 284 | undef, | ||||||||||||||||||||||||||||||||||||||||||
| 285 | $smtp, | ||||||||||||||||||||||||||||||||||||||||||
| 286 | recipients => [ $addr ], | ||||||||||||||||||||||||||||||||||||||||||
| 287 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | # This logic used to include: or (@ok_rcpts == 1 and $ok_rcpts[0] eq '0') | ||||||||||||||||||||||||||||||||||||||||||
| 292 | # because if called without SkipBad, $smtp->to can return 1 or 0. This | ||||||||||||||||||||||||||||||||||||||||||
| 293 | # should not happen because we now always pass SkipBad and do the counting | ||||||||||||||||||||||||||||||||||||||||||
| 294 | # ourselves. Still, I've put this comment here (a) in memory of the | ||||||||||||||||||||||||||||||||||||||||||
| 295 | # suffering it caused to have to find that problem and (b) in case the | ||||||||||||||||||||||||||||||||||||||||||
| 296 | # original problem is more insidious than I thought! -- rjbs, 2008-12-05 | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
@failures and @ok_rcpts == 0 || !$self->allow_partial_success
@ok_rcpts == 0 or not $self->allow_partial_success
MC/DC0%0/3
@failures and @ok_rcpts == 0 || !$self->allow_partial_success
@failures
@ok_rcpts == 0
not $self->allow_partial_success
Truth table0%0/4
A and B or not(C)
A= @failuresB= @ok_rcpts == 0C= not $self->allow_partial_success
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | @failures | ||||||||||||||||||||||||||||||||||||||||||
| 300 | and ((@ok_rcpts == 0) or (! $self->allow_partial_success)) | ||||||||||||||||||||||||||||||||||||||||||
| 301 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | $failures[0]->throw if @failures == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | my $message = sprintf '%s recipients were rejected during RCPT', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | @ok_rcpts ? 'some' : 'all'; | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | Email::Sender::Failure::Multi->throw( | |||||||||||||||||||||||||||||||||||||||||
| 308 | message => $message, | ||||||||||||||||||||||||||||||||||||||||||
| 309 | failures => \@failures, | ||||||||||||||||||||||||||||||||||||||||||
| 310 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | # restore Pobox's support for streaming, code-based messages, and arrays here | ||||||||||||||||||||||||||||||||||||||||||
| 314 | # -- rjbs, 2008-12-04 | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | $smtp->data or $FAULT->("error at DATA start"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my $msg_string = $email->as_string; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | my $hunk_size = $self->_hunk_size; | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | while (length $msg_string) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | my $next_hunk = substr $msg_string, 0, $hunk_size, ''; | |||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | $smtp->datasend($next_hunk) or $FAULT->("error at during DATA"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | $smtp->dataend or $FAULT->("error at after DATA"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my $message = $smtp->message; | |||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $self->_message_complete($smtp); | |||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | # We must report partial success (failures) if applicable. | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | return $self->success({ message => $message }) unless @failures; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | return $self->partial_success({ | |||||||||||||||||||||||||||||||||||||||||
| 336 | message => $message, | ||||||||||||||||||||||||||||||||||||||||||
| 337 | failure => Email::Sender::Failure::Multi->new({ | ||||||||||||||||||||||||||||||||||||||||||
| 338 | message => 'some recipients were rejected during RCPT', | ||||||||||||||||||||||||||||||||||||||||||
| 339 | failures => \@failures | ||||||||||||||||||||||||||||||||||||||||||
| 340 | }), | ||||||||||||||||||||||||||||||||||||||||||
| 341 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | sub _hunk_size { 2**20 } # send messages to DATA in hunks of 1 mebibyte | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hunk_size: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | sub success { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
success: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | my $success = Moo::Role->create_class_with_roles('Email::Sender::Success', 'Email::Sender::Role::HasMessage')->new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | sub partial_success { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
partial_success: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | my $partial_success = Moo::Role->create_class_with_roles('Email::Sender::Success::Partial', 'Email::Sender::Role::HasMessage')->new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | sub _message_complete { $_[1]->quit; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_message_complete: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | #pod =head1 PARTIAL SUCCESS | ||||||||||||||||||||||||||||||||||||||||||
| 359 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 360 | #pod If C<allow_partial_success> was set when creating the transport, the transport | ||||||||||||||||||||||||||||||||||||||||||
| 361 | #pod may return L<Email::Sender::Success::Partial> objects. Consult that module's | ||||||||||||||||||||||||||||||||||||||||||
| 362 | #pod documentation. | ||||||||||||||||||||||||||||||||||||||||||
| 363 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 364 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 2 | with 'Email::Sender::Transport'; | |||||||||||||||||||||||||||||||||||||||||
| 367 | 2 | ▶ | no Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | __END__ | ||||||||||||||||||||||||||||||||||||||||||