| 1 | package Dancer::Plugin::Email; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | our $VERSION = '1.0400'; # 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 | 0 | ▶ | register email => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=28 SCAR=67.0
| |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | my $params = shift || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 15 | 0 | my $multipart = delete $params->{multipart}; | |||||||||||||||||||||||||||
| 16 | 0 | ▶ | my $extra_headers = delete($params->{headers}) || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $params->{'headers'} || {}
MC/DC0%0/1
delete $params->{'headers'} || {}
delete $params->{'headers'}
Truth table0%0/2
A
A= delete $params->{'headers'}
| |||||||||||||||||||||||||||||
| 17 | 0 | my $conf = plugin_setting; | |||||||||||||||||||||||||||
| 18 | 0 | ▶ | my $conf_headers = $conf->{headers} || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$conf->{'headers'} || {}
MC/DC0%0/1
$conf->{'headers'} || {}
$conf->{'headers'}
Truth table0%0/2
A
A= $conf->{'headers'}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | $headers{Type} = $type eq 'html' ? 'text/html' : 'text/plain'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | $headers{Type} ||= 'text/plain'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$headers{"Type"} ||= "text/plain"
MC/DC0%0/1
$headers{"Type"} ||= "text/plain"
$headers{"Type"}
Truth table0%0/2
A
A= $headers{"Type"}
| |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | $headers{Format} ||= 'flowed' if $headers{Type} eq 'text/plain'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$headers{"Format"} ||= "flowed"
MC/DC0%0/1
$headers{"Format"} ||= "flowed"
$headers{"Format"}
Truth table0%0/2
A
A= $headers{"Format"}
| |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | $headers{Date} ||= email_date(); | ||||||||||||||||||||||||||
|
Condition0%0/3
$headers{"Date"} ||= email_date()
MC/DC0%0/2
$headers{"Date"} ||= email_date()
$headers{"Date"}
email_date()
Truth table0%0/3
A ||= B
A= $headers{"Date"}B= email_date()
| |||||||||||||||||||||||||||||
| 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'}
MC/DC0%0/2
$params->{'body'} || $params->{'message'}
$params->{'body'}
$params->{'message'}
Truth table0%0/3
A || B
A= $params->{'body'}B= $params->{'message'}
| |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if ($attach) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ($multipart) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 46 | 0 | for my $attachment (@attachments) { | |||||||||||||||||||||||||||
| 47 | 0 | my %mime; | |||||||||||||||||||||||||||
| 48 | 0 | ▶ | if (ref($attachment) eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | %mime = %$attachment; | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | unless ($mime{Path} || $mime{Data}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mime{"Path"} or $mime{"Data"}
MC/DC0%0/2
$mime{"Path"} or $mime{"Data"}
$mime{"Path"}
$mime{"Data"}
Truth table0%0/3
A or B
A= $mime{"Path"}B= $mime{"Data"}
| |||||||||||||||||||||||||||||
| 51 | 0 | warning "No Path or Data provided for this attachment!"; | |||||||||||||||||||||||||||
| 52 | 0 | next; | |||||||||||||||||||||||||||
| 53 | }; | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ($mime{Path}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | $mime{Encoding} ||= 'base64'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$mime{"Encoding"} ||= "base64"
MC/DC0%0/1
$mime{"Encoding"} ||= "base64"
$mime{"Encoding"}
Truth table0%0/2
A
A= $mime{"Encoding"}
| |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | $mime{Type} ||= File::Type->mime_type($mime{Path}); | ||||||||||||||||||||||||||
|
Condition0%0/3
$mime{"Type"} ||= "File::Type"->mime_type($mime{"Path"})
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"})
| |||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } else { | ||||||||||||||||||||||||||||
| 59 | 0 | %mime = ( | |||||||||||||||||||||||||||
| 60 | Path => $attachment, | ||||||||||||||||||||||||||||
| 61 | Type => File::Type->mime_type($attachment), | ||||||||||||||||||||||||||||
| 62 | Encoding => 'base64', | ||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 0 | $email->attach(%mime); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | my $transport; | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | my $conf_transport = $conf->{transport} || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$conf->{'transport'} || {}
MC/DC0%0/1
$conf->{'transport'} || {}
$conf->{'transport'}
Truth table0%0/2
A
A= $conf->{'transport'}
| |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if (my ($transport_name) = keys %$conf_transport) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | my $transport_params = $conf_transport->{$transport_name} || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$conf_transport->{$transport_name} || {}
MC/DC0%0/1
$conf_transport->{$transport_name} || {}
$conf_transport->{$transport_name}
Truth table0%0/2
A
A= $conf_transport->{$transport_name}
| |||||||||||||||||||||||||||||
| 73 | 0 | my $transport_class = "Email::Sender::Transport::$transport_name"; | |||||||||||||||||||||||||||
| 74 | 0 | my $transport_redirect = $transport_params->{redirect_address}; | |||||||||||||||||||||||||||
| 75 | 0 | load $transport_class; | |||||||||||||||||||||||||||
| 76 | 0 | $transport = $transport_class->new($transport_params); | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ($transport_redirect) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | $transport_class = 'Email::Sender::Transport::Redirect'; | |||||||||||||||||||||||||||
| 80 | 0 | load $transport_class; | |||||||||||||||||||||||||||
| 81 | 0 | debug "Redirecting email to $transport_redirect."; | |||||||||||||||||||||||||||
| 82 | 0 | $transport = $transport_class->new( | |||||||||||||||||||||||||||
| 83 | transport => $transport, | ||||||||||||||||||||||||||||
| 84 | redirect_address => $transport_redirect | ||||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | 0 | my %sendmail_arg = ( transport => $transport ); | |||||||||||||||||||||||||||
| 89 | 0 | ▶ | $sendmail_arg{from} = $sender if defined $sender; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ( $headers{bcc} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | sendmail $email, { %sendmail_arg, to => $headers{bcc} }; | |||||||||||||||||||||||||||
| 92 | 0 | $email->head->delete('bcc'); | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | 0 | return sendmail $email, \%sendmail_arg; | |||||||||||||||||||||||||||
| 95 | 1 | }; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 1 | register_plugin; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # ABSTRACT: Simple email sending for Dancer applications | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 1 | 1; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | __END__ | ||||||||||||||||||||||||||||