blib/lib/Dancer/Plugin/Email.pm

filter: Statementstmt 33.7% 25 / 74 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 25 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 87.5% 7 / 8 Podpod n/a totaltotal 22.0% 32 / 145 SCAR 59.1
CC
26
Cov
20%
__ANON__
702.0
BEGIN
1.0
BEGIN
1.0
CRAP 367.9
↑ Summary
1 package Dancer::Plugin::Email;
2  
3 1 our $VERSION = '1.0300'; # VERSION
4  
5 1 ▶use Dancer qw(:syntax debug warning);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Dancer::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Email::Sender::Simple 'sendmail';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Email::Date::Format 'email_date';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use MIME::Entity;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Module::Load 'load';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 register email => sub {
14 0 ▶ my $params = shift || {};
Subroutine __ANON__: not called CC=26 SCAR=65.5
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
15 0 my $multipart = delete $params->{multipart};
16 0 ▶ my $extra_headers = delete($params->{headers}) || {};
Condition0%0/2
delete $params->{'headers'} || {}
l!l
00
MC/DC0%0/1
delete $params->{'headers'} || {}
delete $params->{'headers'}
Truth table0%0/2
A
A= delete $params->{'headers'}
Aresult
11
00
17 0 my $conf = plugin_setting;
18 0 ▶ my $conf_headers = $conf->{headers} || {};
Condition0%0/2
$conf->{'headers'} || {}
l!l
00
MC/DC0%0/1
$conf->{'headers'} || {}
$conf->{'headers'}
Truth table0%0/2
A
A= $conf->{'headers'}
Aresult
11
00
19 0 my %headers = ( %$conf_headers, %$params, %$extra_headers );
20 0 my $attach = $headers{attach};
21 0 my $sender = delete $headers{sender};
22 0 ▶ if (my $type = $headers{type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = $headers{"type"}) 0 0 0
23 0 ▶ $headers{Type} = $type eq 'html' ? 'text/html' : 'text/plain';
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'html' ? : 0 0 0
24 }
25 0 ▶ $headers{Type} ||= 'text/plain';
Condition0%0/2
$headers{"Type"} ||= "text/plain"
l!l
00
MC/DC0%0/1
$headers{"Type"} ||= "text/plain"
$headers{"Type"}
Truth table0%0/2
A
A= $headers{"Type"}
Aresult
11
00
26 0 ▶ $headers{Format} ||= 'flowed' if $headers{Type} eq 'text/plain';
Branch: 1 branch
BranchTrueFalseTotal
if $headers{"Type"} eq "text/plain" 0 0 0
Condition0%0/2
$headers{"Format"} ||= "flowed"
l!l
00
MC/DC0%0/1
$headers{"Format"} ||= "flowed"
$headers{"Format"}
Truth table0%0/2
A
A= $headers{"Format"}
Aresult
11
00
27 0 ▶ $headers{Date} ||= email_date();
Condition0%0/3
$headers{"Date"} ||= email_date()
l!l&&r!l&&!r
000
MC/DC0%0/2
$headers{"Date"} ||= email_date()
$headers{"Date"} email_date()
Truth table0%0/3
A ||= B
A= $headers{"Date"}B= email_date()
ABresult
1X1
011
000
28 0 delete $headers{$_} for qw(body message attach type);
29  
30 my $email = MIME::Entity->build(
31 Charset => 'utf-8',
32 Encoding => 'quoted-printable',
33 %headers,
34 Data => $params->{body} || $params->{message},
35 0 ▶ );
Condition0%0/3
$params->{'body'} || $params->{'message'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{'body'} || $params->{'message'}
$params->{'body'} $params->{'message'}
Truth table0%0/3
A || B
A= $params->{'body'}B= $params->{'message'}
ABresult
1X1
011
000
36 0 ▶ if ($attach) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attach) 0 0 0
37 0 ▶ if ($multipart) {
Branch: 1 branch
BranchTrueFalseTotal
if ($multipart) 0 0 0
38 # by default, when you add an attachment,
39 # C<make_multipart> will be called by MIME::Entity, but
40 # defaults to 'mixed'. Thunderbird doesn't like this for
41 # embedded images, so we have a chance to set it to
42 # 'related' or anything that the user wants
43 0 $email->make_multipart($multipart);
44 }
45 0 ▶ my @attachments = ref($attach) eq 'ARRAY' ? @$attach : $attach;
Branch: 1 branch
BranchTrueFalseTotal
ref $attach eq 'ARRAY' ? : 0 0 0
46 0 for my $attachment (@attachments) {
47 0 my %mime;
48 0 ▶ if (ref($attachment) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attachment eq 'HASH') { } 0 0 0
49 0 %mime = %$attachment;
50 0 ▶ unless ($mime{Path}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mime{"Path"}) 0 0 0
51 0 warning "No Path provided for this attachment!";
52 0 next;
53 };
54 0 ▶ $mime{Encoding} ||= 'base64';
Condition0%0/2
$mime{"Encoding"} ||= "base64"
l!l
00
MC/DC0%0/1
$mime{"Encoding"} ||= "base64"
$mime{"Encoding"}
Truth table0%0/2
A
A= $mime{"Encoding"}
Aresult
11
00
55 0 ▶ $mime{Type} ||= File::Type->mime_type($mime{Path}),
Condition0%0/3
$mime{"Type"} ||= "File::Type"->mime_type($mime{"Path"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$mime{"Type"} ||= "File::Type"->mime_type($mime{"Path"})
$mime{"Type"} "File::Type"->mime_type($mime{"Path"})
Truth table0%0/3
A ||= B
A= $mime{"Type"}B= "File::Type"->mime_type($mime{"Path"})
ABresult
1X1
011
000
56 } else {
57 0 %mime = (
58 Path => $attachment,
59 Type => File::Type->mime_type($attachment),
60 Encoding => 'base64',
61 );
62 }
63 0 $email->attach(%mime);
64 }
65 }
66  
67 0 my $transport;
68 0 ▶ my $conf_transport = $conf->{transport} || {};
Condition0%0/2
$conf->{'transport'} || {}
l!l
00
MC/DC0%0/1
$conf->{'transport'} || {}
$conf->{'transport'}
Truth table0%0/2
A
A= $conf->{'transport'}
Aresult
11
00
69 0 ▶ if (my ($transport_name) = keys %$conf_transport) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($transport_name) = keys %$conf_transport) 0 0 0
70 0 ▶ my $transport_params = $conf_transport->{$transport_name} || {};
Condition0%0/2
$conf_transport->{$transport_name} || {}
l!l
00
MC/DC0%0/1
$conf_transport->{$transport_name} || {}
$conf_transport->{$transport_name}
Truth table0%0/2
A
A= $conf_transport->{$transport_name}
Aresult
11
00
71 0 my $transport_class = "Email::Sender::Transport::$transport_name";
72 0 my $transport_redirect = $transport_params->{redirect_address};
73 0 load $transport_class;
74 0 $transport = $transport_class->new($transport_params);
75  
76 0 ▶ if ($transport_redirect) {
Branch: 1 branch
BranchTrueFalseTotal
if ($transport_redirect) 0 0 0
77 0 $transport_class = 'Email::Sender::Transport::Redirect';
78 0 load $transport_class;
79 0 debug "Redirecting email to $transport_redirect.";
80 0 $transport = $transport_class->new(
81 transport => $transport,
82 redirect_address => $transport_redirect
83 );
84 }
85 }
86 0 my %sendmail_arg = ( transport => $transport );
87 0 ▶ $sendmail_arg{from} = $sender if defined $sender;
Branch: 1 branch
BranchTrueFalseTotal
if defined $sender 0 0 0
88 0 ▶ if ( $headers{bcc} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($headers{"bcc"}) 0 0 0
89 0 sendmail $email, { %sendmail_arg, to => $headers{bcc} };
90 0 $email->head->delete('bcc');
91 }
92 0 return sendmail $email, \%sendmail_arg;
93 1 };
94  
95  
96 1 register_plugin;
97  
98 # ABSTRACT: Simple email sending for Dancer applications
99  
100  
101 1 1;
102  
103 __END__
↑ Summary