aboutsummaryrefslogtreecommitdiffstats
path: root/community/rt4/0001-email-allow-envelope-from-overriding-from-templates.patch
blob: 32b55b30828927df4e167bf67174f5a4c3a10c80 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
From 16205e84a3b6de87dbe46a03174c2d75f1d1d544 Mon Sep 17 00:00:00 2001
From: Kory Prince <korylprince@gmail.com>
Date: Thu, 22 Mar 2018 13:00:02 -0500
Subject: [PATCH] email: allow envelope from overriding from templates

Add X-RT-Envelope-From header that will override the envelope
from if using sendmailpipe mail sending.
---
 lib/RT/Interface/Email.pm | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm
index 7466c0f78..04a88554c 100644
--- a/lib/RT/Interface/Email.pm
+++ b/lib/RT/Interface/Email.pm
@@ -740,7 +740,14 @@ sub MailError {
 }
 
 sub _OutgoingMailFrom {
-    my $TicketObj = shift;
+    my (%args) = (
+        Ticket => undef,
+        envelope_from => undef,
+        @_,
+    );
+
+    my $TicketObj = $args{'Ticket'};
+    my $envelope_from = $args{'envelope_from'};
 
     my $MailFrom = RT->Config->Get('SetOutgoingMailFrom');
     my $OutgoingMailAddress = $MailFrom =~ /\@/ ? $MailFrom : undef;
@@ -754,8 +761,9 @@ sub _OutgoingMailFrom {
         if ($QueueAddressOverride) {
             $OutgoingMailAddress = $QueueAddressOverride;
         } else {
-            $OutgoingMailAddress ||= $Queue->CorrespondAddress
-                || RT->Config->Get('CorrespondAddress');
+            $OutgoingMailAddress ||= $envelope_from
+            || $Queue->CorrespondAddress
+            || RT->Config->Get('CorrespondAddress');
         }
     }
     elsif ($Overrides->{'Default'}) {
@@ -823,6 +831,9 @@ sub SendEmail {
 
     my $msgid = Encode::decode( "UTF-8", $args{'Entity'}->head->get('Message-ID') || '' );
     chomp $msgid;
+
+    my $envelope_from = $args{'Entity'}->head->get('X-RT-Envelope-From') || '';
+    chomp $envelope_from;
     
     # If we don't have any recipients to send to, don't send a message;
     unless ( $args{'Entity'}->head->get('To')
@@ -901,7 +912,7 @@ sub SendEmail {
         if ( $args{'Bounce'} ) {
             push @args, shellwords(RT->Config->Get('SendmailBounceArguments'));
         } elsif ( RT->Config->Get('SetOutgoingMailFrom') ) {
-            my $OutgoingMailAddress = _OutgoingMailFrom($TicketObj);
+            my $OutgoingMailAddress = _OutgoingMailFrom( $TicketObj, $envelope_from );
 
             push @args, "-f", $OutgoingMailAddress
                 if $OutgoingMailAddress;
-- 
2.15.1