[Rt-commit] rt branch, 4.0/forward-with-transaction, created. rt-3.9.7-1171-g0fc20a8

Alex Vandiver alexmv at bestpractical.com
Mon Jan 10 13:17:13 EST 2011


The branch, 4.0/forward-with-transaction has been created
        at  0fc20a8b473809669d6af7d0cbd10912d0256860 (commit)

- Log -----------------------------------------------------------------
commit 0fc20a8b473809669d6af7d0cbd10912d0256860
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Mon Jan 10 13:16:49 2011 -0500

    refactor RefactorOutgoingMailTransaction from Action::SendEmail to Interface::Email
    
    Still need to finish testing, add tests for forwards and fix display to
    understand the new Transaction type.

diff --git a/lib/RT/Action/SendEmail.pm b/lib/RT/Action/SendEmail.pm
index 0c3147d..f7c41aa 100644
--- a/lib/RT/Action/SendEmail.pm
+++ b/lib/RT/Action/SendEmail.pm
@@ -505,55 +505,13 @@ sub RecordOutgoingMailTransaction {
     my $self    = shift;
     my $MIMEObj = shift;
 
-    my @parts = $MIMEObj->parts;
-    my @attachments;
-    my @keep;
-    foreach my $part (@parts) {
-        my $attach = $part->head->get('RT-Attachment');
-        if ($attach) {
-            $RT::Logger->debug(
-                "We found an attachment. we want to not record it.");
-            push @attachments, $attach;
-        } else {
-            $RT::Logger->debug("We found a part. we want to record it.");
-            push @keep, $part;
-        }
-    }
-    $MIMEObj->parts( \@keep );
-    foreach my $attachment (@attachments) {
-        $MIMEObj->head->add( 'RT-Attachment', $attachment );
-    }
-
-    RT::I18N::SetMIMEEntityToEncoding( $MIMEObj, 'utf-8', 'mime_words_ok' );
-
-    my $transaction
-        = RT::Transaction->new( $self->TransactionObj->CurrentUser );
-
-# XXX: TODO -> Record attachments as references to things in the attachments table, maybe.
-
-    my $type;
-    if ( $self->TransactionObj->Type eq 'Comment' ) {
-        $type = 'CommentEmailRecord';
-    } else {
-        $type = 'EmailRecord';
-    }
-
-    my $msgid = $MIMEObj->head->get('Message-ID');
-    chomp $msgid;
-
-    my ( $id, $msg ) = $transaction->Create(
-        Ticket         => $self->TicketObj->Id,
-        Type           => $type,
-        Data           => $msgid,
-        MIMEObj        => $MIMEObj,
-        ActivateScrips => 0
-    );
-
+    my $id = RT::Interface::Email::RecordOutgoingMailTransaction(
+            Entity => $MIMEObj,
+            Transaction => $self->TransactionObject,
+            Object => $self->TicketObj,
+           );
     if ($id) {
         $self->{'OutgoingMailTransaction'} = $id;
-    } else {
-        $RT::Logger->warning(
-            "Could not record outgoing message transaction: $msg");
     }
     return $id;
 }
diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm
index 183263f..0badbe1 100644
--- a/lib/RT/Interface/Email.pm
+++ b/lib/RT/Interface/Email.pm
@@ -765,9 +765,86 @@ sub SendForward {
         ? SendEmail( %args, Entity => $mail, Sign => 0 )
         : SendEmail( %args, Entity => $mail );
     return (0, $ticket->loc("Couldn't send email")) unless $status;
+    RecordOutgoingMailTransaction(
+        Entity => $mail,
+        Transaction => $txn,
+        Ticket => $ticket,
+        Type => 'ForwardedEmailRecord'
+    );
     return (1, $ticket->loc("Send email successfully"));
 }
 
+=head2 RecordOutgoingMailTransaction MIMEObj
+
+Record a transaction in RT with this outgoing message for future record-keeping purposes
+
+ Passed the following required arguments:
+ Entity => MIMEObj
+ Transaction => Transaction
+ Object => Usually a TicketObj (unless we start Forwarding other things)
+
+ Optional arguments
+ Type => Transaction Type
+
+=cut
+
+sub RecordOutgoingMailTransaction {
+    my %args    = @_;
+    my $MIMEObj = $args{Entity};
+    my $TransactionObj = $args{Transaction};
+    my $Object = $args{Object};
+
+    my @parts = $MIMEObj->parts;
+    my @attachments;
+    my @keep;
+    foreach my $part (@parts) {
+        my $attach = $part->head->get('RT-Attachment');
+        if ($attach) {
+            $RT::Logger->debug(
+                "We found an attachment. we want to not record it.");
+            push @attachments, $attach;
+        } else {
+            $RT::Logger->debug("We found a part. we want to record it.");
+            push @keep, $part;
+        }
+    }
+    $MIMEObj->parts( \@keep );
+    foreach my $attachment (@attachments) {
+        $MIMEObj->head->add( 'RT-Attachment', $attachment );
+    }
+
+    RT::I18N::SetMIMEEntityToEncoding( $MIMEObj, 'utf-8', 'mime_words_ok' );
+
+    my $sending_transaction = RT::Transaction->new( $TransactionObj->CurrentUser );
+
+# XXX: TODO -> Record attachments as references to things in the attachments table, maybe.
+
+    my $type = $args{Type};
+    unless ($type) {
+        if ( $TransactionObj->Type eq 'Comment' ) {
+            $type = 'CommentEmailRecord';
+        } else {
+            $type = 'EmailRecord';
+        }
+    }
+
+    my $msgid = $MIMEObj->head->get('Message-ID');
+    chomp $msgid;
+
+    my ( $id, $msg ) = $sending_transaction->Create(
+        Ticket         => $Object->Id,
+        Type           => $type,
+        Data           => $msgid,
+        MIMEObj        => $MIMEObj,
+        ActivateScrips => 0
+    );
+
+    unless ($id) {
+        $RT::Logger->warning("Could not record outgoing message transaction: $msg");
+    }
+    return $id;
+}
+
 =head2 SignEncrypt Entity => undef, Sign => 0, Encrypt => 0
 
 Signs and encrypts message using L<RT::Crypt::GnuPG>, but as well

-----------------------------------------------------------------------


More information about the Rt-commit mailing list