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