[Rt-commit] rt branch, 3.8-forward-message-encoding, updated. 0393d2a05310e92ce27dd24bab52786acdf2e78a

Ruslan Zakirov ruz at bestpractical.com
Tue Jul 28 18:18:55 EDT 2009


The branch, 3.8-forward-message-encoding has been updated
       via  0393d2a05310e92ce27dd24bab52786acdf2e78a (commit)
       via  ff68e6e00bbca1d4408a2d2869622df32b408873 (commit)
       via  aa0120fe1cc1b4cf9631c3ef8f92d69cb35bd46e (commit)
       via  4ec10e1350c906d09c4db9423e704fba612438c2 (commit)
       via  0ba873fd004afe885a2490f4c8dddcc46c0a9394 (commit)
       via  a8c2a85d3044bfcec709ed4aae197c3a9771a6bb (commit)
       via  62fd9383ca2aed95b76696523f7e81dc83be1770 (commit)
      from  5ede1b1f8c0d22d1b9227feb3f77e0cdf531dfce (commit)

Summary of changes:
 etc/initialdata                 |    2 +-
 lib/RT/Interface/Email.pm       |  126 +++++++++++++++++++++++----------------
 lib/RT/Ticket_Overlay.pm        |    7 ++
 lib/RT/Transaction_Overlay.pm   |   47 ++++++++++++++
 share/html/Ticket/Elements/Tabs |    8 +++
 share/html/Ticket/Forward.html  |   19 ++++--
 6 files changed, 150 insertions(+), 59 deletions(-)

- Log -----------------------------------------------------------------
commit 62fd9383ca2aed95b76696523f7e81dc83be1770
Author: Ruslan Zakirov <Ruslan.Zakirov at gmail.com>
Date:   Wed Jul 29 02:12:09 2009 +0400

    * ContentAsMIME into transactions

diff --git a/lib/RT/Transaction_Overlay.pm b/lib/RT/Transaction_Overlay.pm
index 3878c61..5dd9118 100755
--- a/lib/RT/Transaction_Overlay.pm
+++ b/lib/RT/Transaction_Overlay.pm
@@ -522,6 +522,53 @@ sub _Attach {
 
 # }}}
 
+sub ContentAsMIME {
+    my $self = shift;
+
+    my $main_content = $self->ContentObj;
+    my $entity = $main_content->ContentAsMIME;
+
+    if ( $main_content->Parent ) {
+        # main content is not top most entity, we shouldn't loose
+        # From/To/Cc headers that are on a top part
+        my $attachments = RT::Attachments->new( $self->CurrentUser );
+        $attachments->Columns(qw(id Parent TransactionId Headers));
+        $attachments->Limit( FIELD => 'TransactionId', VALUE => $self->id );
+        $attachments->Limit( FIELD => 'Parent', VALUE => 0 );
+        $attachments->Limit( FIELD => 'Parent', OPERATOR => 'IS', VALUE => 'NULL', QUOTEVALUE => 0 );
+        $attachments->OrderBy( FIELD => 'id', ORDER => 'ASC' );
+        my $tmp = $attachments->First;
+        if ( $tmp && $tmp->id ne $main_content->id ) {
+            $entity->make_multipart;
+            $entity->head->add( split /:/, $_, 2 ) foreach $tmp->SplitHeaders;
+            $entity->make_singlepart;
+        }
+    }
+
+    my $attachments = RT::Attachments->new( $self->CurrentUser );
+    $attachments->Limit( FIELD => 'TransactionId', VALUE => $self->id );
+    $attachments->Limit(
+        FIELD => 'id',
+        OPERATOR => '!=',
+        VALUE => $main_content->id,
+    );
+    $attachments->Limit(
+        FIELD => 'ContentType',
+        OPERATOR => 'NOT STARTSWITH',
+        VALUE => 'multipart/',
+    );
+    $attachments->Limit(
+        FIELD => 'Content',
+        OPERATOR => '!=',
+        VALUE => '',
+    );
+    while ( my $a = $attachments->Next ) {
+        $entity->make_multipart unless $entity->is_multipart;
+        $entity->add_part( $a->ContentAsMIME );
+    }
+    return $entity;
+}
+
 # {{{ Routines dealing with Transaction Attributes
 
 # {{{ sub Description 

commit a8c2a85d3044bfcec709ed4aae197c3a9771a6bb
Author: Ruslan Zakirov <Ruslan.Zakirov at gmail.com>
Date:   Wed Jul 29 02:12:53 2009 +0400

    * limit when user has no rights

diff --git a/lib/RT/Ticket_Overlay.pm b/lib/RT/Ticket_Overlay.pm
index 1c12264..216b807 100755
--- a/lib/RT/Ticket_Overlay.pm
+++ b/lib/RT/Ticket_Overlay.pm
@@ -3474,6 +3474,13 @@ sub Transactions {
             );
 
         }
