| 1 | # Copyrights 2001-2020 by [Mark Overmeer]. | ||||||||||||||||||||||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||||||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||||||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 2.02. | ||||||||||||||||||||||||||||||||||||||
| 5 | # This code is part of distribution Mail-Transport. Meta-POD processed with | ||||||||||||||||||||||||||||||||||||||
| 6 | # OODoc into POD and HTML manual-pages. See README.md | ||||||||||||||||||||||||||||||||||||||
| 7 | # Copyright Mark Overmeer. Licensed under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||
| 9 | package Mail::Transport::SMTP; | ||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | 1 | $VERSION = '3.005'; | |||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use base 'Mail::Transport::Send'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Net::SMTP; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||
| 21 | sub init($) | ||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my $hosts = $args->{hostname}; | |||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | unless($hosts) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 26 | 0 | { require Net::Config; | |||||||||||||||||||||||||||||||||||||
| 27 | 0 | $hosts = $Net::Config::NetConfig{smtp_hosts}; | |||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | undef $hosts unless @$hosts; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 29 | 0 | $args->{hostname} = $hosts; | |||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | $args->{via} ||= 'smtp'; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args->{"via"} ||= "smtp"
MC/DC0%0/1
$args->{"via"} ||= "smtp"
$args->{"via"}
Truth table0%0/2
A
A= $args->{"via"}
| |||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | $args->{port} ||= '25'; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args->{"port"} ||= 25
MC/DC0%0/1
$args->{"port"} ||= 25
$args->{"port"}
Truth table0%0/2
A
A= $args->{"port"}
| |||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | $self->SUPER::init($args) or return; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||
| 37 | my $helo = $args->{helo} | ||||||||||||||||||||||||||||||||||||||
| 38 | 0 | || eval { require Net::Config; $Net::Config::NetConfig{inet_domain} } | |||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | || eval { require Net::Domain; Net::Domain::hostfqdn() }; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$args->{'helo'} || eval {
do {
require Net::Config;
$Net::Config::NetConfig{'inet_domain'}
}
} || eval {
do {
require Net::Domain;
Net::Domain::hostfqdn()
}
}
$args->{"helo"} or eval {
do {
require Net::Config;
$Net::Config::NetConfig{"inet_domain"}
}
}
MC/DC0%0/3
$args->{'helo'} || eval {
do {
require Net::Config;
$Net::Config::NetConfig{'inet_domain'}
}
} || eval {
do {
require Net::Domain;
Net::Domain::hostfqdn()
}
}
$args->{"helo"}
eval {
do {
require Net::Config;
$Net::Config::NetConfig{"inet_domain"}
}
}
eval {
do {
require Net::Domain;
Net::Domain::hostfqdn()
}
}
Truth table0%0/4
A or B || C
A= $args->{"helo"}B= eval {
do {
require Net::Config;
$Net::Config::NetConfig{"inet_domain"}
}
}C= eval {
do {
require Net::Domain;
Net::Domain::hostfqdn()
}
}
| |||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||
| 41 | $self->{MTS_net_smtp_opts} = | ||||||||||||||||||||||||||||||||||||||
| 42 | +{ Hello => $helo | ||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | , Debug => ($args->{smtp_debug} || 0) | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'smtp_debug'} || 0
MC/DC0%0/1
$args->{'smtp_debug'} || 0
$args->{'smtp_debug'}
Truth table0%0/2
A
A= $args->{'smtp_debug'}
| |||||||||||||||||||||||||||||||||||||||
| 44 | }; | ||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $self->{MTS_esmtp_options} = $args->{esmtp_options}; | |||||||||||||||||||||||||||||||||||||
| 46 | 0 | $self->{MTS_from} = $args->{from}; | |||||||||||||||||||||||||||||||||||||
| 47 | 0 | $self; | |||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||
| 51 | sub trySend($@) | ||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | { my ($self, $message, %args) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
trySend: not called CC=23 SCAR=63.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||
| 54 | my %send_options = | ||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | ( %{$self->{MTS_esmtp_options} || {}} | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | , %{$args{esmtp_options} || {}} | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||
| 59 | # From whom is this message. | ||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my $from = $args{from} || $self->{MTS_from} || $message->sender || '<>'; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/8
$args{'from'} || $self->{'MTS_from'} || $message->sender || '<>'
$args{"from"} or $self->{"MTS_from"} or $message->sender
$args{"from"} or $self->{"MTS_from"}
MC/DC0%0/3
$args{'from'} || $self->{'MTS_from'} || $message->sender || '<>'
$args{"from"}
$self->{"MTS_from"}
$message->sender
Truth table0%0/4
A or B or C
A= $args{"from"}B= $self->{"MTS_from"}C= $message->sender
| |||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | $from = $from->address if ref $from && $from->isa('Mail::Address'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $from and $from->isa("Mail::Address")
MC/DC0%0/2
ref $from and $from->isa("Mail::Address")
ref $from
$from->isa("Mail::Address")
Truth table0%0/3
A and B
A= ref $fromB= $from->isa("Mail::Address")
| |||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||
| 63 | # Which are the destinations. | ||||||||||||||||||||||||||||||||||||||
| 64 | ! defined $args{To} | ||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | or $self->log(WARNING => | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 66 | "Use option `to' to overrule the destination: `To' refers to a field"); | ||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my @to = map $_->address, $self->destinations($message, $args{to}); | |||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | unless(@to) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 71 | 0 | { $self->log(NOTICE => | |||||||||||||||||||||||||||||||||||||
| 72 | 'No addresses found to send the message to, no connection made'); | ||||||||||||||||||||||||||||||||||||||
| 73 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||
| 76 | # Prepare the header | ||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my @headers; | |||||||||||||||||||||||||||||||||||||
| 78 | 0 | require IO::Lines; | |||||||||||||||||||||||||||||||||||||
| 79 | 0 | my $lines = IO::Lines->new(\@headers); | |||||||||||||||||||||||||||||||||||||
| 80 | 0 | $message->head->printUndisclosed($lines); | |||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||
| 82 | # | ||||||||||||||||||||||||||||||||||||||
| 83 | # Send | ||||||||||||||||||||||||||||||||||||||
| 84 | # | ||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if(wantarray) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 87 | { # In LIST context | ||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $server; | |||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | return (0, 500, "Connection Failed", "CONNECT", 0) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 90 | unless $server = $self->contactAnyServer; | ||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | return (0, $server->code, $server->message, 'FROM', $server->quit) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 93 | unless $server->mail($from, %send_options); | ||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||
| 95 | 0 | foreach (@to) | |||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | { next if $server->to($_); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 97 | # must we be able to disable this? | ||||||||||||||||||||||||||||||||||||||
| 98 | # next if $args{ignore_erroneous_destinations} | ||||||||||||||||||||||||||||||||||||||
| 99 | 0 | return (0, $server->code, $server->message,"To $_",$server->quit); | |||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my $bodydata = $message->body->file; | |||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $server->data; | |||||||||||||||||||||||||||||||||||||
| 105 | 0 | $server->datasend(\@headers); | |||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | $server->datasend( [ ref $bodydata eq 'GLOB' ? <$bodydata> : $bodydata->getlines ] ); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | $server->dataend | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 108 | or return (0, $server->code, $server->message,'DATA',$server->quit); | ||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $accept = ($server->message)[-1]; | |||||||||||||||||||||||||||||||||||||
| 111 | 0 | chomp $accept; | |||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my $rc = $server->quit; | |||||||||||||||||||||||||||||||||||||
| 114 | 0 | return ($rc, $server->code, $server->message, 'QUIT', $rc, $accept); | |||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||
| 117 | # in SCALAR context | ||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $server; | |||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | return 0 unless $server = $self->contactAnyServer; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | $server->quit, return 0 | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 122 | unless $server->mail($from, %send_options); | ||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||
| 124 | 0 | foreach (@to) | |||||||||||||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | next if $server->to($_); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 127 | # must we be able to disable this? | ||||||||||||||||||||||||||||||||||||||
| 128 | # next if $args{ignore_erroneous_destinations} | ||||||||||||||||||||||||||||||||||||||
| 129 | 0 | $server->quit; | |||||||||||||||||||||||||||||||||||||
| 130 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my $bodydata = $message->body->file; | |||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $server->data; | |||||||||||||||||||||||||||||||||||||
| 136 | 0 | $server->datasend(\@headers); | |||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | $server->datasend( [ ref $bodydata eq 'GLOB' ? <$bodydata> : $bodydata->getlines ] ); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | $server->quit, return 0 | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 140 | unless $server->dataend; | ||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $server->quit; | |||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||
| 145 | #------------------------------------------ | ||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||
| 147 | sub contactAnyServer() | ||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
contactAnyServer: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my ($enterval, $count, $timeout) = $self->retry; | |||||||||||||||||||||||||||||||||||||
| 151 | 0 | my ($host, $port, $username, $password) = $self->remoteHost; | |||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | my @hosts = ref $host ? @$host : $host; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||
| 154 | 0 | foreach my $host (@hosts) | |||||||||||||||||||||||||||||||||||||
| 155 | { my $server = $self->tryConnectTo | ||||||||||||||||||||||||||||||||||||||
| 156 | ( $host, Port => $port, | ||||||||||||||||||||||||||||||||||||||
| 157 | 0 | , %{$self->{MTS_net_smtp_opts}}, Timeout => $timeout | |||||||||||||||||||||||||||||||||||||
| 158 | ); | ||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | defined $server or next; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $self->log(PROGRESS => "Opened SMTP connection to $host."); | |||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if(defined $username) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | { if($server->auth($username, $password)) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 166 | 0 | { $self->log(PROGRESS => "$host: Authentication succeeded."); | |||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||
| 168 | else | ||||||||||||||||||||||||||||||||||||||
| 169 | 0 | { $self->log(ERROR => "Authentication failed."); | |||||||||||||||||||||||||||||||||||||
| 170 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||
| 174 | 0 | return $server; | |||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||
| 177 | 0 | undef; | |||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||
| 181 | sub tryConnectTo($@) | ||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | { my ($self, $host) = (shift, shift); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
tryConnectTo: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 183 | 0 | Net::SMTP->new($host, @_); | |||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||
| 186 | 1 | 1; | |||||||||||||||||||||||||||||||||||||