File Coverage

blib/lib/Siesta/Send/Sendmail.pm
Criterion Covered Total %
statement 3 22 13.6
branch 0 10 0.0
condition 0 6 0.0
subroutine 1 4 25.0
pod 0 3 0.0
total 4 45 8.8


line stmt bran cond sub pod time code
1             # $Id: Sendmail.pm 1429 2003-10-16 16:39:28Z richardc $
2             package Siesta::Send::Sendmail;
3 1     1   3242 use strict;
  1         2  
  1         314  
4              
5 0     0 0   sub description { "Sends a mail using sendmail" };
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, L , L
28              
29             =cut
30              
31 0     0 0   sub new { bless {}, $_[0] }
32              
33             sub send {
34 0     0 0   my $self = shift;
35 0           my $message = shift;
36 0           my %args = @_;
37              
38 0   0       my $from = $args{'from'} || $message->from;
39 0   0       my $to = $args{'to'} || ( $message->to )[0];
40 0 0         my @to = ref $to eq 'ARRAY' ? @$to : ( $to );
41 0 0         return 1 unless @to; # guard against no recipients
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) {
49 0           my $pid = open my $sendmail, '|-';
50 0 0         die "couldn't fork $!" unless defined $pid;
51 0 0         unless ($pid) {
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 0         close $sendmail
57             or die "problem closing sendmail $! $?";
58             }
59              
60 0           return 1;
61             }
62              
63             1;