| 1 | package Email::Send::Sendmail; | ||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 5 | ▶ | use File::Spec (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | BEGIN { | ||||||||||
| 6 | 5 | ▶ | local $Return::Value::NO_CLUCK = 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 5 | require Return::Value; | |||||||||
| 8 | 5 | Return::Value->import; | |||||||||
| 9 | } | ||||||||||
| 10 | 5 | ▶ | use Symbol qw(gensym); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 5 | ▶ | use vars qw[$SENDMAIL $VERSION]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 5 | $VERSION = '2.201'; | |||||||||
| 15 | |||||||||||
| 16 | sub is_available { | ||||||||||
| 17 | 8 | ▶ | my $class = shift; | ||||||||
|
Subroutine
is_available: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 18 | |||||||||||
| 19 | # This is RIDICULOUS. Why do we say it's available if it isn't? | ||||||||||
| 20 | # -- rjbs, 2006-07-06 | ||||||||||
| 21 | 8 | ▶ | return success "No Sendmail found" unless $class->_find_sendmail; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 5 | return success ''; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | sub _find_sendmail { | ||||||||||
| 26 | 12 | ▶ | my $class = shift; | ||||||||
|
Subroutine
_find_sendmail: called CC=5 SCAR=16.1
| |||||||||||
| 27 | 12 | ▶ | return $SENDMAIL if defined $SENDMAIL; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | |||||||||||
| 29 | 6 | my $sendmail; | |||||||||
| 30 | 6 | ▶ | for my $dir ( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | File::Spec->path, | ||||||||||
| 32 | ($ENV{PERL_EMAIL_SEND_SENDMAIL_NO_EXTRA_PATHS} ? () : ( | ||||||||||
| 33 | File::Spec->catfile('', qw(usr sbin)), | ||||||||||
| 34 | File::Spec->catfile('', qw(usr lib)), | ||||||||||
| 35 | )) | ||||||||||
| 36 | ) { | ||||||||||
| 37 | 13 | ▶ | if ( -x "$dir/sendmail" ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 2 | $sendmail = "$dir/sendmail"; | |||||||||
| 39 | 2 | last; | |||||||||
| 40 | } | ||||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 6 | return $sendmail; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | sub send { | ||||||||||
| 47 | 3 | ▶ | my ($class, $message, @args) = @_; | ||||||||
|
Subroutine
send: called CC=6 SCAR=18.4
Pod
undocumented
| |||||||||||
| 48 | 3 | my $mailer = $class->_find_sendmail; | |||||||||
| 49 | |||||||||||
| 50 | 3 | ▶ | return failure "Couldn't find 'sendmail' executable in your PATH" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | ." and \$".__PACKAGE__."::SENDMAIL is not set" | ||||||||||
| 52 | unless $mailer; | ||||||||||
| 53 | |||||||||||
| 54 | 3 | ▶ | return failure "Found $mailer but cannot execute it" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | unless -x $mailer; | ||||||||||
| 56 | |||||||||||
| 57 | 2 | local $SIG{'CHLD'} = 'DEFAULT'; | |||||||||
| 58 | |||||||||||
| 59 | 2 | my $pipe = gensym; | |||||||||
| 60 | |||||||||||
| 61 | 2 | ▶ | open $pipe, "| $mailer -t -oi @args" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | or return failure "Error executing $mailer: $!"; | ||||||||||
| 63 | 2 | ▶ | print $pipe $message->as_string | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | or return failure "Error printing via pipe to $mailer: $!"; | ||||||||||
| 65 | 2 | ▶ | close $pipe | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | or return failure "error when closing pipe to $mailer: $!"; | ||||||||||
| 67 | 2 | return success; | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 5 | 1; | |||||||||
| 71 | |||||||||||
| 72 | __END__ | ||||||||||