[rt-devel] Draft patch to add references and in-reply-to parsing

Chad Scott chad at idworld.net
Fri Feb 20 09:46:17 EST 2004


Unfortunately, you'd have to retrieve the Ticket and either pull the 
oldest attachment (which should be what created the ticket) in the best 
case, or walk through all the attachments in a worst case, and create a 
hash of the Message-ID headers you see.  This would be both database 
and processor intensive as you're essentially going to have to search 
at least one attachment for every ticket.

A better solution would be to create a column either in the Ticket 
table or the Attachment table to hold your reference message-id(s) and 
populate them on the initial insert, but that requires a schema change.

On Jan 27, 2004, at 6:16 AM, Petter Reinholdtsen wrote:

>
> We are testing RT here at work, and one of the problems we would like
> to solve is making sure emails are grouped together in the correct
> ticket, even if the subject is missing the ticket ID marker.  We want
> the follwing messages to end up in the same ticket when recieved in
> order:
>
>   To: otrs at some.domain
>   Subject: Foo is not working, everything is bad
>   From: user at some.domain
>   Message-ID: <1 at some.domain>
>
>   Please, please help us.
>
>
>
>   To: otrs at some.domain
>   Subject: Re: Foo is not working, everything is bad
>   From: user at some.domain
>   References: <1 at some.domain>
>   In-Reply-To: <1 at some.domain>
>   Message-ID: <2 at some.domain>
>
>   Oh, and bar is giving strange noises as well.
>
>
>
>   To: otrs at some.domain
>   Subject: Re: Foo is not working, everything is bad
>   From: user at some.domain
>   References: <1 at some.domain> <2 at some.domain>
>   In-Reply-To: <2 at some.domain>
>   Message-ID: <3 at some.domain>
>
>   I got my local admin to help me.  Everything is OK now.
>
>
> As you can see, the messages contain references to each other, and it
> should be possible to make sure these emails are grouped together in
> one ticket.
>
> I've started on a patch, but do not quite know how to look up ticket
> IDs based on message-ids.  Anyone got a clue to spare?
>
> Here is the current draft, which of course do not work because the
> part marked XXX is broken.
>
>
> --- src-3-0-8/lib/RT/Interface/Email.pm 2004-01-02 22:23:39.000000000 
> +0100
> +++ src-3-0-8-local/lib/RT/Interface/Email.pm  2004-01-27 
> 14:23:13.000000000 +0100
> @@ -475,6 +475,61 @@
>
>      $args{'ticket'} ||= $parser->ParseTicketId($Subject);
>
> +    unless ( $args{'ticket'} ) {
> +        # Based on info from 
> <URL:http://www.jwz.org/doc/threading.html>
> +       my @msgids = ();
> +
> +       my $references = $head->get('References') || '';
> +       my $inreplyto  = $head->get('In-Reply-To') || '';
> +
> +       push(@msgids, split(/\s+/, $references)) if ($references);
> +
> +       if ($inreplyto) {
> +           if ($inreplyto =~ m/(<[^>]+>)/) {
> +               push(@msgids, $1);
> +           } else {
> +               $RT::Logger->log(level => 'debug',
> +                                message => "Gateway: Unhandled 
> In-Reply-To format: '$inreplyto'"
> +                                );
> +           }
> +       }
> +
> +        # Map Message-id(s) to ticket id
> +       my @ids = ();
> +       my %checked;
> +       my $msgid;
> +       for $msgid (@msgids) {
> +           next if $checked{$msgid}; # Already looked up this 
> message-id
> +
> +           # XXX Find proper API
> +           my $TicketID = 
> $RT::Attachment::TicketIDofMessageId($msgid);
> +           push(@ids, @TicketIDs) if (@TicketIDs);
> +
> +           $checked{$msgid} = 1;
> +       }
> +
> +       # Reduce list of IDs to unique IDs only
> +       my $id;
> +       my %idhash;
> +       for $id (sort @ids) {
> +           $idhash{$id} = 1;
> +       }
> +       @ids = sort keys %idhash;
> +
> +       # If the Message-id(s) are already in the database, use their
> +       # ticked-id
> +       if (1 < @ids) {
> +           $RT::Logger->log(level => 'debug',
> +                            message => "Gateway: Several possible 
> tickets: " .
> +                                join(",", @ids)
> +                            );
> +       }
> +
> +       # Just pick the first.  Not sure how we should handle several
> +       # ticket ids
> +       $args{'ticket'} = $ids[0] if (@ids);
> +    }
> +
>      my $SystemTicket;
>      if ( $args{'ticket'} ) {
>          $SystemTicket = RT::Ticket->new($RT::SystemUser);
> _______________________________________________
> rt-devel mailing list
> rt-devel at lists.bestpractical.com
> http://lists.bestpractical.com/mailman/listinfo/rt-devel




More information about the Rt-devel mailing list