| 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
| |||||||||||||
| 16 | 0 | ▶ | return $success | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 24 | 0 | my %args; | |||||||||||
| 25 | 0 | ▶ | if ( @args % 2 ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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'
MC/DC0%0/1
delete $args{'Host'} || 'localhost'
delete $args{'Host'}
Truth table0%0/2
A
A= delete $args{'Host'}
| |||||||||||||
| 34 | 0 | ▶ | if ( $args{ssl} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | 0 | require Net::SMTP::SSL; | |||||||||||
| 36 | 0 | ▶ | $SMTP->quit if $SMTP; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 37 | 0 | $SMTP = Net::SMTP::SSL->new($host, %args); | |||||||||||
| 38 | 0 | ▶ | return failure "Couldn't connect to $host" unless $SMTP; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 39 | } else { | ||||||||||||
| 40 | 0 | ▶ | $SMTP->quit if $SMTP; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | 0 | $SMTP = Net::SMTP->new($host, %args); | |||||||||||
| 42 | 0 | ▶ | return failure "Couldn't connect to $host" unless $SMTP; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | } | ||||||||||||
| 44 | |||||||||||||
| 45 | my ($user, $pass) | ||||||||||||
| 46 | 0 | = @args{qw[username password]}; | |||||||||||
| 47 | 0 | ▶ | if ( $user ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 48 | 0 | ▶ | $SMTP->auth($user, $pass) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 73 | |||||||||||||
| 74 | 0 | ▶ | return failure "No valid recipients" if @bad == @to; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 75 | |||||||||||||
| 76 | 0 | ▶ | return failure "Can't send data" | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | 1 | 1; | |||||||||||
| 89 | |||||||||||||
| 90 | __END__ | ||||||||||||