[Rt-commit] rt branch, 4.0/outgoing-mail-override-and-bounces, created. rt-4.0.4-185-ge707f34

Kevin Falcone falcone at bestpractical.com
Thu Jan 12 20:14:16 EST 2012


The branch, 4.0/outgoing-mail-override-and-bounces has been created
        at  e707f34ee7d9577a214590ee31f4b1ac3920112d (commit)

- Log -----------------------------------------------------------------
commit a380f3b8d1fabed992080b201642d03ff2a7994e
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Thu Jan 12 18:07:28 2012 -0500

    Sometimes sending mail through the mailgate fails
    
    Rather than throwing a warning trying to call $ticket->id,
    allow the call to return to the caller with the status and a ticket id
    of 0 so the test can tell that it failed (probably intentionally).

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 048b3f8..0d6da1b 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -1010,7 +1010,7 @@ sub send_via_mailgate {
 
     my ( $status, $error_message, $ticket )
         = RT::Interface::Email::Gateway( {%args, message => $message} );
-    return ( $status, $ticket->id );
+    return ( $status, $ticket ? $ticket->id : 0 );
 
 }
 

commit 6441b96db3268bb2dc72d4c33e358146403ebf0c
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Thu Jan 12 18:04:15 2012 -0500

    A failing test to show that SetOutgoingMailFrom and Bounces mix poorly

diff --git a/t/mail/bounce.t b/t/mail/bounce.t
new file mode 100644
index 0000000..703e86d
--- /dev/null
+++ b/t/mail/bounce.t
@@ -0,0 +1,42 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+
+RT->Config->Set( MailCommand  => 'sendmailpipe' );
+RT->Config->Set( SetOutgoingMailFrom => 1 );
+RT->Config->Set( OverrideOutgoingMailFrom  => { Default => 'queue at example.invalid' } );
+
+# Ensure that the fake sendmail knows where to write to
+$ENV{RT_MAILLOGFILE} = RT::Test->temp_directory . "/sendmailpipe.log";
+my $fake = File::Spec->rel2abs( File::Spec->catfile(
+        't', 'mail', 'fake-sendmail' ) );
+RT->Config->Set( SendmailPath => $fake);
+
+my $message = <<EOM;
+From: doesnotexist\@willbounce.invalid
+Subject: This is a test of new ticket creation
+
+Bounce bounce bounce
+EOM
+
+{
+    # by default, MailError wants to crit or error the email message
+    # out to Screen, which scribbles all over the test output
+    no warnings 'redefine';
+    my $orig_mail_error = RT::Interface::Email->can('MailError');
+    local *RT::Interface::Email::MailError = sub { $orig_mail_error->( @_, LogLevel => undef ) };
+    RT::Test->send_via_mailgate($message);
+}
+
+
+open(LOG, "<", $ENV{RT_MAILLOGFILE}) or die "Can't open log file: $!";
+my $fcount;
+while (my $line = <LOG>) {
+    $fcount++ if $line =~ /^-f/;
+}
+close(LOG);
+# RT_MAILLOGFILE will contain all the command line flags if you need them
+is($fcount,1,"Only one -f specified to sendmail command");
+
+done_testing;
diff --git a/t/mail/fake-sendmail b/t/mail/fake-sendmail
new file mode 100755
index 0000000..44c2377
--- /dev/null
+++ b/t/mail/fake-sendmail
@@ -0,0 +1,27 @@
+#!/usr/bin/env perl
+
+# captures command line arguments so you can validate
+# what is being generated in sendmailpipe
+
+use strict;
+use warnings;
+
+die "No \$RT_MAILLOGFILE set in environment"
+    unless $ENV{RT_MAILLOGFILE};
+open LOG, ">", $ENV{RT_MAILLOGFILE}
+    or die "Can't write to $ENV{RT_MAILLOGFILE}: $!";
+
+my $needs_newline;
+for (@ARGV) {
+    if (/^-/) {
+        print LOG "\n" if $needs_newline++;
+        print LOG $_;
+    } else {
+        print LOG " $_";
+    }
+}
+print LOG "\n";
+
+1 while $_ = <STDIN>;
+
+exit 0;

commit e707f34ee7d9577a214590ee31f4b1ac3920112d
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Thu Jan 12 19:09:49 2012 -0500

    SetOutgoingMailFrom and Bounces mix poorly
    
    If you turn on SetOutgoingMailFrom, RT will try to pass
    -f Queue.CorrespondAddress to the command line, but will then also tack
    on -f <> and that just causes the sendmail command line program included
    with postfix and sendmail to throw an error condition.  This can result
    in RT throwing away bounce mail instead of notifying Admins.
    
    Fixes test introduced in 6441b96db3268bb2dc72d4c33e358146403ebf0c

diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm
index 384abb3..23ac412 100644
--- a/lib/RT/Interface/Email.pm
+++ b/lib/RT/Interface/Email.pm
@@ -406,8 +406,10 @@ sub SendEmail {
         my $path = RT->Config->Get('SendmailPath');
         my $args = RT->Config->Get('SendmailArguments');
 
-        # SetOutgoingMailFrom
-        if ( RT->Config->Get('SetOutgoingMailFrom') ) {
+        # SetOutgoingMailFrom and bounces conflict, since they both want -f
+        if ( $args{'Bounce'} ) {
+            $args .= ' '. RT->Config->Get('SendmailBounceArguments');
+        } elsif ( RT->Config->Get('SetOutgoingMailFrom') ) {
             my $OutgoingMailAddress;
 
             if ($TicketObj) {
@@ -427,9 +429,6 @@ sub SendEmail {
                 if $OutgoingMailAddress;
         }
 
-        # Set Bounce Arguments
-        $args .= ' '. RT->Config->Get('SendmailBounceArguments') if $args{'Bounce'};
-
         # VERP
         if ( $TransactionObj and
              my $prefix = RT->Config->Get('VERPPrefix') and

-----------------------------------------------------------------------


More information about the Rt-commit mailing list