Associate email ticket with Subject Tag in the body

Hi everyone,

I was wondering if there is a way to associate an email ticket with its corresponding subject tag without having the subject tag in the subject line of the email message. Is it possible to put the subject tag in the body of the email message and still be able to associate it with the ticket?

We have several customers who change the subject of their email messages and when it arrives in our RTIR system, we need to manually associate it with the correct ticket. This can be time-consuming and I was hoping there might be a better way to handle this situation.

If anyone has any ideas or suggestions, I would greatly appreciate it!

Thanks in advance.

You can add custom code to the code that trys to parse the ticket ID value from the subject line, see here

From what I understood I need to change this code in /opt/rt5/lib/RT/Interface/Email.pm:

=head3 ExtractTicketId

Passed a L<MIME::Entity> object, and returns a either ticket id or undef
to signal 'new ticket'.

This is a great entry point if you need to customize how ticket ids are
handled for your site. L<RT::Extension::RepliesToResolved> demonstrates
one possible use for this extension.

If the Subject of the L<MIME::Entity> is modified, the updated subject
will be used during ticket creation.

=cut

sub ExtractTicketId {
    my $entity = shift;

    my $subject = Encode::decode( "UTF-8", $entity->head->get('Subject') || '' );
    chomp $subject;
    return ParseTicketId( $subject, $entity );
}

=head3 ParseTicketId

Takes a string (the email subject) and searches for [subjecttag #id]

For customizations, the L<MIME::Entity> object is passed as the second
argument.

Returns the id if a match is found.  Otherwise returns undef.

=cut

sub ParseTicketId {
    my $Subject = shift;
    my $Entity = shift;

    my $rtname = RT->Config->Get('rtname');
    my $test_name = RT->Config->Get('EmailSubjectTagRegex') || qr/\Q$rtname\E/i;

    # We use @captures and pull out the last capture value to guard against
    # someone using (...) instead of (?:...) in $EmailSubjectTagRegex.
    my $id;
    if ( my @captures = $Subject =~ m{\[(?:https?://)?$test_name\s+\#(\d+)\s*\]}i ) {
        $id = $captures[-1];
    } else {
        foreach my $tag ( RT->System->SubjectTag ) {
            next unless my @captures = $Subject =~ m{\[(?:https?://)?\Q$tag\E\s+\#(\d+)\s*\]}i;
            $id = $captures[-1];
            last;
        }
    }
    return undef unless $id;

    $RT::Logger->debug("Found a ticket ID. It's $id");
    return $id;
}

I need to change everything that says Subject or $subject with the body of the message.

What is the variable of the body of the message?

Also here:

my $test_name = RT->Config->Get('EmailSubjectTagRegex') || qr/\Q$rtname\E/i;

What should I change at EmailSubjectTagRegex ?

Thanks in advanced !!!

It looks like you can try and get the body from the MIME obj:

and then try and figure out the ticket ID and return it so that RT replies on the ticket instead of creating a new one