]> git.donarmstrong.com Git - debbugs.git/blobdiff - Debbugs/Mail.pm
- Implement versioning aware archiving support (closes: #419693)
[debbugs.git] / Debbugs / Mail.pm
index 6d311f8af87d0654ee9734d8fc26fbe19551661e..54e52f5dc6d852a7dc161932f449fcdc6adb9431 100644 (file)
@@ -1,4 +1,9 @@
-# $Id: Mail.pm,v 1.1 2005/08/17 21:46:16 don Exp $
+# This module is part of debbugs, and is released
+# under the terms of the GPL version 2, or any later
+# version at your option.
+# See the file README and COPYING for more information.
+#
+# Copyright 2004-7 by Don Armstrong <don@donarmstrong.com>.
 
 package Debbugs::Mail;
 
@@ -41,6 +46,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 +59,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 +109,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(params => \@_,
+                              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 +207,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 +230,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";
      }
 }