[Rt-devel] Looking up a ticket by attachment's messageid

Gordon Messmer yinyang at eburg.com
Sat Jun 7 21:30:42 EDT 2008


Petter Reinholdtsen wrote:
> An old patch to do what you want is available from
> <URL:http://www.usit.uio.no/it/rt/modifications/> under the title "Use
> References and In-Reply-to of incoming emails to find ticket ID"
>
> Happy hacking,
>   

I came back to this patch and added the In-Reply-To header.  I see that 
one part of the patch from UiO appears to have been integrated into 
RT3.  The reset seems overly complicated, or inconsistent (UiO strips <> 
from In-Reply-To, but not from anything else) so I'll keep using my own.

I was quite happy to find the Email-administration package there.  I've 
added that to my installation.

Thanks, again, to everyone that gave me pointers to get this going.


-------------- next part --------------
--- /usr/lib/perl5/vendor_perl/5.8.8/RT/Interface/Email.pm.orig	2008-02-26 15:31:19.000000000 -0800
+++ /usr/lib/perl5/vendor_perl/5.8.8/RT/Interface/Email.pm	2008-06-03 12:07:04.000000000 -0700
@@ -599,6 +599,29 @@
         $Right = 'CreateTicket';
     }
 
+    # Look up ticket by messageid if the subject doesn't have the ticket id.
+    if ( ! $SystemTicket->id ) {
+        my $References = $head->get('References');
+        my $InReplyTo = $head->get('In-Reply-To');
+        my @RefArray = ();
+        push(@RefArray, split(/\s+/, $References)) if ( defined($References) );
+        push(@RefArray, $InReplyTo) if ( defined($InReplyTo) );
+        if ( @RefArray > 0 ) {
+            my $a = RT::Attachment->new($RT::SystemUser);
+            foreach my $Reference (@RefArray) {
+                if ($Reference =~ /<(.*)>/) {
+                    $Reference = $1;
+                }
+                $a->LoadByCols(MessageId => $Reference);
+                if ( $a->id ) {
+                    $SystemTicket->Load( $a->TransactionObj->TicketObj->id );
+                    $Right = 'ReplyToTicket';
+                    last;
+                }
+            }
+        }
+    }
+
     #Set up a queue object
     my $SystemQueueObj = RT::Queue->new($RT::SystemUser);
     $SystemQueueObj->Load( $args{'queue'} );


More information about the Rt-devel mailing list