From c1d8d599e09cae3c7cfb42ee836a973ea70ce436 Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Sat, 23 Dec 2006 00:40:11 -0800 Subject: [PATCH] * Switch to using Params::Validate in Debbugs::Mail * Use Debbugs::Config in Debbugs::Mail and add a $gSendmail configuration variable to select the sendmail binary to run. --- Debbugs/Config.pm | 9 +++++++++ Debbugs/Mail.pm | 41 ++++++++++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/Debbugs/Config.pm b/Debbugs/Config.pm index 879db01..58f7b63 100644 --- a/Debbugs/Config.pm +++ b/Debbugs/Config.pm @@ -49,6 +49,7 @@ BEGIN { qw($gIncomingDir $gWebDir $gDocDir $gMaintainerFile), qw($gMaintainerFileOverride $gPseudoDescFile $gPackageSource), qw($gVersionPackagesDir $gVersionIndex $gBinarySourceMap $gSourceBinaryMap), + qw($gSendmail), qw(%gSeverityDisplay @gTags @gSeverityList @gStrongSeverities), qw(%gSearchEstraier), ], @@ -368,6 +369,14 @@ set_default(\%config,'package_source',$config{config_dir}.'/indices/sources'); set_default(\%config,'version_packages_dir',$config{spool_dir}.'/../versions/pkg'); +=item sendmail + +Sets the sendmail binary to execute; defaults to /usr/lib/sendmail + +=cut + +set_default(\%config,'sendmail',$config{sendmail},'/usr/lib/sendmail'); + =back diff --git a/Debbugs/Mail.pm b/Debbugs/Mail.pm index 6d311f8..0a54f8e 100644 --- a/Debbugs/Mail.pm +++ b/Debbugs/Mail.pm @@ -41,6 +41,8 @@ use POSIX ":sys_wait_h"; use Time::HiRes qw(usleep); use Mail::Address (); use Debbugs::MIME qw(encode_rfc1522); +use Debbugs::Config qw(:config); +use Params::Validate qw(:types validate_with); BEGIN{ ($VERSION) = q$Revision: 1.1 $ =~ /^Revision:\s+([^\s+])/; @@ -52,6 +54,9 @@ BEGIN{ } +# We set this here so it can be overridden for testing purposes +our $SENDMAIL = $config{sendmail}; + =head2 get_addresses my @addresses = get_addresses('don@debian.org blars@debian.org @@ -99,12 +104,26 @@ using warn. =cut sub send_mail_message{ - die "send_mail_message requires an even number of arguments" if @_ % 2; - # It would be better to use Param::Validate instead... - my %param = @_; - - die "send_mail_message requires a message" if not defined $param{message}; - + my %param = validate_with(param => \@_, + spec => {sendmail_arguments => {type => ARRAYREF, + default => [qw(-odq -oem -oi)], + }, + parse_for_recipients => {type => BOOLEAN, + default => 0, + }, + encode_headers => {type => BOOLEAN, + default => 1, + }, + message => {type => SCALAR, + }, + envelope_from => {type => SCALAR, + optional => 1, + }, + recipients => {type => ARRAYREF|UNDEF, + optional => 1, + }, + }, + ); my @sendmail_arguments = qw(-odq -oem -oi); push @sendmail_arguments, '-f', $param{envelope_from} if exists $param{envelope_from}; @@ -183,12 +202,12 @@ sub _send_message{ my ($message,@sendmail_args) = @_; my ($wfh,$rfh); - my $pid = open3($wfh,$rfh,$rfh,'/usr/lib/sendmail',@sendmail_args) - or die "Unable to fork off /usr/lib/sendmail: $!"; + my $pid = open3($wfh,$rfh,$rfh,$SENDMAIL,@sendmail_args) + or die "Unable to fork off $SENDMAIL: $!"; local $SIG{PIPE} = 'IGNORE'; eval { - print {$wfh} $message or die "Unable to write to /usr/lib/sendmail: $!"; - close $wfh or die "/usr/lib/sendmail exited with $?"; + print {$wfh} $message or die "Unable to write to $SENDMAIL: $!"; + close $wfh or die "$SENDMAIL exited with $?"; }; if ($@) { local $\; @@ -206,7 +225,7 @@ sub _send_message{ usleep(50_000); } if ($loop >= 600) { - warn "Sendmail didn't exit within 30 seconds"; + warn "$SENDMAIL didn't exit within 30 seconds"; } } -- 2.39.2