]> git.donarmstrong.com Git - debbugs.git/commitdiff
* Switch to using Params::Validate in Debbugs::Mail
authorDon Armstrong <don@volo>
Sat, 23 Dec 2006 08:40:11 +0000 (00:40 -0800)
committerDon Armstrong <don@volo>
Sat, 23 Dec 2006 08:40:11 +0000 (00:40 -0800)
 * Use Debbugs::Config in Debbugs::Mail and add a $gSendmail
   configuration variable to select the sendmail binary to run.

Debbugs/Config.pm
Debbugs/Mail.pm

index 879db01ada97c1f9f22e30a610d9026253795ef2..58f7b631c0ec2058a4f3f1336ca9c7b24384d620 100644 (file)
@@ -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
 
 
index 6d311f8af87d0654ee9734d8fc26fbe19551661e..0a54f8edeec7335eac85854d487887873e2a9043 100644 (file)
@@ -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";
      }
 }