[rt-users] Including email/correspond attachments in a template

Mauricio Tavares raubvogel at gmail.com
Mon Jun 27 04:37:58 EDT 2011


On Sun, Jun 26, 2011 at 2:05 AM, Mauricio Tavares <raubvogel at gmail.com> wrote:
>        Based on what I have seen on the list, I have the following template
> to include the contents (correspond, email body) of the last ticket being
> sent:
>
> RT-Attach-Message: yes
>
> { ### Get last Correspond
>   my $Transactions = $Ticket->Transactions;
>   $Transactions->Limit( FIELD => 'Type', VALUE => 'Correspond' );
>   $Transactions->OrderByCols (
>      { FIELD => 'Created',  ORDER => 'DESC' },
>      { FIELD => 'id',     ORDER => 'DESC' },
>   );
>   my $CorrespondObj = $Transactions->First;
>   if ($CorrespondObj && $CorrespondObj->Id) {
>     $c_content = $CorrespondObj->Content;
>     chomp $c_content;
>
>   }
>   $c_content
> }
>
> Now that takes care of the text part of the ticket, but what to do when a
> given ticket has an attachment -- say, a picture -- and I would like to keep
> it?
>

Let me rephrase my question: What I am trying to do is emulate

{$Transaction->Content()}

for when the transaction really has no content, such as owner change.
With the code below I can see that I have attachments associated with
the last correspond transaction in the ticket and what kind of
attachments they are.

To: { $Ticket->OwnerObj->EmailAddress }
Subject: Worked on: { $Ticket->Subject() }
RT-Attach-Message: yes

{
   my $thingie = "Attachments:";
   my $Transactions = $Ticket->Transactions;

   $Transactions->Limit( FIELD => 'Type',
                           VALUE => "Correspond"
                         );
   my $TransactionObj = $Transactions->Last;
      my $AttachmentsObj = RT::Attachments->new($TransactionObj->CurrentUser);
      $AttachmentsObj->Limit( FIELD => 'TransactionID',
                              VALUE => $TransactionObj->id
                            );
      while ( my $a = $AttachmentsObj->Next ) {
         $thingie .= "\nFound an attachment with encoding " .
$a->ContentType . " ID " . $a->id;
         if ( $a->ContentType eq 'text/plain' ){
            $thingie .= "\nContent:\n" . $a->Content;
         }
         else {
            $thingie .= "\nNon ascii content here!";
         }
      }
   $thingie;
}

But that is as far as I went. I have been searching through the wiki
and this mailing list but am yet to find something like what I am
after. Could anyone provide some pointers?



More information about the rt-users mailing list