Commit 4e2bfc82 authored by gerv%gerv.net's avatar gerv%gerv.net

Bug 59351 - move all calls to sendmail to a central place. Patch by mkanat;…

Bug 59351 - move all calls to sendmail to a central place. Patch by mkanat; r=gerv,vladd; a=justdave.
parent b9cfd23f
...@@ -864,20 +864,29 @@ sub NewProcessOnePerson ($$$$$$$$$$$$$) { ...@@ -864,20 +864,29 @@ sub NewProcessOnePerson ($$$$$$$$$$$$$) {
my $msg = PerformSubsts($template, \%substs); my $msg = PerformSubsts($template, \%substs);
my $sendmailparam = "-ODeliveryMode=deferred"; MessageToMTA($msg);
if (Param("sendmailnow")) {
$sendmailparam = ""; 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) { if ($enableSendMail == 1) {
open(SENDMAIL, "|/usr/lib/sendmail $sendmailparam -t -i") || open(SENDMAIL, "|/usr/lib/sendmail $sendmailparam -t -i") ||
die "Can't open sendmail"; die "Can't open sendmail";
print SENDMAIL trim($msg) . "\n"; print SENDMAIL trim($msg) . "\n";
close SENDMAIL; close SENDMAIL;
} }
push(@sentlist, $person);
return 1;
} }
1; 1;
...@@ -36,6 +36,7 @@ use Bugzilla::Config; ...@@ -36,6 +36,7 @@ use Bugzilla::Config;
use Bugzilla::Util; use Bugzilla::Util;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::Attachment; use Bugzilla::Attachment;
use Bugzilla::BugMail;
use constant TABLES_ALREADY_LOCKED => 1; use constant TABLES_ALREADY_LOCKED => 1;
...@@ -637,12 +638,8 @@ sub notify { ...@@ -637,12 +638,8 @@ sub notify {
Bugzilla->cgi->header(); Bugzilla->cgi->header();
ThrowTemplateError($::template->error()); ThrowTemplateError($::template->error());
} }
my $delivery_mode = Param("sendmailnow") ? "" : "-ODeliveryMode=deferred"; Bugzilla::BugMail::MessageToMTA($message);
open(SENDMAIL, "|/usr/lib/sendmail $delivery_mode -t -i")
|| die "Can't open sendmail";
print SENDMAIL $message;
close(SENDMAIL);
} }
################################################################################ ################################################################################
......
...@@ -31,6 +31,7 @@ package Bugzilla::Token; ...@@ -31,6 +31,7 @@ package Bugzilla::Token;
use Bugzilla::Config; use Bugzilla::Config;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::BugMail;
use Date::Format; use Date::Format;
...@@ -91,9 +92,7 @@ sub IssueEmailChangeToken { ...@@ -91,9 +92,7 @@ sub IssueEmailChangeToken {
$template->process("account/email/change-old.txt.tmpl", $vars, \$message) $template->process("account/email/change-old.txt.tmpl", $vars, \$message)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
open SENDMAIL, "|/usr/lib/sendmail -t -i"; Bugzilla::BugMail::MessageToMTA($message);
print SENDMAIL $message;
close SENDMAIL;
$vars->{'token'} = $newtoken; $vars->{'token'} = $newtoken;
$vars->{'emailaddress'} = $new_email . Param('emailsuffix'); $vars->{'emailaddress'} = $new_email . Param('emailsuffix');
...@@ -102,10 +101,7 @@ sub IssueEmailChangeToken { ...@@ -102,10 +101,7 @@ sub IssueEmailChangeToken {
$template->process("account/email/change-new.txt.tmpl", $vars, \$message) $template->process("account/email/change-new.txt.tmpl", $vars, \$message)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
open SENDMAIL, "|/usr/lib/sendmail -t -i"; Bugzilla::BugMail::MessageToMTA($message);
print SENDMAIL $message;
close SENDMAIL;
} }
sub IssuePasswordToken { sub IssuePasswordToken {
...@@ -157,10 +153,7 @@ sub IssuePasswordToken { ...@@ -157,10 +153,7 @@ sub IssuePasswordToken {
$vars, \$message) $vars, \$message)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
open SENDMAIL, "|/usr/lib/sendmail -t -i"; Bugzilla::BugMail::MessageToMTA($message);
print SENDMAIL $message;
close SENDMAIL;
} }
...@@ -236,9 +229,7 @@ sub Cancel { ...@@ -236,9 +229,7 @@ sub Cancel {
$template->process("account/cancel-token.txt.tmpl", $vars, \$message) $template->process("account/cancel-token.txt.tmpl", $vars, \$message)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
open SENDMAIL, "|/usr/lib/sendmail -t -i"; Bugzilla::BugMail::MessageToMTA($message);
print SENDMAIL $message;
close SENDMAIL;
# Delete the token from the database. # Delete the token from the database.
&::SendSQL("LOCK TABLES tokens WRITE"); &::SendSQL("LOCK TABLES tokens WRITE");
......
...@@ -44,6 +44,7 @@ use Bugzilla::Util; ...@@ -44,6 +44,7 @@ use Bugzilla::Util;
use Bugzilla::Config; use Bugzilla::Config;
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::BugMail;
# Shut up misguided -w warnings about "used only once". For some reason, # Shut up misguided -w warnings about "used only once". For some reason,
# "use vars" chokes on me when I try it here. # "use vars" chokes on me when I try it here.
...@@ -225,9 +226,7 @@ sub MailPassword { ...@@ -225,9 +226,7 @@ sub MailPassword {
"login" => $login, "login" => $login,
"password" => $password}); "password" => $password});
open SENDMAIL, "|/usr/lib/sendmail -t -i"; Bugzilla::BugMail::MessageToMTA($msg);
print SENDMAIL $msg;
close SENDMAIL;
} }
sub PutHeader { sub PutHeader {
......
...@@ -33,6 +33,7 @@ use Bugzilla::Constants; ...@@ -33,6 +33,7 @@ use Bugzilla::Constants;
use Bugzilla::Util; use Bugzilla::Util;
# Bring ChmodDataFile in until this is all moved to the module # Bring ChmodDataFile in until this is all moved to the module
use Bugzilla::Config qw(:DEFAULT ChmodDataFile $localconfig $datadir); use Bugzilla::Config qw(:DEFAULT ChmodDataFile $localconfig $datadir);
use Bugzilla::BugMail;
# Shut up misguided -w warnings about "used only once". For some reason, # Shut up misguided -w warnings about "used only once". For some reason,
# "use vars" chokes on me when I try it here. # "use vars" chokes on me when I try it here.
...@@ -1410,32 +1411,26 @@ sub RemoveVotes { ...@@ -1410,32 +1411,26 @@ sub RemoveVotes {
# Now lets send the e-mail to alert the user to the fact that their votes have # Now lets send the e-mail to alert the user to the fact that their votes have
# been reduced or removed. # been reduced or removed.
my $sendmailparm = '-ODeliveryMode=deferred'; my %substs;
if (Param('sendmailnow')) {
$sendmailparm = '';
}
if (open(SENDMAIL, "|/usr/lib/sendmail $sendmailparm -t -i")) {
my %substs;
$substs{"to"} = $name . Param('emailsuffix'); $substs{"to"} = $name . Param('emailsuffix');
$substs{"bugid"} = $id; $substs{"bugid"} = $id;
$substs{"reason"} = $reason; $substs{"reason"} = $reason;
$substs{"votesremoved"} = $removedvotes; $substs{"votesremoved"} = $removedvotes;
$substs{"votesold"} = $oldvotes; $substs{"votesold"} = $oldvotes;
$substs{"votesnew"} = $newvotes; $substs{"votesnew"} = $newvotes;
$substs{"votesremovedtext"} = $removedvotestext; $substs{"votesremovedtext"} = $removedvotestext;
$substs{"votesoldtext"} = $oldvotestext; $substs{"votesoldtext"} = $oldvotestext;
$substs{"votesnewtext"} = $newvotestext; $substs{"votesnewtext"} = $newvotestext;
$substs{"count"} = $removedvotes . "\n " . $newvotestext; $substs{"count"} = $removedvotes . "\n " . $newvotestext;
my $msg = PerformSubsts(Param("voteremovedmail"), my $msg = PerformSubsts(Param("voteremovedmail"),
\%substs); \%substs);
print SENDMAIL $msg;
close SENDMAIL; Bugzilla::BugMail::MessageToMTA($msg);
}
} }
SendSQL("SELECT SUM(vote_count) FROM votes WHERE bug_id = $id"); SendSQL("SELECT SUM(vote_count) FROM votes WHERE bug_id = $id");
my $v = FetchOneColumn(); my $v = FetchOneColumn();
......
...@@ -61,6 +61,7 @@ use lib ($::path); ...@@ -61,6 +61,7 @@ use lib ($::path);
use Bugzilla; use Bugzilla;
use Bugzilla::Config qw(:DEFAULT $datadir); use Bugzilla::Config qw(:DEFAULT $datadir);
use Bugzilla::BugMail;
use XML::Parser; use XML::Parser;
use Data::Dumper; use Data::Dumper;
...@@ -113,11 +114,8 @@ sub MailMessage { ...@@ -113,11 +114,8 @@ sub MailMessage {
$header.= "From: Bugzilla <$from>\n"; $header.= "From: Bugzilla <$from>\n";
$header.= "Subject: $subject\n\n"; $header.= "Subject: $subject\n\n";
open(SENDMAIL, my $sendmessage = $header . $message . "\n";
"|/usr/lib/sendmail -ODeliveryMode=background -t -i") || Bugzilla::BugMail::MessageToMTA($sendmessage);
die "Can't open sendmail";
print SENDMAIL $header . $message . "\n";
close SENDMAIL;
Log($subject . " sent to: $to"); Log($subject . " sent to: $to");
} }
......
...@@ -168,11 +168,7 @@ $template->process("bug/show.xml.tmpl", { bugs => \@bugs, ...@@ -168,11 +168,7 @@ $template->process("bug/show.xml.tmpl", { bugs => \@bugs,
$msg .= "\n"; $msg .= "\n";
open(SENDMAIL, Bugzilla::BugMail::MessageToMTA($msg);
"|/usr/lib/sendmail -ODeliveryMode=background -t -i") ||
die "Can't open sendmail";
print SENDMAIL $msg;
close SENDMAIL;
my $logstr = "XML: bugs $buglist sent to $to"; my $logstr = "XML: bugs $buglist sent to $to";
Log($logstr); Log($logstr);
...@@ -33,6 +33,7 @@ use Bugzilla::Config qw(:DEFAULT $datadir); ...@@ -33,6 +33,7 @@ use Bugzilla::Config qw(:DEFAULT $datadir);
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Search; use Bugzilla::Search;
use Bugzilla::User; use Bugzilla::User;
use Bugzilla::BugMail;
# create some handles that we'll need # create some handles that we'll need
my $template = Bugzilla->template; my $template = Bugzilla->template;
...@@ -378,12 +379,7 @@ sub mail { ...@@ -378,12 +379,7 @@ sub mail {
$template->process("whine/multipart-mime.txt.tmpl", $args, \$msg) $template->process("whine/multipart-mime.txt.tmpl", $args, \$msg)
or die($template->error()); or die($template->error());
my $sendmailparam = Bugzilla::BugMail::MessageToMTA($msg);
Param('sendmailnow') ? '' : "-ODeliveryMode=deferred";
open SENDMAIL, "|/usr/lib/sendmail $sendmailparam -t -i"
or die "Can't open sendmail";
print SENDMAIL $msg;
close SENDMAIL;
delete $args->{'boundary'}; delete $args->{'boundary'};
delete $args->{'alternatives'}; delete $args->{'alternatives'};
......
...@@ -31,6 +31,8 @@ use strict; ...@@ -31,6 +31,8 @@ use strict;
require "globals.pl"; require "globals.pl";
use Bugzilla::BugMail;
SendSQL("select bug_id,short_desc,login_name from bugs,profiles where " . SendSQL("select bug_id,short_desc,login_name from bugs,profiles where " .
"(bug_status = 'NEW' or bug_status = 'REOPENED') and " . "(bug_status = 'NEW' or bug_status = 'REOPENED') and " .
"to_days(now()) - to_days(delta_ts) > " . Param('whinedays') . "to_days(now()) - to_days(delta_ts) > " . Param('whinedays') .
...@@ -68,10 +70,7 @@ foreach my $email (sort (keys %bugs)) { ...@@ -68,10 +70,7 @@ foreach my $email (sort (keys %bugs)) {
$msg .= " -> ${urlbase}show_bug.cgi?id=$i\n"; $msg .= " -> ${urlbase}show_bug.cgi?id=$i\n";
} }
my $sendmailparam = Param('sendmailnow') ? '' : "-ODeliveryMode=deferred"; Bugzilla::BugMail::MessageToMTA($msg);
open SENDMAIL, "|/usr/lib/sendmail $sendmailparam -t -i"
or die "Can't open sendmail";
print SENDMAIL $msg;
close SENDMAIL;
print "$email " . join(" ", @{$bugs{$email}}) . "\n"; print "$email " . join(" ", @{$bugs{$email}}) . "\n";
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment