Wikia

Request Tracker Wiki

SendEmail

Comments0
833pages on
this wiki

Contents

SendEmail_Local.pm Edit

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 Edit

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

Example 1 Edit

Template forwards the original e-mail to me@myorg.org with Fwd: at the start of the subject line

E-mail headers:

From: <ticket creator>
To: me@myorg.org
Reply-To: <ticket creator>
Subject: Fwd: My password expired

Template code:

{
  my $ToAddress = 'me@myorg.org';
  my $FromAddress = $Ticket->CreatorObj->EmailAddress;
  my $Subject = $RT::DisableSubjectToken;
  $Subject .= 'Fwd: ' . $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 2 Edit

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 Edit

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 Edit

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 Edit

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 "~~~~~" 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 "~~~~~" 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 Edit

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

Photos

Add a Photo
33photos on this wiki
See all photos >

Recent Wiki Activity

See more >

Around Wikia's network

Random Wiki