File Coverage

blib/lib/Test/Smoke/Mailer/SendEmail.pm
Criterion Covered Total %
statement 9 33 27.2
branch 0 24 0.0
condition 0 4 0.0
subroutine 3 4 75.0
pod 1 1 100.0
total 13 66 19.7


line stmt bran cond sub pod time code
1             package Test::Smoke::Mailer::SendEmail;
2 3     3   20 use warnings;
  3         7  
  3         104  
3 3     3   15 use strict;
  3         6  
  3         104  
4              
5             our $VERSION = '0.016';
6              
7 3     3   15 use base 'Test::Smoke::Mailer::Base';
  3         5  
  3         1481  
8              
9             =head1 Test::Smoke::Mailer::SendEmail
10              
11             This handles sending the message with the B program.
12              
13             =head1 DESCRIPTION
14              
15             =head2 Test::Smoke::Mailer::SendEmail->new( %args )
16              
17             Keys for C<%args>:
18              
19             * ddir
20             * mserver
21             * msport
22             * msuser
23             * mspass
24             * sendemailbin
25             * to
26             * from
27             * cc
28             * v
29              
30             =cut
31              
32             =head2 $mailer->mail( )
33              
34             C sets up the commandline and body and passes it to the
35             B program.
36              
37             =cut
38              
39             sub mail {
40 0     0 1   my $self = shift;
41              
42 0           my $mailer = $self->{sendemailbin};
43              
44 0           my $subject = $self->fetch_report();
45 0           my $cc = $self->_get_cc( $subject );
46              
47 0           my $cmdline = qq|$mailer -u "$subject"|;
48 0 0 0       $self->{swcc} ||= '-cc', $cmdline .= qq| $self->{swcc} "$cc"| if $cc;
49             $self->{swbcc} ||= '-bcc', $cmdline .= qq| $self->{swbcc} "$self->{bcc}"|
50 0 0 0       if $self->{bcc};
51 0           $cmdline .= qq| -t "$self->{to}"|;
52 0 0         $cmdline .= qq| -f "$self->{from}"| if $self->{from};
53              
54 0 0         if ($self->{mserver}) {
55 0           my $mserver = $self->{mserver};
56 0 0         if ($self->{msport}) {
57 0           $mserver .= ":$self->{msport}";
58             }
59 0           $cmdline .= qq| -s "$mserver"|;
60             }
61              
62 0 0         $cmdline .= qq| -xu "$self->{msuser}"| if $self->{msuser};
63 0 0         $cmdline .= qq| -xp "$self->{mspass}"| if defined $self->{mspass};
64 0           $cmdline .= qq| -o message-file="$self->{file}"|;
65              
66 0 0         $self->{v} > 1 and print "[$cmdline]\n";
67 0 0         $self->{v} and print "Sending report to $self->{to}\n";
68 0           system $cmdline;
69 0 0         if ($?) {
70 0           $self->{error} = "Error executing '$mailer': " . $?>>8;
71             }
72 0 0         $self->{v} and print $self->{error} ? "not OK\n" : "OK\n";
    0          
73              
74 0           return ! $self->{error};
75             }
76              
77             1;
78              
79             =head1 COPYRIGHT
80              
81             (c) 2002-2013, All rights reserved.
82              
83             * Abe Timmerman
84              
85             This library is free software; you can redistribute it and/or modify
86             it under the same terms as Perl itself.
87              
88             See:
89              
90             * ,
91             *
92              
93             This program is distributed in the hope that it will be useful,
94             but WITHOUT ANY WARRANTY; without even the implied warranty of
95             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
96              
97             =cut