Remove RT signature from subject line

Hi All,

I thought I’d seen this somewhere before, but I can’t find the answer in my
archives or the wiki.

I want to use a template to send an e-mail, but I don’t want the have the
ticket info prepended to the original subject line.

All of the e-mail coming into a particular queue address should be either
generated by a web app or be a reply to an RT-generated e-mail. If an
e-mail comes in that is not related to an existing ticket or is not a new
ticket from the web app, it was sent to the wrong address and I want to
forward it to what I think the intended address is. I’m able to make the
generated mail look like the original mail (original from line, replaced
reply-to, original content) except for the "[MyOrg #2345] " that gets
pasted to the front of the subject line. There’s probably a trick to
sending mail without it, but I haven’t stumbled across it yet.

Thanks,
Gene

Gene LeDuc, GSEC
Security Analyst
San Diego State University

Hi All,
I solved my own problem and thought it might be useful to someone else.

I needed to be able to forward certain mail to an address so that it didn’t
look like it came from RT, so I needed to remove the ticket info from the
subject line. After poking around in the code I figured out that this
requires customization to the SetSubjectToken method in SendEmail.pm (I
chose to create SendEmail_Local.pm to do this). I didn’t want to make
changes that were likely to affect other modules, so I chose to stick a
character sequence at the front of the subject line to signal special
handling. If the flag is not found, the subject line is handled normally
(RT sticks ticket info on the front of the subject). If the flag is found,
the ticket info is not put on the front of the subject line. An optional
second flag if brackets immediately following the first will be put on the
front of the subject line instead (like Fwd: ). For my signal I chose a
sequence of characters that are unlikely to appear at the front of a normal
subject line, like “[__><##]”. The code for my SendEmail_Local.pm is at
the end of this message. Remember to restart apache after creating the
_Local file.

Assumptions for the following template examples:
Ticket Id is 1234
Ticket subject is “How can I change my password?”
Special $no_rt_flag is “[__><##]”

Example 1.
Send an e-mail with the original subject line only, no ticket info:
my $Subject = $Ticket->Transactions->First->Subject();
$Subject = $no_rt_flag . $Subject; # signal to leave off the ticket id
Subject line will be “How can I change my password?”

Example 2.
Send an e-mail with the normal RT-modified subject line:
my $Subject = $Ticket->Transactions->First->Subject();
Subject line will be “[RT #1234] How can I change my password?”

Example 3.
Send an e-mail that looks like a “forwarded” e-mail:
my $Subject = $Ticket->Transactions->First->Subject();
$Subject = $no_rt_flag . “[Fwd: ]” . $Subject; # signal to leave off
ticket id and replace with something else
Subject line will be “Fwd: How can I change my password?”

Example 4.
Send an urgent e-mail to admin alert address:
my $ToAddress = ‘admin_alert@mycompany.com’;
my $Subject = $Ticket->Transactions->First->Subject();
$Subject = $no_rt_flag . “[Urgent: ]” . $Subject; # signal to leave
off ticket id and replace with something else
Subject line will be “Urgent: How can I change my password?”

This isn’t a terribly sophisticated hack and I’m sure it can be
improved. For instance, as coded, you probably can’t embed brackets in the
special tag to get a subject like “[Yowza!] How can…” It suffices for
me, but feel free to fix it up if you want.

Enjoy!
Gene

====== Begin SendEmail_Local.pm =====
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 = “[__><##_]”;
unless ( $sub =~ /\Q$tag\E/ ) {
$sub =~ s/(\r\n|\n|\s)/ /gi;
chomp $sub;
if ( $sub =~ /^\Q$no_rt_flag\E/ ) {
$sub =~ s/(\Q$no_rt_flag\E)//;
if ( $sub =~ /^[.]/ ) {
($tag) = $sub =~ /^[(.
)]/;
$sub =~ s/^([.*])//;
} else {
$tag = ‘’;
}
}
$self->TemplateObj->MIMEObj->head->replace( ‘Subject’, “$tag$sub” );
}
}

1;
======= End SendEmail_Local.pm =====

Gene LeDuc, GSEC
Security Analyst
San Diego State University