]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 59351 - move all calls to sendmail to a central place. Patch by mkanat; r=gerv...
authorgerv%gerv.net <>
Sat, 1 Jan 2005 21:44:15 +0000 (21:44 +0000)
committergerv%gerv.net <>
Sat, 1 Jan 2005 21:44:15 +0000 (21:44 +0000)
Bugzilla/BugMail.pm
Bugzilla/Flag.pm
Bugzilla/Token.pm
CGI.pl
globals.pl
importxml.pl
move.pl
whine.pl
whineatnews.pl

index 0e089fa121000c463ca2d1eb6a27ca4ee9d58143..638b8a41372a57c6ab1c16f16ac693c8a1ee080c 100644 (file)
@@ -864,20 +864,29 @@ sub NewProcessOnePerson ($$$$$$$$$$$$$) {
     
     my $msg = PerformSubsts($template, \%substs);
 
-    my $sendmailparam = "-ODeliveryMode=deferred";
-    if (Param("sendmailnow")) {
-       $sendmailparam = "";
+    MessageToMTA($msg);
+
+    push(@sentlist, $person);
+    return 1;
+}
+
+# XXX: Should eventually add $mail_from and $mail_to options to 
+# control the SMTP Envelope. -mkanat
+sub MessageToMTA ($) {
+   my ($msg) = (@_);
+
+    my $sendmailparam = "";
+    unless (Param("sendmailnow")) {
+       $sendmailparam = "-ODeliveryMode=deferred";
     }
 
     if ($enableSendMail == 1) {
         open(SENDMAIL, "|/usr/lib/sendmail $sendmailparam -t -i") ||
           die "Can't open sendmail";
-    
+
         print SENDMAIL trim($msg) . "\n";
         close SENDMAIL;
     }
-    push(@sentlist, $person);
-    return 1;
 }
 
 1;
index 1ee6ba71c74367ec557857f098402bc7ded43f06..8fa1e9457ef36cb9330007d649ea1089bc8d3657 100644 (file)
@@ -36,6 +36,7 @@ use Bugzilla::Config;
 use Bugzilla::Util;
 use Bugzilla::Error;
 use Bugzilla::Attachment;
+use Bugzilla::BugMail;
 
 use constant TABLES_ALREADY_LOCKED => 1;
 
@@ -637,12 +638,8 @@ sub notify {
         Bugzilla->cgi->header();
         ThrowTemplateError($::template->error());
     }
-    
-    my $delivery_mode = Param("sendmailnow") ? "" : "-ODeliveryMode=deferred";
-    open(SENDMAIL, "|/usr/lib/sendmail $delivery_mode -t -i") 
-      || die "Can't open sendmail";
-    print SENDMAIL $message;
-    close(SENDMAIL);
+
+    Bugzilla::BugMail::MessageToMTA($message);
 }
 
 ################################################################################
index 55362d18473e67fadb993d008677631710c9d1f9..90efe99bda499769b9c8625d0c3141e0ea828946 100644 (file)
@@ -31,6 +31,7 @@ package Bugzilla::Token;
 
 use Bugzilla::Config;
 use Bugzilla::Error;
+use Bugzilla::BugMail;
 
 use Date::Format;
 
