| 1 | package Serge::Mail; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | no warnings qw(uninitialized); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use MIME::Lite; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Net::SMTP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | our $debug = $ENV{SMTP_DEBUG} == 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | our $disable = $ENV{SMTP_DISABLE} == 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | our $force_to = $ENV{SMTP_FORCE_RECIPIENTS}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | our $host = $ENV{SMTP_HOST} || 'localhost'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'SMTP_HOST'} || 'localhost'
MC/DC0%0/1
$ENV{'SMTP_HOST'} || 'localhost'
$ENV{'SMTP_HOST'}
Truth table50%1/2
A
A= $ENV{'SMTP_HOST'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | our $port = $ENV{SMTP_PORT} || 25; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'SMTP_PORT'} || 25
MC/DC0%0/1
$ENV{'SMTP_PORT'} || 25
$ENV{'SMTP_PORT'}
Truth table50%1/2
A
A= $ENV{'SMTP_PORT'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | our $user = $ENV{SMTP_USERNAME}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | our $pass = $ENV{SMTP_PASSWORD}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | if ($pass && !$user || $user && !$pass) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$Serge::Mail::pass and not $Serge::Mail::user or $Serge::Mail::user and not $Serge::Mail::pass
$Serge::Mail::pass and not $Serge::Mail::user
$Serge::Mail::user and not $Serge::Mail::pass
MC/DC0%0/4
$Serge::Mail::pass and not $Serge::Mail::user or $Serge::Mail::user and not $Serge::Mail::pass
$Serge::Mail::pass
not $Serge::Mail::user
$Serge::Mail::user
not $Serge::Mail::pass
Truth table0%0/7
A and not(B) or C and not(D)
A= $Serge::Mail::passB= not $Serge::Mail::userC= $Serge::Mail::userD= not $Serge::Mail::pass
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | die "Both SMTP_PASSWORD and SMTP_USERNAME should be provided (or neither one)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | our $use_ssl = ($port == 465); # autodetect | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | $use_ssl = ($ENV{SMTP_USE_SSL} == 1) if exists $ENV{SMTP_USE_SSL}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | $use_ssl = undef if exists $ENV{SMTP_NO_SSL}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | if ($debug) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | print "SMTP Host: $host\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | print "SMTP Port: $port\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | print "SMTP SSL : ".($use_ssl ? 'YES' : 'NO')."\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | print "SMTP User: $user\n" if $user; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | sub _send { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my ($from, $toref, $ccref, $bccref, $data) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_send: not called CC=19 SCAR=59.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ($disable) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | print "Warning: email will not be sent because of SMTP_DISABLE environment variable\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my $smtp = Net::SMTP->new($host, Port => $port, SSL => $use_ssl, Debug => $debug); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | warn "Failed to send the following email:\n$data\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | warn $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ($user) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $smtp->auth($user, $pass) or die "auth() call failed for user '$user'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | $smtp->mail("$from\n") or die "mail(from) call failed; from='$from'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my @to = @$toref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ($force_to) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | @to = split(',', $force_to); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | print "Warning: the list of email recipients is overridden by SMTP_FORCE_RECIPIENTS environment variable\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | print "Email will be sent to: ", join(', ', sort @to), "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | foreach my $recpt (@to) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | $smtp->to($recpt) or die "to(rcpt) call failed; rcpt='$recpt'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if (defined($ccref)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | foreach my $recpt (@$ccref) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | $smtp->cc($recpt) or die "cc(rcpt) call failed; rcpt='$recpt'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if (defined($bccref)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | foreach my $recpt (@$bccref) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | $smtp->bcc($recpt) or die "bcc(rcpt) call failed; rcpt='$recpt'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | $smtp->data() or die "data() call failed"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | $smtp->datasend($data) or die "datasend() call failed"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | $smtp->dataend() or die "dataend() call failed"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | $smtp->quit() or die "quit() call failed"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | sub sendmessage { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | my ($from, $toref, $subject, $body, $ccref, $bccref) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sendmessage: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | $body = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | "From: $from\n". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | "To: ".join(', ', @$toref)."\n". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | "Cc: ". (defined($ccref) ? join(', ', @$ccref) : '') ."\n". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | "Bcc: ". (defined($bccref) ? join(', ', @$bccref) : '') ."\n". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | "Subject: $subject\n". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | "\n". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | "$body\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | _send($from, $toref, $ccref, $bccref, $body); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | sub send_html_message { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | my ($from, $toref, $subject, $body, $ccref, $bccref) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_html_message: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | ### Create a new multipart message: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | my $msg = MIME::Lite->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | From => $from, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | To => join(', ', @$toref), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | Cc => defined($ccref) ? join(', ', @$ccref) : '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | Bcc => defined($bccref) ? join(', ', @$bccref) : '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | Subject => $subject, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | Type => 'multipart/mixed' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $msg->attach( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | Type => 'text/html; charset=utf-8', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | Data => $body | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | _send($from, $toref, $ccref, $bccref, $msg->as_string); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||