File Coverage

blib/lib/Email/Send/SMTP/TLS.pm
Criterion Covered Total %
statement 18 46 39.1
branch 0 4 0.0
condition 0 2 0.0
subroutine 6 10 60.0
pod 0 4 0.0
total 24 66 36.3


line stmt bran cond sub pod time code
1             package Email::Send::SMTP::TLS;
2              
3 1     1   29553 use warnings;
  1         3  
  1         34  
4 1     1   6 use strict;
  1         2  
  1         39  
5 1     1   6 use vars qw[$VERSION];
  1         7  
  1         46  
6 1     1   968 use Email::Address;
  1         47357  
  1         85  
7 1     1   1175 use Net::SMTP::TLS::ButMaintained;
  1         598268  
  1         36  
8 1     1   1097 use Return::Value;
  1         1492  
  1         408  
9              
10             $VERSION = '0.04';
11              
12             sub is_available {
13 0     0 0   return 1;
14             }
15              
16             sub get_env_sender {
17 0     0 0   my ( $class, $message ) = @_;
18              
19 0           my $from
20             = ( Email::Address->parse( $message->header('From') ) )[0]->address;
21             }
22              
23             sub get_env_recipients {
24 0     0 0   my ( $class, $message ) = @_;
25              
26 0           my %to = map { $_->address => 1 }
  0            
27 0           map { Email::Address->parse( $message->header($_) ) } qw(To Cc Bcc);
28              
29 0           return keys %to;
30             }
31              
32             sub send {
33 0     0 0   my ($class, $message, @args) = @_;
34              
35 0           my %args;
36 0 0         if ( @args % 2 ) {
37 0           my $host = shift @args;
38 0           %args = @args;
39 0           $args{Host} = $host;
40             } else {
41 0           %args = @args;
42             }
43              
44 0   0       my $host = delete($args{Host}) || 'localhost';
45 0           my $SMTP = Net::SMTP::TLS::ButMaintained->new($host, %args);
46            
47 0           eval {
48 0           my $from = $class->get_env_sender($message);
49 0           $SMTP->mail($from);
50            
51 0           my @to = $class->get_env_recipients($message);
52 0           $SMTP->to( @to );
53            
54             };
55 0 0         return failure $@ if $@;
56            
57 0           $SMTP->data();
58 0           $SMTP->datasend( $message->as_string );
59 0           $SMTP->dataend;
60 0           $SMTP->quit;
61              
62 0           return success 1;
63             }
64              
65             1;
66             __END__