[Rt-commit] r19596 - in rt/3.8/branches/forward-with-transaction/lib/RT: Interface
falcone at bestpractical.com
falcone at bestpractical.com
Fri May 8 17:43:52 EDT 2009
Author: falcone
Date: Fri May 8 17:43:51 2009
New Revision: 19596
Modified:
rt/3.8/branches/forward-with-transaction/lib/RT/Action/SendEmail.pm
rt/3.8/branches/forward-with-transaction/lib/RT/Interface/Email.pm
Log:
* 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.
Modified: rt/3.8/branches/forward-with-transaction/lib/RT/Action/SendEmail.pm
==============================================================================
--- rt/3.8/branches/forward-with-transaction/lib/RT/Action/SendEmail.pm (original)
+++ rt/3.8/branches/forward-with-transaction/lib/RT/Action/SendEmail.pm Fri May 8 17:43:51 2009
@@ -509,55 +509,13 @@
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;
}
Modified: rt/3.8/branches/forward-with-transaction/lib/RT/Interface/Email.pm
==============================================================================
--- rt/3.8/branches/forward-with-transaction/lib/RT/Interface/Email.pm (original)
+++ rt/3.8/branches/forward-with-transaction/lib/RT/Interface/Email.pm Fri May 8 17:43:51 2009
@@ -651,9 +651,85 @@
? SendEmail( Entity => $mail, Transaction => $txn, Sign => 0 )
: SendEmail( Entity => $mail, Transaction => $txn );
return (0, $txn->loc("Couldn't send email")) unless $status;
+ RecordOutgoingMailTransaction(
+ Entity => $mail,
+ Transaction => $txn,
+ Ticket => $txn->Object,
+ Type => 'ForwardedEmailRecord'
+ );
return (1, $txn->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