[Rt-commit] r7486 - in rt/branches/3.7-EXPERIMENTAL: .

jesse at bestpractical.com jesse at bestpractical.com
Thu Apr 12 03:09:31 EDT 2007


Author: jesse
Date: Thu Apr 12 03:09:29 2007
New Revision: 7486

Modified:
   rt/branches/3.7-EXPERIMENTAL/   (props changed)
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Attachment_Overlay.pm
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Ticket_Overlay.pm
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Transaction_Overlay.pm

Log:
 r54774 at pinglin:  jesse | 2007-04-12 02:59:53 -0400
 * Added support for finding the users on all ticket txns.


Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Attachment_Overlay.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Attachment_Overlay.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Attachment_Overlay.pm	Thu Apr 12 03:09:29 2007
@@ -425,6 +425,42 @@
     return $entity;
 }
 
+
+=head2 Addresses
+
+Returns a hashref of all addresses related to this attachment.  
+The keys of the hash are C<To>,C<Cc> and C<Bcc>. The values are references to lists of Mail::Address objects.
+
+
+=cut
+
+
+sub Addresses {
+    my $self = shift;
+
+    my %data = ();
+    my $current_user_address = lc $self->CurrentUser->EmailAddress;
+    my $correspond = lc $self->TransactionObj->TicketObj->QueueObj->CorrespondAddress;
+    my $comment = lc $self->TransactionObj->TicketObj->QueueObj->CommentAddress;
+    foreach my $hdr (qw(To Cc Bcc RT-Send-Cc RT-Send-Bcc)) {
+        my @Addresses;
+        my $line      = $self->GetHeader($hdr);
+        
+        foreach my $AddrObj ( Mail::Address->parse( $line )) {
+            my $address = $AddrObj->address;
+            my $user    = RT::User->new($RT::SystemUser);
+            $address = lc $user->CanonicalizeEmailAddress($address);
+            next if ( $current_user_address eq $address );
+            next if ( $comment              eq $address );
+            next if ( $correspond           eq $address );
+            next if ( RT::EmailParser->IsRTAddress($address) );
+            push @Addresses, $AddrObj ;
+        }
+		$data{$hdr} = \@Addresses;
+    }
+	return \%data;
+}
+
 =head2 NiceHeaders
 
 Returns a multi-line string of the To, From, Cc, Date and Subject headers.

Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Ticket_Overlay.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Ticket_Overlay.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Ticket_Overlay.pm	Thu Apr 12 03:09:29 2007
@@ -1925,6 +1925,44 @@
 
 # }}}
 
+
+=head2 TransactionAddresses
+
+Returns a composite hashref of the results of L<RT::Transaction/Addresses> for all this ticket's Create, Comment or Correspond transactions.
+The keys are C<To>, C<Cc> and C<Bcc>. The values are lists of C<Mail::Address> objects.
+
+NOTE: For performance reasons, this method might want to skip transactions and go straight for attachments. But to make that work right, we're going to need to go and walk around the access control in Attachment.pm's sub _Value.
+
+=cut
+
+
+sub TransactionAddresses {
+    my $self = shift;
+    my $txns = $self->Transactions;
+
+    my %addresses = ();
+    foreach my $type (qw(Create Comment Correspond)) {
+    $txns->Limit(FIELD => 'Type', OPERATOR => '=', VALUE => $type , ENTRYAGGREGATOR => 'OR', CASESENSITIVE => 1);
+        }
+
+    while (my $txn = $txns->Next) {
+        my $txnaddrs = $txn->Addresses; 
+        foreach my $addrlist ( values %$txnaddrs ) {
+                foreach my $addr (@$addrlist) {
+                    # Skip addresses without a phrase (things that are just raw addresses) if we have a phrase
+                    next if ($addresses{$addr->address} && $addresses{$addr->address}->phrase && not $addr->phrase);
+                    $addresses{$addr->address} = $addr;
+                }
+        }
+    }
+
+    return \%addresses;
+
+}
+
+
+
+
 # {{{ Routines dealing with queues 
 
 # {{{ sub ValidateQueue
@@ -2400,8 +2438,11 @@
     # internal Message-ID now, so all emails sent because of this
     # message have a common Message-ID
     my $org = RT->Config->Get('Organization');
-    unless ($args{'MIMEObj'}->head->get('Message-ID')
-            =~ /<(rt-.*?-\d+-\d+)\.(\d+-0-0)\@\Q$org\E>/) {
+    
+    
+    
+    my $msgid = $args{'MIMEObj'}->head->get('Message-ID');
+    unless (defined $msgid && $msgid =~ /<(rt-.*?-\d+-\d+)\.(\d+-0-0)\@\Q$org\E>/) {
         $args{'MIMEObj'}->head->set( 'RT-Message-ID',
             "<rt-"
             . $RT::VERSION . "-"

Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Transaction_Overlay.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Transaction_Overlay.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Transaction_Overlay.pm	Thu Apr 12 03:09:29 2007
@@ -335,6 +335,26 @@
 
 # }}}
 
+
+=head2 Addresses
+
+Returns a hashref of addresses related to this transaction. See L<RT::Attachment/Addresses> for details.
+
+=cut
+
+sub Addresses {
+	my $self = shift;
+
+	if (my $attach = $self->Attachments->First) {	
+		return $attach->Addresses;
+	}
+	else {
+		return {};
+	}
+
+}
+
+
 # {{{ ContentObj
 
 =head2 ContentObj 


More information about the Rt-commit mailing list