Commit 5d96fa70 authored by Frédéric Buclin's avatar Frédéric Buclin

Bug 502625: Replace Email::Send with Email::Sender

r=dylan a=glob
parent 917ede93
...@@ -185,16 +185,19 @@ sub update_params { ...@@ -185,16 +185,19 @@ sub update_params {
} }
# Old mail_delivery_method choices contained no uppercase characters # Old mail_delivery_method choices contained no uppercase characters
if (exists $param->{'mail_delivery_method'} my $mta = $param->{'mail_delivery_method'};
&& $param->{'mail_delivery_method'} !~ /[A-Z]/) { if ($mta) {
my $method = $param->{'mail_delivery_method'}; if ($mta !~ /[A-Z]/) {
my %translation = ( my %translation = (
'sendmail' => 'Sendmail', 'sendmail' => 'Sendmail',
'smtp' => 'SMTP', 'smtp' => 'SMTP',
'qmail' => 'Qmail', 'qmail' => 'Qmail',
'testfile' => 'Test', 'testfile' => 'Test',
'none' => 'None'); 'none' => 'None');
$param->{'mail_delivery_method'} = $translation{$method}; $param->{'mail_delivery_method'} = $translation{$mta};
}
# This will force the parameter to be reset to its default value.
delete $param->{'mail_delivery_method'} if $param->{'mail_delivery_method'} eq 'Qmail';
} }
# Convert the old "ssl" parameter to the new "ssl_redirect" parameter. # Convert the old "ssl" parameter to the new "ssl_redirect" parameter.
......
...@@ -12,13 +12,6 @@ use strict; ...@@ -12,13 +12,6 @@ use strict;
use warnings; use warnings;
use Bugzilla::Config::Common; use Bugzilla::Config::Common;
# Return::Value 1.666002 pollutes the error log with warnings about this
# deprecated module. We have to set NO_CLUCK = 1 before loading Email::Send
# to disable these warnings.
BEGIN {
$Return::Value::NO_CLUCK = 1;
}
use Email::Send;
our $sortkey = 1200; our $sortkey = 1200;
...@@ -28,9 +21,7 @@ sub get_param_list { ...@@ -28,9 +21,7 @@ sub get_param_list {
{ {
name => 'mail_delivery_method', name => 'mail_delivery_method',
type => 's', type => 's',
# Bugzilla is not ready yet to send mails to newsgroups, and 'IO' choices => ['Sendmail', 'SMTP', 'Test', 'None'],
# is of no use for now as we already have our own 'Test' mode.
choices => [grep {$_ ne 'NNTP' && $_ ne 'IO'} Email::Send->new()->all_mailers(), 'None'],
default => 'Sendmail', default => 'Sendmail',
checker => \&check_mail_delivery_method checker => \&check_mail_delivery_method
}, },
......
...@@ -1033,9 +1033,6 @@ Params: ...@@ -1033,9 +1033,6 @@ Params:
=item C<email> - The C<Email::MIME> object that's about to be sent. =item C<email> - The C<Email::MIME> object that's about to be sent.
=item C<mailer_args> - An arrayref that's passed as C<mailer_args> to
L<Email::Send/new>.
=back =back
=head2 object_before_create =head2 object_before_create
......
...@@ -23,13 +23,6 @@ use Bugzilla::Install::Util qw(install_string bin_loc ...@@ -23,13 +23,6 @@ use Bugzilla::Install::Util qw(install_string bin_loc
use List::Util qw(max); use List::Util qw(max);
use Term::ANSIColor; use Term::ANSIColor;
# Return::Value 1.666002 pollutes the error log with warnings about this
# deprecated module. We have to set NO_CLUCK = 1 before loading Email::Send
# in have_vers() to disable these warnings.
BEGIN {
$Return::Value::NO_CLUCK = 1;
}
use parent qw(Exporter); use parent qw(Exporter);
our @EXPORT = qw( our @EXPORT = qw(
REQUIRED_MODULES REQUIRED_MODULES
...@@ -131,12 +124,11 @@ sub REQUIRED_MODULES { ...@@ -131,12 +124,11 @@ sub REQUIRED_MODULES {
module => 'Template', module => 'Template',
version => '2.24' version => '2.24'
}, },
# 2.04 implement the "Test" method (to write to data/mailer.testfile). # 1.300011 has a debug mode for SMTP and automatically pass -i to sendmail.
{ {
package => 'Email-Send', package => 'Email-Sender',
module => 'Email::Send', module => 'Email::Sender',
version => ON_WINDOWS ? '2.16' : '2.04', version => '1.300011',
blacklist => ['^2\.196$']
}, },
{ {
package => 'Email-MIME', package => 'Email-MIME',
......
...@@ -23,15 +23,10 @@ use Date::Format qw(time2str); ...@@ -23,15 +23,10 @@ use Date::Format qw(time2str);
use Encode qw(encode); use Encode qw(encode);
use Encode::MIME::Header; use Encode::MIME::Header;
use Email::Address;
use Email::MIME; use Email::MIME;
# Return::Value 1.666002 pollutes the error log with warnings about this use Email::Sender::Simple qw(sendmail);
# deprecated module. We have to set NO_CLUCK = 1 before loading Email::Send use Email::Sender::Transport::SMTP;
# to disable these warnings. use Email::Sender::Transport::Sendmail;
BEGIN {
$Return::Value::NO_CLUCK = 1;
}
use Email::Send;
sub MessageToMTA { sub MessageToMTA {
my ($msg, $send_now) = (@_); my ($msg, $send_now) = (@_);
...@@ -55,8 +50,6 @@ sub MessageToMTA { ...@@ -55,8 +50,6 @@ sub MessageToMTA {
# Email::MIME doesn't do this for us. We use \015 (CR) and \012 (LF) # Email::MIME doesn't do this for us. We use \015 (CR) and \012 (LF)
# directly because Perl translates "\n" depending on what platform # directly because Perl translates "\n" depending on what platform
# you're running on. See http://perldoc.perl.org/perlport.html#Newlines # you're running on. See http://perldoc.perl.org/perlport.html#Newlines
# We check for multiple CRs because of this Template-Toolkit bug:
# https://rt.cpan.org/Ticket/Display.html?id=43345
$msg =~ s/(?:\015+)?\012/\015\012/msg; $msg =~ s/(?:\015+)?\012/\015\012/msg;
$email = new Email::MIME($msg); $email = new Email::MIME($msg);
} }
...@@ -108,21 +101,14 @@ sub MessageToMTA { ...@@ -108,21 +101,14 @@ sub MessageToMTA {
my $from = $email->header('From'); my $from = $email->header('From');
my ($hostname, @args); my $hostname;
my $mailer_class = $method; my $transport;
if ($method eq "Sendmail") { if ($method eq "Sendmail") {
$mailer_class = 'Bugzilla::Send::Sendmail';
if (ON_WINDOWS) { if (ON_WINDOWS) {
$Email::Send::Sendmail::SENDMAIL = SENDMAIL_EXE; $transport = Email::Sender::Transport::Sendmail->new({ sendmail => SENDMAIL_EXE });
} }
push @args, "-i"; else {
# We want to make sure that we pass *only* an email address. $transport = Email::Sender::Transport::Sendmail->new();
if ($from) {
my ($email_obj) = Email::Address->parse($from);
if ($email_obj) {
my $from_email = $email_obj->address;
push(@args, "-f$from_email") if $from_email;
}
} }
} }
else { else {
...@@ -141,16 +127,16 @@ sub MessageToMTA { ...@@ -141,16 +127,16 @@ sub MessageToMTA {
} }
if ($method eq "SMTP") { if ($method eq "SMTP") {
push @args, Host => Bugzilla->params->{"smtpserver"}, $transport = Email::Sender::Transport::SMTP->new({
username => Bugzilla->params->{"smtp_username"}, host => Bugzilla->params->{'smtpserver'},
password => Bugzilla->params->{"smtp_password"}, sasl_username => Bugzilla->params->{'smtp_username'},
Hello => $hostname, sasl_password => Bugzilla->params->{'smtp_password'},
ssl => Bugzilla->params->{'smtp_ssl'}, helo => $hostname,
Debug => Bugzilla->params->{'smtp_debug'}; ssl => Bugzilla->params->{'smtp_ssl'},
debug => Bugzilla->params->{'smtp_debug'} });
} }
Bugzilla::Hook::process('mailer_before_send', Bugzilla::Hook::process('mailer_before_send', { email => $email });
{ email => $email, mailer_args => \@args });
return if $email->header('to') eq ''; return if $email->header('to') eq '';
...@@ -185,13 +171,12 @@ sub MessageToMTA { ...@@ -185,13 +171,12 @@ sub MessageToMTA {
close TESTFILE; close TESTFILE;
} }
else { else {
# This is useful for both Sendmail and Qmail, so we put it out here. # This is useful for Sendmail, so we put it out here.
local $ENV{PATH} = SENDMAIL_PATH; local $ENV{PATH} = SENDMAIL_PATH;
my $mailer = Email::Send->new({ mailer => $mailer_class, eval { sendmail($email, { transport => $transport }) };
mailer_args => \@args }); if ($@) {
my $retval = $mailer->send($email); ThrowCodeError('mail_send_error', { msg => $@->message, mail => $email });
ThrowCodeError('mail_send_error', { msg => $retval, mail => $email }) }
if !$retval;
} }
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
mail_delivery_method => "Defines how email is sent, or if it is sent at all.<br> mail_delivery_method => "Defines how email is sent, or if it is sent at all.<br>
<ul> <ul>
<li> <li>
'Sendmail', 'SMTP' and 'Qmail' are all MTAs. 'Sendmail' and 'SMTP' are both MTAs.
You need to install a third-party sendmail replacement if You need to install a third-party sendmail replacement if
you want to use sendmail on Windows. you want to use sendmail on Windows.
</li> </li>
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
in 'data/mailer.testfile' instead of being sent. in 'data/mailer.testfile' instead of being sent.
</li> </li>
<li> <li>
'none' will completely disable email. Bugzilla continues 'None' will completely disable email. Bugzilla continues
to act as though it is sending mail, but nothing is sent or to act as though it is sending mail, but nothing is sent or
stored. stored.
</li> </li>
......
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