Send/SMTP.pm

filter: Statementstmt 30.6% 19 / 62 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 66.6% 6 / 9 Podpod 0.0% 0 / 2 totaltotal 22.7% 25 / 110 CC 19 SCAR 50.9
CC
19
Cov
19%
send
272.0
is_available
12.0
DESTROY
6.0
CRAP 163.2
↑ Summary Send.pm »
1 package Email::Send::SMTP;
2 # $Id: SMTP.pm,v 1.9 2005/05/11 03:01:25 cwest Exp $
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use vars qw[$SMTP];
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Net::SMTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Email::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Return::Value;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use UNIVERSAL::require;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub is_available {
12 0 ▶ my ($class, %args) = @_;
Subroutine is_available: not called CC=3 SCAR=24.8
Pod undocumented
13 0 my $success = 1;
14 0 $success = Net::SMTP->require;
15 0 ▶ $success = Net::SMTP::SSL->require if $args{ssl};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"ssl"} 0 0 0
16 0 ▶ return $success
Branch: 1 branch
BranchTrueFalseTotal
$success ? : 0 0 0
17 ? success
18 : failure;
19 }
20  
21 sub send {
22 0 ▶ my ($class, $message, @args) = @_;
Subroutine send: not called CC=16 SCAR=56.1
Pod undocumented
23 0 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 0 0 0
24 0 my %args;
25 0 ▶ if ( @args % 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args % 2) { } 0 0 0
26 0 my $host = shift @args;
27 0 %args = @args;
28 0 $args{Host} = $host;
29 } else {
30 0 %args = @args;
31 }
32  
33 0 ▶ my $host = delete($args{Host}) || 'localhost';
Condition0%0/2
delete $args{'Host'} || 'localhost'
l!l
00
MC/DC0%0/1
delete $args{'Host'} || 'localhost'
delete $args{'Host'}
Truth table0%0/2
A
A= delete $args{'Host'}
Aresult
11
00
34 0 ▶ if ( $args{ssl} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'ssl'}) { } 0 0 0
35 0 require Net::SMTP::SSL;
36 0 ▶ $SMTP->quit if $SMTP;
Branch: 1 branch
BranchTrueFalseTotal
if $Email::Send::SMTP::SMTP 0 0 0
37 0 $SMTP = Net::SMTP::SSL->new($host, %args);
38 0 ▶ return failure "Couldn't connect to $host" unless $SMTP;
Branch: 1 branch
BranchTrueFalseTotal
unless $Email::Send::SMTP::SMTP 0 0 0
39 } else {
40 0 ▶ $SMTP->quit if $SMTP;
Branch: 1 branch
BranchTrueFalseTotal
if $Email::Send::SMTP::SMTP 0 0 0
41 0 $SMTP = Net::SMTP->new($host, %args);
42 0 ▶ return failure "Couldn't connect to $host" unless $SMTP;
Branch: 1 branch
BranchTrueFalseTotal
unless $Email::Send::SMTP::SMTP 0 0 0
43 }
44
45 my ($user, $pass)
46 0 = @args{qw[username password]};
47 0 ▶ if ( $user ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user) 0 0 0
48 0 ▶ $SMTP->auth($user, $pass)
Branch: 1 branch
BranchTrueFalseTotal
$Email::Send::SMTP::SMTP->auth($user, $pass) or return failure("Couldn't authenticate '${user}:...'") 0 0 0
49 or return failure "Couldn't authenticate '$user:...'";
50 }
51 }
52
53 0 my @bad;
54 my @to;
55 0 eval {
56 0 my $from =
57 (Email::Address->parse($message->header('From')))[0]->address;
58 0 ▶ $SMTP->mail($from) or return failure "FROM: <$from> denied";
Branch: 1 branch
BranchTrueFalseTotal
$Email::Send::SMTP::SMTP->mail($from) or return failure("FROM: <$from> denied") 0 0 0
59  
60 @to = map {
61 0 map { $_->address }
62 Email::Address->parse($message->header($_))
63 } qw[To Cc Bcc];
64 0 my @ok = $SMTP->to(@to, { SkipBad => 1 });
65  
66 0 ▶ if ( @to != @ok ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@to != @ok) 0 0 0
67 0 my %to; @to{@to} = (1) x @to;
68 0 delete @to{@ok};
69 0 @bad = keys %to;
70 }
71 };
72 0 ▶ return failure $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
73  
74 0 ▶ return failure "No valid recipients" if @bad == @to;
Branch: 1 branch
BranchTrueFalseTotal
if @bad == @to 0 0 0
75  
76 0 ▶ return failure "Can't send data"
Branch: 1 branch
BranchTrueFalseTotal
unless $Email::Send::SMTP::SMTP->data($message->as_string) 0 0 0
77 unless $SMTP->data( $message->as_string );
78  
79 0 return success "Message sent", prop => {
80 bad => [ @bad ],
81 };
82 }
83  
84 sub DESTROY {
85 0 ▶ $SMTP->quit if $SMTP;
Subroutine DESTROY: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $Email::Send::SMTP::SMTP 0 0 0
86 }
87  
88 1 1;
89  
90 __END__
↑ Summary Send.pm »