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 = '[EMAIL PROTECTED]';
  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
_______________________________________________
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Community help: http://wiki.bestpractical.com
Commercial support: [EMAIL PROTECTED]


Discover RT's hidden secrets with RT Essentials from O'Reilly Media. Buy a copy at http://rtbook.bestpractical.com

Reply via email to