[rt-devel] Using MessageId field in Attachments table

Eric Berggren ericb at fpt.fujitsu.com
Mon Feb 25 16:05:17 EST 2002


  As partial closure to my thread, here's the rest of the patch for the
MessageId tracking 'thingy'... note that this hasn't been put through
very rigorous testing, as the project slowly moves along, but will
certainly update my findings if anything turns up...

regards,
-eric
--
Fujitsu Processor Technologies, Inc.
 (Lawrence System Integration, Inc.)


*** lib/RT/EasySearch.pm-old	Mon Dec  3 17:13:42 2001
--- lib/RT/EasySearch.pm	Tue Feb 19 14:39:08 2002
***************
*** 23,29 ****
  
  package RT::EasySearch;
  use DBIx::SearchBuilder;
! @ISA= qw(DBIx::SearchBuilder);
  
  # {{{ sub _Init 
  sub _Init  {
--- 23,30 ----
  
  package RT::EasySearch;
  use DBIx::SearchBuilder;
! use DBIx::SearchBuilder::Record::Cachable;
! @ISA= qw(DBIx::SearchBuilder DBIx::SearchBuilder::Record::Cachable);
  
  # {{{ sub _Init 
  sub _Init  {
*** lib/RT/Attachment.pm-old	Tue Nov  6 15:04:14 2001
--- lib/RT/Attachment.pm	Tue Feb 19 12:26:23 2002
***************
*** 66,72 ****
  
  =head2 TransactionObj
  
! Returns the transaction object asscoiated with this attachment.
  
  =cut
  
--- 66,72 ----
  
  =head2 TransactionObj
  
! Returns the transaction object associated with this attachment.
  
  =cut
  
***************
*** 123,128 ****
--- 123,134 ----
      defined($Subject) or $Subject = '';
      chomp($Subject);
    
+     #Get the message-id
+     my $MessageId = $Attachment->head->get('message-id',0);
+     defined($MessageId) or $MessageId = '';
+     chomp($MessageId);
+     $MessageId = $1 if ( $MessageId =~ /<(.+)>/ );
+   
      #Get the filename
      my $Filename = $Attachment->head->recommended_filename;
      
***************
*** 131,136 ****
--- 137,143 ----
  				   Parent => 0,
  				   ContentType  => $Attachment->mime_type,
  				   Headers => $Attachment->head->as_string,
+ 				   MessageId => $MessageId,
  				   Subject => $Subject,
  				   
  				  );
***************
*** 201,206 ****
--- 208,214 ----
  				      Parent => $args{'Parent'},
  				      Content => $Body,
  				      Headers => $Attachment->head->as_string,
+ 				      MessageId => $MessageId,
  				      Subject => $Subject,
  				      Filename => $Filename,
  				     );
*** lib/RT/EasySearch.pm-old	Mon Dec  3 17:13:42 2001
--- lib/RT/EasySearch.pm	Tue Feb 19 14:39:08 2002
***************
*** 23,29 ****
  
  package RT::EasySearch;
  use DBIx::SearchBuilder;
! @ISA= qw(DBIx::SearchBuilder);
  
  # {{{ sub _Init 
  sub _Init  {
--- 23,30 ----
  
  package RT::EasySearch;
  use DBIx::SearchBuilder;
! use DBIx::SearchBuilder::Record::Cachable;
! @ISA= qw(DBIx::SearchBuilder DBIx::SearchBuilder::Record::Cachable);
  
  # {{{ sub _Init 
  sub _Init  {
*** lib/RT/Interface/Email.pm-old	Tue Nov  6 15:04:52 2001
--- lib/RT/Interface/Email.pm	Tue Feb 19 16:23:31 2002
***************
*** 6,11 ****
--- 6,12 ----
  use strict;
  use Mail::Address;
  use MIME::Entity;
+ use RT::Transactions;
  
  BEGIN {
      use Exporter ();
***************
*** 265,280 ****
  
  sub ParseTicketId {
      my $Subject = shift;
      my ($Id);
!     
      if ($Subject =~ s/\[$RT::rtname \#(\d+)\]//i) {
  	$Id = $1;
  	$RT::Logger->debug("Found a ticket ID. It's $Id");
  	return($Id);
      }
!     else {
! 	return(undef);
      }
  }
  # }}}
  
--- 266,304 ----
  
  sub ParseTicketId {
      my $Subject = shift;
+     my $MessageId = shift;
      my ($Id);
! 
!     # see if there's a ticket reference in the subject
      if ($Subject =~ s/\[$RT::rtname \#(\d+)\]//i) {
  	$Id = $1;
  	$RT::Logger->debug("Found a ticket ID. It's $Id");
  	return($Id);
      }
! 
!     # else, try to lookup in Attachments table (from incoming e-mail)
!     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 Transactions tbl
! 	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);
  }
  # }}}
  

*** /u/ericb/projects/reqtracker-2.0.11/bin/rt-mailgate	Thu Nov 29 00:42:41 2001
--- bin/rt-mailgate	Tue Feb 19 16:51:08 2002
***************
*** 109,120 ****
  my $MessageId = $head->get('Message-Id') || 
    "<no-message-id-".time.rand(2000)."\@.$RT::rtname>";
  
  #Pull apart the subject line
  $Subject = $head->get('Subject') || "[no subject]";
  chomp $Subject;
  
  # Get the ticket ID unless it's already set
! $TicketId = ParseTicketId($Subject) unless ($TicketId);
  
  #Set up a queue object
  my $QueueObj = RT::Queue->new($CurrentUser);
--- 109,123 ----
  my $MessageId = $head->get('Message-Id') || 
    "<no-message-id-".time.rand(2000)."\@.$RT::rtname>";
  
+ my $ReplMessageId = $head->get('In-Reply-To');
+ $ReplMessageId = $1 if ( $ReplMessageId =~ /<(.+)>/ );
+ 
  #Pull apart the subject line
  $Subject = $head->get('Subject') || "[no subject]";
  chomp $Subject;
  
  # Get the ticket ID unless it's already set
! $TicketId = ParseTicketId($Subject,$ReplMessageId) unless ($TicketId);
  
  #Set up a queue object
  my $QueueObj = RT::Queue->new($CurrentUser);





More information about the Rt-devel mailing list