Skip to content

Commit

Permalink
Bug 1070640: Update (and rename) Bugzilla::Send::Sendmail to work wit…
Browse files Browse the repository at this point in the history
…h Email::Sender::Transport::Sendmail

r=dylan a=justdave

(cherry picked from commit 0ff4174)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
  • Loading branch information
LpSolit authored and mrenvoize committed Jan 15, 2024
1 parent 5039e5a commit 477c014
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
6 changes: 3 additions & 3 deletions Bugzilla/Mailer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use Try::Tiny;

use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTP;
use Email::Sender::Transport::Sendmail;
use Bugzilla::Sender::Transport::Sendmail;
use Sys::Hostname;
use Bugzilla::Version qw(vers_cmp);

Expand Down Expand Up @@ -119,10 +119,10 @@ sub MessageToMTA {
my $transport;
if ($method eq "Sendmail") {
if (ON_WINDOWS) {
$transport = Email::Sender::Transport::Sendmail->new({ sendmail => SENDMAIL_EXE });
$transport = Bugzilla::Sender::Transport::Sendmail->new({ sendmail => SENDMAIL_EXE });
}
else {
$transport = Email::Sender::Transport::Sendmail->new();
$transport = Bugzilla::Sender::Transport::Sendmail->new();
}
}
else {
Expand Down
52 changes: 27 additions & 25 deletions Bugzilla/Send/Sendmail.pm → Bugzilla/Sender/Transport/Sendmail.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,55 @@
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

package Bugzilla::Send::Sendmail;
package Bugzilla::Sender::Transport::Sendmail;

use 5.10.1;
use strict;
use warnings;

use base qw(Email::Send::Sendmail);

use Return::Value;
use Symbol qw(gensym);
use parent qw(Email::Sender::Transport::Sendmail);

sub send {
my ($class, $message, @args) = @_;
my $mailer = $class->_find_sendmail;
use Email::Sender::Failure;

return failure "Couldn't find 'sendmail' executable in your PATH"
. " and Email::Send::Sendmail::SENDMAIL is not set"
unless $mailer;
sub send_email {
my ($class, $message, $envelope) = @_;

return failure "Found $mailer but cannot execute it" unless -x $mailer;
my $pipe = $self->_sendmail_pipe($envelope);

local $SIG{'CHLD'} = 'DEFAULT';
my $string = $email->as_string;
$string =~ s/\x0D\x0A/\x0A/g unless $^O eq 'MSWin32';

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) {
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);
if (Bugzilla->get_param_with_override('use_mailer_queue')) {

# Return success for errors which are fatal so Bugzilla knows to
# remove them from the queue
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 {
warn "error when closing pipe to $mailer: $error_message\n";
return success;
warn "error when closing pipe to sendmail: $error_message\n";
return $self->success;
}
}
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 {

# Returns (error message, is_transient)
# from the sendmail source (sendmail/sysexit.h)
# from the sendmail source (sendmail/sysexits.h)
my $code = shift;
if ($code == 64) {
return ("Command line usage error (EX_USAGE)", 1);
Expand Down Expand Up @@ -112,3 +107,10 @@ sub _map_exitcode {

1;

=head1 B<Methods in need of POD>
=over
=item send_email
=back

0 comments on commit 477c014

Please sign in to comment.