+    } else {
+        $transactions->Limit(
+            SUBCLAUSE => 'acl',
+            FIELD    => 'id',
+            VALUE    => 0,
+            ENTRYAGGREGATOR => 'AND'
+        );
     }
 
     return ($transactions);

commit 0ba873fd004afe885a2490f4c8dddcc46c0a9394
Author: Ruslan Zakirov <Ruslan.Zakirov at gmail.com>
Date:   Wed Jul 29 02:14:12 2009 +0400

    * split ForwardTransaction into ForwardTicket and SendForward

diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm
index 703338b..d57f8eb 100755
--- a/lib/RT/Interface/Email.pm
+++ b/lib/RT/Interface/Email.pm
@@ -548,7 +548,7 @@ sub SendEmailUsingTemplate {
 
 =head2 ForwardTransaction TRANSACTION, To => '', Cc => '', Bcc => ''
 
-Forwards transaction with all attachments 'message/rfc822'.
+Forwards transaction with all attachments as 'message/rfc822'.
 
 =cut
 
@@ -556,55 +556,72 @@ sub ForwardTransaction {
     my $txn = shift;
     my %args = ( To => '', Cc => '', Bcc => '', @_ );
 
-    my $main_content = $txn->ContentObj;
-    my $entity = $main_content->ContentAsMIME;
-
-    if ( $main_content->Parent ) {
-        # main content is not top most entity, we shouldn't loose
-        # From/To/Cc headers that are on a top part
-        my $attachments = RT::Attachments->new( $txn->CurrentUser );
-        $attachments->Columns(qw(id Parent TransactionId Headers));
-        $attachments->Limit( FIELD => 'TransactionId', VALUE => $txn->id );
-        $attachments->Limit( FIELD => 'Parent', VALUE => 0 );
-        $attachments->Limit( FIELD => 'Parent', OPERATOR => 'IS', VALUE => 'NULL', QUOTEVALUE => 0 );
-        $attachments->OrderBy( FIELD => 'id', ORDER => 'ASC' );
-        my $tmp = $attachments->First;
-        if ( $tmp && $tmp->id ne $main_content->id ) {
-            $entity->make_multipart;
-            $entity->head->add( split /:/, $_, 2 ) foreach $tmp->SplitHeaders;
-            $entity->make_singlepart;
-        }
-    }
+    my $entity = $txn->ContentAsMIME;
 
-    my $attachments = RT::Attachments->new( $txn->CurrentUser );
-    $attachments->Limit( FIELD => 'TransactionId', VALUE => $txn->id );
-    $attachments->Limit(
-        FIELD => 'id',
-        OPERATOR => '!=',
-        VALUE => $main_content->id,
-    );
-    $attachments->Limit(
-        FIELD => 'ContentType',
-        OPERATOR => 'NOT STARTSWITH',
-        VALUE => 'multipart/',
+    return SendForward( %args, Entity => $entity, Transaction => $txn );
+}
+
+=head2 ForwardTicket TICKET, To => '', Cc => '', Bcc => ''
+
+Forwards ticket with all transactions and attachments as 'message/rfc822'.
+
+=cut
+
+sub ForwardTicket {
+    my $ticket = shift;
+    my %args = ( To => '', Cc => '', Bcc => '', @_ );
+
+    my $txns = $ticket->Transactions;
+    $txns->Limit(
+        FIELD    => 'Type',
+        VALUE    => $_,
+    ) for qw(Create Correspond);
+
+    my $entity = MIME::Entity->build(
+        Type => 'multipart/mixed',
     );
-    $attachments->Limit(
-        FIELD => 'Content',
-        OPERATOR => '!=',
-        VALUE => '',
+    $entity->add_part( $_ ) foreach 
+        map $_->ContentAsMIME,
+        @{ $txns->ItemsArrayRef };
+
+    return SendForward( %args, Entity => $entity, Ticket => $ticket );
+}
+
+=head2 SendForward Entity => undef, Ticket => undef, Transaction => undef, Template => undef, To => '', Cc => '', Bcc => ''
+
+Forwards an Entity representing Ticket or Transaction as 'message/rfc822'. Entity is wrapped into Template.
+
+=cut
+
+sub SendForward {
+    my (%args) = (
+        Entity => undef,
+        Ticket => undef,
+        Transaction => undef,
+        Template => 'Forward',
+        To => '', Cc => '', Bcc => '',
+        @_
     );
-    while ( my $a = $attachments->Next ) {
-        $entity->make_multipart unless $entity->is_multipart;
-        $entity->add_part( $a->ContentAsMIME );
+
+    my $txn = $args{'Transaction'};
+    my $ticket = $args{'Ticket'};
+    $ticket ||= $txn->Object if $txn;
+
+    my $entity = $args{'Entity'};
+    unless ( $entity ) {
+        require Carp;
+        $RT::Logger->error(Carp::longmess("No entity provided"));
+        return (0, $ticket->loc("Couldn't send email"));
     }
 
     my ($template, $msg) = PrepareEmailUsingTemplate(
-        Template  => 'Forward',
+        Template  => $args{'Template'},
         Arguments => {
+            Ticket      => $ticket,
             Transaction => $txn,
-            Ticket      => $txn->Object,
         },
     );
+
     my $mail;
     if ( $template ) {
         $mail = $template->MIMEObj;
@@ -614,8 +631,13 @@ sub ForwardTransaction {
     unless ( $mail ) {
         $RT::Logger->warning("Couldn't generate email using template 'Forward'");
 
-        my $description = 'This is forward of transaction #'
-            . $txn->id ." of a ticket #". $txn->ObjectId;
+        my $description;
+        unless ( $args{'Transaction'} ) {
+            $description = 'This is forward of ticket #'. $ticket->id;
+        } else {
+            $description = 'This is forward of transaction #'
+                . $txn->id ." of a ticket #". $txn->ObjectId;
+        }
         $mail = MIME::Entity->build(
             Type => 'text/plain',
             Data => $description,
@@ -633,14 +655,15 @@ sub ForwardTransaction {
     );
 
     my $from;
-    my $subject = $txn->Subject || $txn->Object->Subject;
+    my $subject = '';
+    $subject = $txn->Subject if $txn;
+    $subject ||= $ticket->Subject if $ticket;
     if ( RT->Config->Get('ForwardFromUser') ) {
-        $from = $txn->CurrentUser->UserObj->EmailAddress;
+        $from = ($txn || $ticket)->CurrentUser->UserObj->EmailAddress;
     } else {
         # XXX: what if want to forward txn of other object than ticket?
-        my $obj = $txn->Object;
-        $subject = AddSubjectTag( $subject, $obj );
-        $from = $obj->QueueObj->CorrespondAddress
+        $subject = AddSubjectTag( $subject, $ticket );
+        $from = $ticket->QueueObj->CorrespondAddress
             || RT->Config->Get('CorrespondAddress');
     }
     $mail->head->set( Subject => EncodeToMIME( String => "Fwd: $subject" ) );
@@ -648,10 +671,10 @@ sub ForwardTransaction {
 
     my $status = RT->Config->Get('ForwardFromUser')
         # never sign if we forward from User
-        ? SendEmail( Entity => $mail, Transaction => $txn, Sign => 0 )
-        : SendEmail( Entity => $mail, Transaction => $txn );
-    return (0, $txn->loc("Couldn't send email")) unless $status;
-    return (1, $txn->loc("Send email successfully"));
+        ? SendEmail( %args, Entity => $mail, Sign => 0 )
+        : SendEmail( %args, Entity => $mail );
+    return (0, $ticket->loc("Couldn't send email")) unless $status;
+    return (1, $ticket->loc("Send email successfully"));
 }
 
 =head2 SignEncrypt Entity => undef, Sign => 0, Encrypt => 0

commit 4ec10e1350c906d09c4db9423e704fba612438c2
Author: Ruslan Zakirov <Ruslan.Zakirov at gmail.com>
Date:   Wed Jul 29 02:15:49 2009 +0400

    * heh, in RT::I::Email everything else is a function

diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm
index d57f8eb..e987a02 100755
--- a/lib/RT/Interface/Email.pm
+++ b/lib/RT/Interface/Email.pm
@@ -797,7 +797,6 @@ is used, or "latin-1" if that is not set.
 =cut
 
 sub EncodeToMIME {
-    my $self  = shift;
     my %args = (
         String => undef,
         Charset  => undef,

commit aa0120fe1cc1b4cf9631c3ef8f92d69cb35bd46e
Author: Ruslan Zakirov <Ruslan.Zakirov at gmail.com>
Date:   Wed Jul 29 02:16:39 2009 +0400

    * register forward in actions

diff --git a/share/html/Ticket/Elements/Tabs b/share/html/Ticket/Elements/Tabs
index 55b4b87..b57b329 100755
--- a/share/html/Ticket/Elements/Tabs
+++ b/share/html/Ticket/Elements/Tabs
@@ -173,6 +173,14 @@ if ($Ticket) {
         };
     }
 
+    if ( $Ticket->CurrentUserHasRight('ForwardMessage') )
+    {
+        $actions->{'FA'} = {
+            title => loc('Forward'),
+            path  => "Ticket/Forward.html?id=" . $id,
+        };
+    }
+
     if ( $can{'ModifyTicket'} ) {
         if ( $Ticket->Status ne 'resolved' ) {
             $actions->{'G'} = {

commit ff68e6e00bbca1d4408a2d2869622df32b408873
Author: Ruslan Zakirov <Ruslan.Zakirov at gmail.com>
Date:   Wed Jul 29 02:17:23 2009 +0400

    * change web ui according to new API

diff --git a/share/html/Ticket/Forward.html b/share/html/Ticket/Forward.html
index a0d0b41..9830f91 100644
--- a/share/html/Ticket/Forward.html
+++ b/share/html/Ticket/Forward.html
@@ -85,15 +85,20 @@ $id = $ARGS{'id'} = $TicketObj->id;
 Abort( loc("Permission Denied") )
     unless $TicketObj->CurrentUserHasRight('ForwardMessage');
 
-my $txn = RT::Transaction->new( $session{'CurrentUser'} );
-$txn->Load( $QuoteTransaction );
-Abort( loc("Couldn't load transaction #[_1]", $QuoteTransaction) )
-    unless $txn->id;
+my $txn;
+if ( $QuoteTransaction ) {
+    $txn = RT::Transaction->new( $session{'CurrentUser'} );
+    $txn->Load( $QuoteTransaction );
+    Abort( loc("Couldn't load transaction #[_1]", $QuoteTransaction) )
+        unless $txn->id;
+}
 
 my @results;
 if ( $Forward || $ForwardAndReturn ) {
     require RT::Interface::Email;
-    my ($status, $msg) = RT::Interface::Email::ForwardTransaction( $txn, %ARGS );
+    my ($status, $msg) = $txn
+        ? RT::Interface::Email::ForwardTransaction( $txn, %ARGS )
+        : RT::Interface::Email::ForwardTicket( $TicketObj, %ARGS );
     push @results, $msg;
 
     if ( $ForwardAndReturn ) {
@@ -104,7 +109,9 @@ if ( $Forward || $ForwardAndReturn ) {
     }
 }
 
-my $Title = loc('Forward message');
+my $Title = $txn
+    ? loc('Forward transaction #[_1]', $txn->id)
+    : loc('Forward ticket #[_1]', $TicketObj->id);
 
 </%INIT>
 

commit 0393d2a05310e92ce27dd24bab52786acdf2e78a
Author: Ruslan Zakirov <Ruslan.Zakirov at gmail.com>
Date:   Wed Jul 29 02:18:30 2009 +0400

    * update initial data

diff --git a/etc/initialdata b/etc/initialdata
index 6fa740a..ec4e1d9 100755
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -380,7 +380,7 @@ The ticket has been approved, you may now start to act on it.
        Description => "Heading of a forwarded message", # loc
        Content => q{
 
-This is forward of transaction #{ $Transaction->id } of a ticket #{ $Ticket->id }
+This is forward { $Transaction? ('of transaction #'. $Transaction->id) : '' }of a ticket #{ $Ticket->id }
 }
     },
     {  Queue       => 0,

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


More information about the Rt-commit mailing list