SendEmail
SendEmail_Local.pm
This overlay for SendEmail.pm provides a modified SetSubjectToken method. This method is normally invoked by other modules to prepare outgoing e-mail before it is actually sent. Under normal circumstances, it replaces various unwanted linefeed characters in the subject line and then makes sure that the subject line has the associated ticket id prepended to it. This is why every outgoing e-mail from RT has a ticket id at the beginning of the subject line.
This replacement code works in conjunction with a value set in RT_SiteConfig.pm to allow templates to disable the default action of prepending the ticket id. This lets the template programmer generate e-mails whose subject lines are not modified by RT; this allows you to produce e-mails that have subject lines that start with 'Fwd: ' or 'URGENT: ' for example.
Examples
Assumptions for the following template examples are
- Ticket subject is 'My password expired'
- Ticket id is 'MyOrg #1243'
- A value is set for $DisableSubjectToken in RT_SiteConfig.pm
- Scrip action is NotifyOtherRecipients
Received: from EXCHMAILSERVER.tikona.in ([::1]) by EXCHMAILSERVER1.tikona.in
([::1]) with mapi; Fri, 23 Aug 2013 15:56:17 +0530
Content-Type: application/ms-tnef; name="winmail.dat"
Content-Transfer-Encoding: binary
From: Ashish Shrivastava <Ashish.Shrivastava@tikona.in>
To: ATS Indore <ATS.Indore@tikona.in>
Date: Fri, 23 Aug 2013 15:55:39 +0530
Subject: FW: Pending Cases installation reqd
Thread-Topic: Pending Cases installation reqd
Thread-Index: AQHOnv/RJ3UKn5/HhU+D9f3KL+AYN5mgwjWcgAA952CAAZgZMA==
Message-ID: <46E8B8EF4D35704395DAB166E97829BE40B3678FCC@EXCHMAILSERVER.tikona.in>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: yes
X-MS-Exchange-Organization-SCL: -1
X-MS-TNEF-Correlator: <46E8B8EF4D35704395DAB166E97829BE40B3678FCC@EXCHMAILSERVER.tikona.in>
MIME-Version: 1.0
Example 2
Template forwards the original e-mail to me@myorg.org without changing the subject line
E-mail headers:
From: <ticket creator> To: me@myorg.org Reply-To: <ticket creator> Subject: My password expired
Template code:
{ my $ToAddress = 'me@myorg.org'; my $FromAddress = $Ticket->CreatorObj->EmailAddress; my $Subject = $RT::DisableSubjectToken . $Ticket->Subject; my $Content = $Ticket->Transactions->First->Content(); $OUT = "From: $FromAddress\n"; $OUT .= "To: $ToAddress\n"; $OUT .= "Reply-To: $FromAddress\n"; $OUT .= "Subject: $Subject\n\n"; $OUT .= "$Content\n"; }
Example 3
Template forwards the original e-mail to me@myorg.org, but adds the RT ticket id to the subject line (default RT behavior)
E-mail headers:
From: <ticket creator> To: me@myorg.org Reply-To: <ticket creator> Subject: [MyOrg #1243] My password expired
Template code:
{ my $ToAddress = 'me@myorg.org'; my $FromAddress = $Ticket->CreatorObj->EmailAddress; my $Subject = $Ticket->Subject; my $Content = $Ticket->Transactions->First->Content(); $OUT = "From: $FromAddress\n"; $OUT .= "To: $ToAddress\n"; $OUT .= "Reply-To: $FromAddress\n"; $OUT .= "Subject: $Subject\n\n"; $OUT .= "$Content\n"; }
Example 4
Template forwards the original e-mail to me@myorg.org with Admin Alert! at the start of the subject line
E-mail headers:
From: <ticket creator> To: me@myorg.org Reply-To: <ticket creator> Subject: Admin Alert! My password expired
Template code:
{ my $ToAddress = 'me@myorg.org'; my $FromAddress = $Ticket->CreatorObj->EmailAddress; my $Subject = $RT::DisableSubjectToken; $Subject .= 'Admin Alert! ' . $Ticket->Subject; my $Content = $Ticket->Transactions->First->Content(); $OUT = "From: $FromAddress\n"; $OUT .= "To: $ToAddress\n"; $OUT .= "Reply-To: $FromAddress\n"; $OUT .= "Subject: $Subject\n\n"; $OUT .= "$Content\n"; }
Installation
To install this modification:
- Create a new file called SendEmail_Local.pm in RT's lib/RT/Action directory. If the file already exists, open it in an editor.
- Copy everything between the "10:56, August 23, 2013 (UTC)" lines below into the file, then save and close it.
~~~~~ Start of SendEmail_Local.pm code use strict; no warnings qw(redefine); sub SetSubjectToken { my $self = shift; my $tag = "[$RT::rtname #" . $self->TicketObj->id . "] "; my $sub = $self->TemplateObj->MIMEObj->head->get('Subject'); my $no_rt_flag = $RT::DisableSubjectToken if $RT::DisableSubjectToken; unless ( $sub =~ /\Q$tag\E/ ) { $sub =~ s/(\r\n|\n|\s)/ /gi; chomp $sub; if ( $no_rt_flag && $sub =~ /^\Q$no_rt_flag\E/ ) { $sub =~ s/(\Q$no_rt_flag\E)//; $tag = ''; } $self->TemplateObj->MIMEObj->head->replace( 'Subject', $tag . $sub ); } } 1; ~~~~~ End of SendEmail_Local.pm code
- Copy everything between the "10:56, August 23, 2013 (UTC)" lines below into your RT_SiteConfig.pm file.
~~~~~ Start of RT_SiteConfig.pm code # $DisableSubjectToken is an optional value and can be commented out. # When prepended to a subject line, this character sequence signals RT to # not attach the ticket id to the front of outgoing e-mail. If used, this # value should be a sequence that is unlikely to ever appear at the beginning # of a normal e-mail subject line. It is useful for sending mail that doesn't # "look like" part of a ticket. Set($DisableSubjectToken, '[_><##_]'); ~~~~~ End of RT_SiteConfig.pm code
- Change value of $DisableSubjectToken to whatever you want, just make sure you choose a character sequence that is unlikey to ever appear at the beginning of a normal subject line.
- Save and close RT_SiteConfig.pm
- Restart your web server.
Using this hack
To disable the ticket-stamping behavior, just make the first characters of your subject line the value of $RT::DisableSubjectToken. For example:
$Subject = $RT::DisableSubjectToken . $Ticket->Subject;
Author: Gene LeDuc, gleduc at mail dot sdsu dot edu from