Look in the message body for ticket ids

This patch makes RT’s e-mail interface look for ticket ids in the body
of a message if it didn’t find one in the subject. It only looks in
the first MIME part and only if it’s of type text/plain. The
configuration variable $RT::CheckBodyLinesForTicketId enables this
code and also limits the number of lines to look at before giving up.
We set it to 50.

The patch is against 3.0.7_01 but should apply cleanly against 3.0.9
pre 2. Use -p0 when applying. Does anyone see any problems with this
code or have any ideas how it can be improved?

— etc/RT_Config.pm~ 2004-01-26 15:04:39.000000000 -0500
+++ etc/RT_Config.pm 2004-01-26 16:11:27.000000000 -0500
@@ -159,6 +159,13 @@

RT is designed such that any mail which already has a ticket-id associated

with it will get to the right place automatically.

+# If $CheckBodyLinesForTicketId is nonzero, RT will look that many lines
+# into the message body for a ticket id. If it finds one, the message
+# will be appended to the indicated ticket. This only works for text/plain
+# messages.
+Set($CheckBodyLinesForTicketId , undef);

$CorrespondAddress and $CommentAddress are the default addresses

that will be listed in From: and Reply-To: headers of correspondence

and comment mail tracked by RT, unless overridden by a queue-specific

— lib/RT/Interface/Email.pm~ 2004-01-28 07:39:14.000000000 -0500
+++ lib/RT/Interface/Email.pm 2004-01-27 15:23:54.000000000 -0500
@@ -479,7 +479,47 @@
my $Subject = $head->get(‘Subject’) || ‘’;
chomp $Subject;

  • $args{‘ticket’} ||= $parser->ParseTicketId($Subject);
  • $RT::Logger->debug(‘reached new e-mail parsing code’);

  • unless ($args{‘ticket’}) {

  • Try the subject first

  •    my $id = $parser->ParseTicketId($Subject);
    
  • Else look in the body if text/plain and

  • $RT::CheckBodyLinesForTicketId is nonzero (zero by default)

  •    my $lines = $RT::CheckBodyLinesForTicketId;
    
  •    if ($lines && !defined $id) {
    
  •   # Find the first part
    
  •   my $first_part = $Message;
    
  •   while (1) {
    
  •   if (my @parts = $first_part->parts) {
    
  •       $RT::Logger->debug('exploding multipart');
    
  •       $first_part = $parts[0];
    
  •       next;
    
  •   }
    
  •   last;
    
  •   }
    
  •   # If it's text/plain, look for the ticket id
    
  •   my $type = $first_part->effective_type;
    
  •   $RT::Logger->debug("type of first part: $type");
    
  •   if ($type eq 'text/plain'
    
  •   && (my $io = $first_part->open('r'))) {
    
  •       # search the unencoded body line by line
    
  •            while ($lines-- && (my $line = $io->getline)) {
    
  •           chomp $line;
    
  •                $id = $parser->ParseTicketId($line);
    
  •                last if $id;
    
  •            }
    
  •            $io->close;
    
  •        }
    
  •    }
    
  •    $args{'ticket'} = $id;
    
  • }

    my $SystemTicket;
    if ( $args{‘ticket’} ) {

Andrew J. Korty, Principal Security Engineer, GCIA, GCFA
Office of the Vice President for Information Technology
Indiana University

Andrew J. Korty wrote:

The patch is against 3.0.7_01 but should apply cleanly against 3.0.9
pre 2. Use -p0 when applying. Does anyone see any problems with this
code or have any ideas how it can be improved?

Have you considered using ticket-specific email addresses?

The patch that was included here is too old to apply to 4.4 ( I’m on the latest GA - 4.4.2 ).

Can anyone here please provide me with some advice on how to achieve the same goal of parsing the message body (in addition to the subject) for the ticketID ?

Thanks in advance for any assistance you can provide.

Best regards,
G Swizzle