[rt-devel] Using MessageId field in Attachments table

Eric Berggren ericb at fpt.fujitsu.com
Tue Feb 19 19:30:41 EST 2002


> You just want to make sure that it's a _local_ rt ticket id.

  You mean in terms of checking that RT::rtname is in there too,
indicating coming from the same system ?  Looks like from the
comments that SetMessageID in SendEmail.pm might later change, so the
code in ParseTicketId would need to change with id. But here's what I
presently have (I'm not a Perl OOpert, btw :) :

    EasySearch.pm:
    > use DBIx::SearchBuilder::Record::Cachable;
    > @ISA= qw(DBIx::SearchBuilder DBIx::SearchBuilder::Record::Cachable);
    

    Email.pm:
    >use RT::Transactions;
    
    sub ParseTicketId {
        my $Subject = shift;
    >   my $MessageId = shift;
        ....
    
    >   # else (ticket ref not in Subject), try to lookup in Attachments table
    >   elsif (defined $MessageId && $MessageId) {
    >       my($attachments) = new RT::Attachment($RT::Nobody);
    >       my($transactions) = new RT::Transaction($RT::Nobody);
    >
    >       $attachments->RT::Record::LoadByCols('MessageId', $MessageId);
    >
    >       # found match in Attachments table, lookup Ticket # in Trans table
    >       if (defined $attachments->TransactionId &&
    >               $attachments->TransactionId > 0) {
    >
    >               $transactions->LoadById($attachments->TransactionId);
    >               return($transactions->Ticket);
    >       }
    >       # else, try to parse RT-generated message-id, if it looks like one
    >       elsif ($MessageId =~ /^rt-(\d+)-(\d+).*\@$RT::rtname$/i) {
    >                my($mticketid, $mtransactionid) = ($1, $2);
    >
    >               $transactions->LoadById($mtransactionid);
    >               return($mticketid) if ($transactions->Ticket == $mticketid);
    >       }
    >   }
    >   return(undef);
    }


  Am I using the objects in their correct form ?


regards,
-eric





More information about the Rt-devel mailing list