[rt-devel] Draft patch to add references and in-reply-to parsing
Ruslan U. Zakirov
cubic at acronis.ru
Tue Jan 27 10:01:33 EST 2004
Hello, Petter.
Msgids is good idea, but it's really for ideal world only.
There is one known problem in such behavior. Often users use reply
button to create new one ticket. RT don't have split tool. So you should
check Subject alsow.
Also look at comments in code.
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);
You should skip other code if there is no references, shouldn't you?
> +
> + if ($inreplyto) {
> + if ($inreplyto =~ m/(<[^>]+>)/) {
> + push(@msgids, $1);
> + } else {
> + $RT::Logger->log(level => 'debug',
> + message => "Gateway: Unhandled In-Reply-To format: '$inreplyto'"
> + );
> + }
> + }
else {
skip other checks;
}
> +
> + # 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;
> + }
Here is something like
my $Attachs = $RT::Attachments->new($RT::SystemUser);
$Attachs->Limit(FIELD => 'ContentType',
OPERATOR => '=',
VALUE => 'text/plain'
);
$Attachs->Limit(FIELD => 'ContentType',
OPERATOR => '=',
VALUE => 'text/html'
);
$Attachs->Limit(FIELD => 'Parent', OPERATOR => '=', VALUE => '0');
my $trs = $Attachs->NewAlias('Transactions');
my $tis = $Attachs->NewAlias('Tickets');
$Attachs->Join(
ALIAS1 => 'main',
FIELD1 => 'TransactionId',
ALIAS2 => $trs,
FIELD2 => 'id'
);
$Attachs->Join(
ALIAS1 => $trs,
FIELD1 => 'Ticket',
ALIAS2 => $tis,
FIELD2 => 'id'
);
$Attachs->Limit( ALIAS => $trs,
FIELD => 'Type',
OPERATOR => '=',
VALUE => 'Comment'
);
$Attachs->Limit( ALIAS => $trs,
FIELD => 'Type',
OPERATOR => '=',
VALUE => 'Correspond'
);
........
I hope you could continue this...
> +
> + # 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