[Rt-commit] rt branch, 4.2-trunk, updated. rt-4.2.13-52-g9b47056
Shawn Moore
shawn at bestpractical.com
Wed Aug 24 13:22:42 EDT 2016
The branch, 4.2-trunk has been updated
via 9b4705611e637604a3c00b7c3f036196928c581f (commit)
via 69474c481897f655239467077976fbdc11b6879d (commit)
via b34993b69bbb8480f2759950a926995b0fae7aed (commit)
from 1e3010c6bffdbf4923edf0cdc439fba39655acc0 (commit)
Summary of changes:
lib/RT/Interface/Email.pm | 47 ++++++++++++++++++++++---------------
t/mail/outgoing-mail-from.t | 56 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+), 19 deletions(-)
create mode 100644 t/mail/outgoing-mail-from.t
- Log -----------------------------------------------------------------
commit b34993b69bbb8480f2759950a926995b0fae7aed
Author: Christian Loos <cloos at netcologne.de>
Date: Tue Aug 23 12:58:25 2016 +0200
add tests for *OutgoingMailFrom configs
This tests will actually prove that the next commit don't change
anything.
diff --git a/t/mail/outgoing-mail-from.t b/t/mail/outgoing-mail-from.t
new file mode 100644
index 0000000..fd1050c
--- /dev/null
+++ b/t/mail/outgoing-mail-from.t
@@ -0,0 +1,56 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+
+RT->Config->Set( MailCommand => 'sendmailpipe' );
+RT->Config->Set( SetOutgoingMailFrom => 'rt at example.com' );
+RT->Config->Set( OverrideOutgoingMailFrom => { Test => 'rt-test at example.com' } );
+
+# 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 $queue = RT::Test->load_or_create_queue( Name => 'General' );
+ ok $queue && $queue->id, 'loaded or created queue General';
+
+ my $ticket = RT::Ticket->new( RT->SystemUser );
+ $ticket->Create(
+ Queue => $queue->id,
+ Subject => 'test',
+ Requestor => 'root at localhost',
+ );
+
+ open(my $fh, "<", $ENV{RT_MAILLOGFILE}) or die "Can't open log file: $!";
+ my $ok = 0;
+ while (my $line = <$fh>) {
+ $ok++ if $line =~ /^-f rt\@example.com/;
+ }
+ close($fh);
+ is($ok,1,"'-f rt\@example.com' specified to sendmail command");
+}
+
+{
+ my $queue = RT::Test->load_or_create_queue( Name => 'Test' );
+ ok $queue && $queue->id, 'loaded or created queue Test';
+
+ my $ticket = RT::Ticket->new( RT->SystemUser );
+ $ticket->Create(
+ Queue => $queue->id,
+ Subject => 'test',
+ Requestor => 'root at localhost',
+ );
+
+ open(my $fh, "<", $ENV{RT_MAILLOGFILE}) or die "Can't open log file: $!";
+ my $ok = 0;
+ while (my $line = <$fh>) {
+ $ok++ if $line =~ /^-f rt-test\@example.com/;
+ }
+ close($fh);
+ is($ok,1,"'-f rt-test\@example.com' specified to sendmail command");
+}
+
+done_testing;
commit 69474c481897f655239467077976fbdc11b6879d
Author: Christian Loos <cloos at netcologne.de>
Date: Tue Aug 23 14:51:29 2016 +0200
factor out OutgoingMailFrom in a separate method
This helps extension who want to modify the outgoing mail from.
diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm
index 039c0a8..a82c7fb 100644
--- a/lib/RT/Interface/Email.pm
+++ b/lib/RT/Interface/Email.pm
@@ -352,6 +352,32 @@ sub WillSignEncrypt {
return wantarray ? %args : ($args{Sign} || $args{Encrypt});
}
+sub _OutgoingMailFrom {
+ my $TicketObj = shift;
+
+ my $MailFrom = RT->Config->Get('SetOutgoingMailFrom');
+ my $OutgoingMailAddress = $MailFrom =~ /\@/ ? $MailFrom : undef;
+ my $Overrides = RT->Config->Get('OverrideOutgoingMailFrom') || {};
+
+ if ($TicketObj) {
+ my $Queue = $TicketObj->QueueObj;
+ my $QueueAddressOverride = $Overrides->{$Queue->id}
+ || $Overrides->{$Queue->Name};
+
+ if ($QueueAddressOverride) {
+ $OutgoingMailAddress = $QueueAddressOverride;
+ } else {
+ $OutgoingMailAddress ||= $Queue->CorrespondAddress
+ || RT->Config->Get('CorrespondAddress');
+ }
+ }
+ elsif ($Overrides->{'Default'}) {
+ $OutgoingMailAddress = $Overrides->{'Default'};
+ }
+
+ return $OutgoingMailAddress;
+}
+
sub SendEmail {
my (%args) = (
Entity => undef,
@@ -437,25 +463,8 @@ sub SendEmail {
# SetOutgoingMailFrom and bounces conflict, since they both want -f
if ( $args{'Bounce'} ) {
push @args, shellwords(RT->Config->Get('SendmailBounceArguments'));
- } elsif ( my $MailFrom = RT->Config->Get('SetOutgoingMailFrom') ) {
- my $OutgoingMailAddress = $MailFrom =~ /\@/ ? $MailFrom : undef;
- my $Overrides = RT->Config->Get('OverrideOutgoingMailFrom') || {};
-
- if ($TicketObj) {
- my $Queue = $TicketObj->QueueObj;
- my $QueueAddressOverride = $Overrides->{$Queue->id}
- || $Overrides->{$Queue->Name};
-
- if ($QueueAddressOverride) {
- $OutgoingMailAddress = $QueueAddressOverride;
- } else {
- $OutgoingMailAddress ||= $Queue->CorrespondAddress
- || RT->Config->Get('CorrespondAddress');
- }
- }
- elsif ($Overrides->{'Default'}) {
- $OutgoingMailAddress = $Overrides->{'Default'};
- }
+ } elsif ( RT->Config->Get('SetOutgoingMailFrom') ) {
+ my $OutgoingMailAddress = _OutgoingMailFrom($TicketObj);
push @args, "-f", $OutgoingMailAddress
if $OutgoingMailAddress;
commit 9b4705611e637604a3c00b7c3f036196928c581f
Merge: 1e3010c 69474c4
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Wed Aug 24 17:22:35 2016 +0000
Merge branch '4.2/outgoing-mail-from' into 4.2-trunk
-----------------------------------------------------------------------
More information about the rt-commit
mailing list