@@ -91,9 +92,7 @@ sub IssueEmailChangeToken {
     $template->process("account/email/change-old.txt.tmpl", $vars, \$message)
       || ThrowTemplateError($template->error());
 
-    open SENDMAIL, "|/usr/lib/sendmail -t -i";
-    print SENDMAIL $message;
-    close SENDMAIL;
+    Bugzilla::BugMail::MessageToMTA($message);
 
     $vars->{'token'} = $newtoken;
     $vars->{'emailaddress'} = $new_email . Param('emailsuffix');
@@ -102,10 +101,7 @@ sub IssueEmailChangeToken {
     $template->process("account/email/change-new.txt.tmpl", $vars, \$message)
       || ThrowTemplateError($template->error());
 
-    open SENDMAIL, "|/usr/lib/sendmail -t -i";
-    print SENDMAIL $message;
-    close SENDMAIL;
-
+    Bugzilla::BugMail::MessageToMTA($message);
 }
 
 sub IssuePasswordToken {
@@ -157,10 +153,7 @@ sub IssuePasswordToken {
                                                                $vars, \$message)
       || ThrowTemplateError($template->error());
 
-    open SENDMAIL, "|/usr/lib/sendmail -t -i";
-    print SENDMAIL $message;
-    close SENDMAIL;
-
+    Bugzilla::BugMail::MessageToMTA($message);
 }
 
 
@@ -236,9 +229,7 @@ sub Cancel {
     $template->process("account/cancel-token.txt.tmpl", $vars, \$message)
       || ThrowTemplateError($template->error());
 
-    open SENDMAIL, "|/usr/lib/sendmail -t -i";
-    print SENDMAIL $message;
-    close SENDMAIL;
+    Bugzilla::BugMail::MessageToMTA($message);
 
     # Delete the token from the database.
     &::SendSQL("LOCK TABLES tokens WRITE");
diff --git a/CGI.pl b/CGI.pl
index 0d03562fefc87d2f7692176ebe365fc2faab81b7..163c83a562d29f1d91396730b87e9d602e9e6f38 100644 (file)
--- a/CGI.pl
+++ b/CGI.pl
@@ -44,6 +44,7 @@ use Bugzilla::Util;
 use Bugzilla::Config;
 use Bugzilla::Constants;
 use Bugzilla::Error;
+use Bugzilla::BugMail;
 
 # Shut up misguided -w warnings about "used only once".  For some reason,
 # "use vars" chokes on me when I try it here.
@@ -225,9 +226,7 @@ sub MailPassword {
                              "login" => $login,
                              "password" => $password});
 
-    open SENDMAIL, "|/usr/lib/sendmail -t -i";
-    print SENDMAIL $msg;
-    close SENDMAIL;
+    Bugzilla::BugMail::MessageToMTA($msg);
 }
 
 sub PutHeader {
index 02a4f8fb40a9e8d1620de167b6a54b6574fd4d57..12644d50602a90dfbda7308f8ec6ded41e83e54e 100644 (file)
@@ -33,6 +33,7 @@ use Bugzilla::Constants;
 use Bugzilla::Util;
 # Bring ChmodDataFile in until this is all moved to the module
 use Bugzilla::Config qw(:DEFAULT ChmodDataFile $localconfig $datadir);
+use Bugzilla::BugMail;
 
 # Shut up misguided -w warnings about "used only once".  For some reason,
 # "use vars" chokes on me when I try it here.
@@ -1410,32 +1411,26 @@ sub RemoveVotes {
 
             # Now lets send the e-mail to alert the user to the fact that their votes have
             # been reduced or removed.
-            my $sendmailparm = '-ODeliveryMode=deferred';
-            if (Param('sendmailnow')) {
-               $sendmailparm = '';
-            }
-            if (open(SENDMAIL, "|/usr/lib/sendmail $sendmailparm -t -i")) {
-                my %substs;
+            my %substs;
 
-                $substs{"to"} = $name . Param('emailsuffix');
-                $substs{"bugid"} = $id;
-                $substs{"reason"} = $reason;
+            $substs{"to"} = $name . Param('emailsuffix');
+            $substs{"bugid"} = $id;
+            $substs{"reason"} = $reason;
 
-                $substs{"votesremoved"} = $removedvotes;
-                $substs{"votesold"} = $oldvotes;
-                $substs{"votesnew"} = $newvotes;
+            $substs{"votesremoved"} = $removedvotes;
+            $substs{"votesold"} = $oldvotes;
+            $substs{"votesnew"} = $newvotes;
 
-                $substs{"votesremovedtext"} = $removedvotestext;
-                $substs{"votesoldtext"} = $oldvotestext;
-                $substs{"votesnewtext"} = $newvotestext;
+            $substs{"votesremovedtext"} = $removedvotestext;
+            $substs{"votesoldtext"} = $oldvotestext;
+            $substs{"votesnewtext"} = $newvotestext;
 
-                $substs{"count"} = $removedvotes . "\n    " . $newvotestext;
+            $substs{"count"} = $removedvotes . "\n    " . $newvotestext;
 
-                my $msg = PerformSubsts(Param("voteremovedmail"),
-                                        \%substs);
-                print SENDMAIL $msg;
-                close SENDMAIL;
-            }
+            my $msg = PerformSubsts(Param("voteremovedmail"),
+                                    \%substs);
+
+            Bugzilla::BugMail::MessageToMTA($msg);
         }
         SendSQL("SELECT SUM(vote_count) FROM votes WHERE bug_id = $id");
         my $v = FetchOneColumn();
index f233871765d207c8f426469b39b37a924ec9b50c..277681a35e003a09ca73a5029e0529dc560fbbd9 100755 (executable)
@@ -61,6 +61,7 @@ use lib ($::path);
 
 use Bugzilla;
 use Bugzilla::Config qw(:DEFAULT $datadir);
+use Bugzilla::BugMail;
 
 use XML::Parser;
 use Data::Dumper;
@@ -113,11 +114,8 @@ sub MailMessage {
   $header.= "From: Bugzilla <$from>\n";
   $header.= "Subject: $subject\n\n";
 
-  open(SENDMAIL,
-    "|/usr/lib/sendmail -ODeliveryMode=background -t -i") ||
-      die "Can't open sendmail";
-  print SENDMAIL $header . $message . "\n";
-  close SENDMAIL;
+  my $sendmessage = $header . $message . "\n";
+  Bugzilla::BugMail::MessageToMTA($sendmessage);
 
   Log($subject . " sent to: $to");
 }
diff --git a/move.pl b/move.pl
index 8218c4069984be840d79dc2fb5f14886360975d1..328671f8170898af8be2cbe8a933626fedbbbfd0 100755 (executable)
--- a/move.pl
+++ b/move.pl
@@ -168,11 +168,7 @@ $template->process("bug/show.xml.tmpl", { bugs => \@bugs,
 
 $msg .= "\n";
 
-open(SENDMAIL,
-  "|/usr/lib/sendmail -ODeliveryMode=background -t -i") ||
-    die "Can't open sendmail";
-print SENDMAIL $msg;
-close SENDMAIL;
+Bugzilla::BugMail::MessageToMTA($msg);
 
 my $logstr = "XML: bugs $buglist sent to $to";
 Log($logstr);
index dc3f2302c9dc65539f381650cac2367ee333d301..25a422a7101678e0ba3fdc75a5c7b642c75802a3 100755 (executable)
--- a/whine.pl
+++ b/whine.pl
@@ -33,6 +33,7 @@ use Bugzilla::Config qw(:DEFAULT $datadir);
 use Bugzilla::Constants;
 use Bugzilla::Search;
 use Bugzilla::User;
+use Bugzilla::BugMail;
 
 # create some handles that we'll need
 my $template = Bugzilla->template;
@@ -378,12 +379,7 @@ sub mail {
     $template->process("whine/multipart-mime.txt.tmpl", $args, \$msg)
         or die($template->error());
 
-    my $sendmailparam =
-        Param('sendmailnow') ? '' : "-ODeliveryMode=deferred";
-    open SENDMAIL, "|/usr/lib/sendmail $sendmailparam -t -i"
-        or die "Can't open sendmail";
-    print SENDMAIL $msg;
-    close SENDMAIL;
+    Bugzilla::BugMail::MessageToMTA($msg);
 
     delete $args->{'boundary'};
     delete $args->{'alternatives'};
index b5fd020a9faf515cd868bd149a1a96220c1a76eb..8e73e1b6d2f9578e8871806f0c2b11b3e7342498 100755 (executable)
@@ -31,6 +31,8 @@ use strict;
 
 require "globals.pl";
 
+use Bugzilla::BugMail;
+
 SendSQL("select bug_id,short_desc,login_name from bugs,profiles where " .
         "(bug_status = 'NEW' or bug_status = 'REOPENED') and " . 
         "to_days(now()) - to_days(delta_ts) > " . Param('whinedays') .
@@ -68,10 +70,7 @@ foreach my $email (sort (keys %bugs)) {
         $msg .= "    -> ${urlbase}show_bug.cgi?id=$i\n";
     }
 
-    my $sendmailparam = Param('sendmailnow') ? '' : "-ODeliveryMode=deferred";
-    open SENDMAIL, "|/usr/lib/sendmail $sendmailparam -t -i"
-        or die "Can't open sendmail";
-    print SENDMAIL $msg;
-    close SENDMAIL;
+    Bugzilla::BugMail::MessageToMTA($msg);
+
     print "$email      " . join(" ", @{$bugs{$email}}) . "\n";
 }