]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1070640: Update (and rename) Bugzilla::Send::Sendmail to work with Email::Sender...
authorFrédéric Buclin <LpSolit@gmail.com>
Wed, 1 Oct 2014 10:15:23 +0000 (12:15 +0200)
committerFrédéric Buclin <LpSolit@gmail.com>
Wed, 1 Oct 2014 10:15:23 +0000 (12:15 +0200)
r=dylan a=justdave

Bugzilla/Mailer.pm
Bugzilla/Sender/Transport/Sendmail.pm [moved from Bugzilla/Send/Sendmail.pm with 64% similarity]

index 5c0d85d337c8b0e9a2918f37b0c2844f31ce4729..3c88153066f839be4d89f916e7b0681afbf3dd8c 100644 (file)
@@ -26,7 +26,7 @@ use Encode::MIME::Header;
 use Email::MIME;
 use Email::Sender::Simple qw(sendmail);
 use Email::Sender::Transport::SMTP;
-use Email::Sender::Transport::Sendmail;
+use Bugzilla::Sender::Transport::Sendmail;
 
 sub MessageToMTA {
     my ($msg, $send_now) = (@_);
@@ -105,10 +105,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 {
similarity index 64%
rename from Bugzilla/Send/Sendmail.pm
rename to Bugzilla/Sender/Transport/Sendmail.pm
index 48312b2fa96e5b688aadc899e1f054d9d44f4aab..49f00777fc19761941d02b425b4bcbc28f995d25 100644 (file)
@@ -5,58 +5,49 @@
 # 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 parent qw(Email::Send::Sendmail);
+use parent qw(Email::Sender::Transport::Sendmail);
 
-use Return::Value;
-use Symbol qw(gensym);
+use Email::Sender::Failure;
 
-sub send {
-    my ($class, $message, @args) = @_;
-    my $mailer = $class->_find_sendmail;
+sub send_email {
+    my ($self, $email, $envelope) = @_;
 
-    return failure "Couldn't find 'sendmail' executable in your PATH"
-        ." and Email::Send::Sendmail::SENDMAIL is not set"
-        unless $mailer;
+    my $pipe = $self->_sendmail_pipe($envelope);
 
-    return failure "Found $mailer but cannot execute it"
-        unless -x $mailer;
-    
-    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->params->{'use_mailer_queue'}) {
             # Return success for errors which are fatal so Bugzilla knows to
-            # remove them from the queue
+            # 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);
@@ -99,6 +90,6 @@ sub _map_exitcode {
 
 =over
 
-=item send
+=item send_email
 
 =back