Commit 0ff4174b authored by Frédéric Buclin's avatar Frédéric Buclin

Bug 1070640: Update (and rename) Bugzilla::Send::Sendmail to work with…

Bug 1070640: Update (and rename) Bugzilla::Send::Sendmail to work with Email::Sender::Transport::Sendmail r=dylan a=justdave
parent f7f98a3c
...@@ -26,7 +26,7 @@ use Encode::MIME::Header; ...@@ -26,7 +26,7 @@ use Encode::MIME::Header;
use Email::MIME; use Email::MIME;
use Email::Sender::Simple qw(sendmail); use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTP; use Email::Sender::Transport::SMTP;
use Email::Sender::Transport::Sendmail; use Bugzilla::Sender::Transport::Sendmail;
sub MessageToMTA { sub MessageToMTA {
my ($msg, $send_now) = (@_); my ($msg, $send_now) = (@_);
...@@ -105,10 +105,10 @@ sub MessageToMTA { ...@@ -105,10 +105,10 @@ sub MessageToMTA {
my $transport; my $transport;
if ($method eq "Sendmail") { if ($method eq "Sendmail") {
if (ON_WINDOWS) { if (ON_WINDOWS) {
$transport = Email::Sender::Transport::Sendmail->new({ sendmail => SENDMAIL_EXE }); $transport = Bugzilla::Sender::Transport::Sendmail->new({ sendmail => SENDMAIL_EXE });
} }
else { else {
$transport = Email::Sender::Transport::Sendmail->new(); $transport = Bugzilla::Sender::Transport::Sendmail->new();
} }
} }
else { else {
......
...@@ -5,58 +5,49 @@ ...@@ -5,58 +5,49 @@
# This Source Code Form is "Incompatible With Secondary Licenses", as # This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0. # defined by the Mozilla Public License, v. 2.0.
package Bugzilla::Send::Sendmail; package Bugzilla::Sender::Transport::Sendmail;
use 5.10.1; use 5.10.1;
use strict; use strict;
use warnings; use warnings;
use parent qw(Email::Send::Sendmail); use parent qw(Email::Sender::Transport::Sendmail);
use Return::Value; use Email::Sender::Failure;
use Symbol qw(gensym);
sub send { sub send_email {
my ($class, $message, @args) = @_; my ($self, $email, $envelope) = @_;
my $mailer = $class->_find_sendmail;
return failure "Couldn't find 'sendmail' executable in your PATH" my $pipe = $self->_sendmail_pipe($envelope);
." and Email::Send::Sendmail::SENDMAIL is not set"
unless $mailer;
return failure "Found $mailer but cannot execute it" my $string = $email->as_string;
unless -x $mailer; $string =~ s/\x0D\x0A/\x0A/g unless $^O eq 'MSWin32';
local $SIG{'CHLD'} = 'DEFAULT';
my $pipe = gensym; print $pipe $string
or Email::Sender::Failure->throw("couldn't send message to sendmail: $!");
open($pipe, "| $mailer -t -oi @args")
|| return failure "Error executing $mailer: $!";
print($pipe $message->as_string)
|| return failure "Error printing via pipe to $mailer: $!";
unless (close $pipe) { unless (close $pipe) {
return failure "error when closing pipe to $mailer: $!" if $!; Email::Sender::Failure->throw("error when closing pipe to sendmail: $!") if $!;
my ($error_message, $is_transient) = _map_exitcode($? >> 8); my ($error_message, $is_transient) = _map_exitcode($? >> 8);
if (Bugzilla->params->{'use_mailer_queue'}) { if (Bugzilla->params->{'use_mailer_queue'}) {
# Return success for errors which are fatal so Bugzilla knows to # Return success for errors which are fatal so Bugzilla knows to
# remove them from the queue # remove them from the queue.
if ($is_transient) { if ($is_transient) {
return failure "error when closing pipe to $mailer: $error_message"; Email::Sender::Failure->throw("error when closing pipe to sendmail: $error_message");
} else { } else {
warn "error when closing pipe to $mailer: $error_message\n"; warn "error when closing pipe to sendmail: $error_message\n";
return success; return $self->success;
} }
} else { } else {
return failure "error when closing pipe to $mailer: $error_message"; Email::Sender::Failure->throw("error when closing pipe to sendmail: $error_message");
} }
} }
return success; return $self->success;
} }
sub _map_exitcode { sub _map_exitcode {
# Returns (error message, is_transient) # Returns (error message, is_transient)
# from the sendmail source (sendmail/sysexit.h) # from the sendmail source (sendmail/sysexits.h)
my $code = shift; my $code = shift;
if ($code == 64) { if ($code == 64) {
return ("Command line usage error (EX_USAGE)", 1); return ("Command line usage error (EX_USAGE)", 1);
...@@ -99,6 +90,6 @@ sub _map_exitcode { ...@@ -99,6 +90,6 @@ sub _map_exitcode {
=over =over
=item send =item send_email
=back =back
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