| 1 | # $Id: Sendmail.pm 1429 2003-10-16 16:39:28Z richardc $ | ||||||||||||||||||||
| 2 | package Siesta::Send::Sendmail; | ||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 0 | ▶ | sub description { "Sends a mail using sendmail" }; | ||||||||||||||||||
|
Subroutine
description: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | Siesta::Send::Sendmail - send a Siesta::Message using sendmail | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | A extension to siesta that allows you to send mail using the local | ||||||||||||||||||||
| 14 | sendmail executable. | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head1 USAGE | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | # This module should not really | ||||||||||||||||||||
| 19 | # be used outside the siesta system | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | my $sender = Siesta::Send::Sendmail->new(); | ||||||||||||||||||||
| 22 | my $mail = Siesta::Message->new(*\STDIN); | ||||||||||||||||||||
| 23 | $sender->send($mail); | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | =head1 SEE ALSO | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | L<Siesta>, L<Siesta::Message> , L<Siesta::Send> | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | =cut | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 0 | ▶ | sub new { bless {}, $_[0] } | ||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 0 | ▶ | sub send { | ||||||||||||||||||
|
Subroutine
send: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||
| 34 | 0 | my $self = shift; | |||||||||||||||||||
| 35 | 0 | my $message = shift; | |||||||||||||||||||
| 36 | 0 | my %args = @_; | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 0 | ▶ | my $from = $args{'from'} || $message->from; | ||||||||||||||||||
|
Condition0%0/3
$args{'from'} || $message->from
MC/DC0%0/2
$args{'from'} || $message->from
$args{'from'}
$message->from
Truth table0%0/3
A || B
A= $args{'from'}B= $message->from
| |||||||||||||||||||||
| 39 | 0 | ▶ | my $to = $args{'to'} || ( $message->to )[0]; | ||||||||||||||||||
|
Condition0%0/3
$args{'to'} || ($message->to)[0]
MC/DC0%0/2
$args{'to'} || ($message->to)[0]
$args{'to'}
($message->to)[0]
Truth table0%0/3
A || B
A= $args{'to'}B= ($message->to)[0]
| |||||||||||||||||||||
| 40 | 0 | ▶ | my @to = ref $to eq 'ARRAY' ? @$to : ( $to ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | 0 | ▶ | return 1 unless @to; # guard against no recipients | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | # according to MBM one shouldn't try and give sendmail more than | ||||||||||||||||||||
| 44 | # about 80 recipients at the same time. And frankly, he should | ||||||||||||||||||||
| 45 | # know. | ||||||||||||||||||||
| 46 | 0 | my $sendmail_limit = 80; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 0 | ▶ | while (my @local = splice @to, 0, $sendmail_limit) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | 0 | my $pid = open my $sendmail, '|-'; | |||||||||||||||||||
| 50 | 0 | ▶ | die "couldn't fork $!" unless defined $pid; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | 0 | ▶ | unless ($pid) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 0 | exec '/usr/sbin/sendmail', '-oi', '-f', $from, @local; | |||||||||||||||||||
| 53 | 0 | die "exec failed $!"; | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | 0 | print $sendmail $message->as_string; | |||||||||||||||||||
| 56 | 0 | ▶ | close $sendmail | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | or die "problem closing sendmail $! $?"; | ||||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 0 | return 1; | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 1 | 1; | |||||||||||||||||||