import rt 3.0.12
[freeside.git] / rt / html / Ticket / Elements / ShowTransaction
index f2f89d3..8cde038 100644 (file)
 <%PERL>
 
 unless ($Collapsed) {
- $attachments->GotoFirstItem;
- while (my $message=$attachments->Next) {
-     #we don't want to show any empty transactions, unless they have kids
-     next unless ($message->ContentLength || $message->Children->Count);
+ foreach my $message (@$Attachments) { 
 
   my ($headers, $quoted);
       if ($ShowHeaders && ($ShowHeaders == $Ticket->Id)) {
@@ -52,13 +49,31 @@ unless ($Collapsed) {
           # localize the common headers (like 'Subject:'), too.
           eval {$headers =~ s/^([^:]+)(?=:)/loc($1)/em; } # we eval here to catch errors when 5.6 panics
       }
-     # 13456 is a random # of about the biggest size we want to see inline text
-     my $MAX_INLINE_BODY = 13456;
-     if ($message->ContentType =~ m{^(text/plain|message|text$)}i && 
-                                   $message->ContentLength < $MAX_INLINE_BODY ) {
-         require Text::Quoted;
-        $quoted = Text::Quoted::extract($message->Content); 
-     }
+     
+
+     my $MAX_INLINE_BODY = $RT::MaxInlineBody || 13456;
+    if (    $message->ContentType =~ m{^(text/plain|message|text$)}i
+         && $message->ContentLength < $MAX_INLINE_BODY ) {
+
+        my $content;
+        # If we've preloaded all the content, let's pull from there
+        # if we haven't, load it now
+        if ($AttachmentContent->{$message->id}) {
+            $content = $AttachmentContent->{$message->id}->Content;
+        } else {
+            $content = $message->Content;
+        } 
+
+
+
+        eval {
+            require Text::Quoted;
+            $quoted = Text::Quoted::extract( $content );
+        };
+        if ($@) {
+            $quoted = $content;
+        }
+    }
         
 </%PERL>
 <TR class="<% $RowNum%2 ? 'oddline' : 'evenline'%>" >                                
@@ -69,7 +84,12 @@ unless ($Collapsed) {
        <PRE>
 <& ShowMessageHeaders, Headers => $headers, Transaction => $Transaction &>
 </PRE>
+% if ($message->ContentLength && !length($quoted) && $message->ContentType =~ m#^text/#) {
+<blockquote><i><&|/l&>Message body not shown because it is too large or is not plain text.</&><br>
+<&|/l&>You can access it with the Download button on the right.</&></i></blockquote>
+% } else {
 <& ShowMessageStanza, Depth => 0, Message => $quoted, Transaction => $Transaction &>
+% }
 </span>
       </TD>
       <TD VALIGN=TOP ALIGN=RIGHT>
@@ -78,7 +98,7 @@ unless ($Collapsed) {
 <BR>
 % }
 <%PERL>
-my $size = $message->ContentLength;
+my $size = $message->ContentLength or next;
 
 if ($size) {
     if ($size > 1024) {
@@ -88,7 +108,7 @@ if ($size) {
        $size = loc("[_1]b", $size);
     }
 </%PERL>
-<font size=-1><A HREF="<%$RT::WebPath%>/Ticket/Attachment/<%$Transaction->Id%>/<%$message->Id%>/<%$message->Filename%>"><&|/l&>Download</&> <% $message->Filename|| loc('(untitled)') %></a> <% $size %></font>
+<font size=-1><A HREF="<%$AttachPath%>/<%$Transaction->Id%>/<%$message->Id%>/<%$message->Filename | u%>"><&|/l&>Download</&> <% $message->Filename|| loc('(untitled)') %></a> <% $size %></font>
 % }
 </TD>
 </TR>
@@ -104,6 +124,10 @@ $ShowHeaders => 0
 $Collapsed => undef
 $ShowTitleBarCommands => 1
 $RowNum => 1
+$AttachPath => $RT::WebPath."/Ticket/Attachment"
+$UpdatePath => $RT::WebPath."/Ticket/Update.html"
+$Attachments => undef
+$AttachmentContent => undef
 </%ARGS>
 
 <%INIT>
@@ -115,12 +139,7 @@ my $transdate = $Transaction->CreatedAsString();
 $transdate =~ s/\s/&nbsp;/g;
 
 if ($Transaction->Type =~ /^(Create|Correspond|Comment$)/) {
-       if ($Transaction->IsInbound) {
                $bgcolor="#336699";
-       }
-       else {
-               $bgcolor="#339999";
-       }
 } elsif (($Transaction->Field =~ /^Owner$/) or 
         ($Transaction->Type =~ /^(AddWatcher|DelWatcher)$/)) {
        $bgcolor="#333399";
@@ -143,24 +162,30 @@ if ($Ticket->Id != $Transaction->Ticket) {
        $TicketString = "Ticket ".$Transaction->Ticket .": ";
 }
 
-if ($Transaction->TimeTaken > 0) {
+if ($Transaction->TimeTaken != 0) {
        $TimeTaken = $Transaction->TimeTaken." min"
 }
-my $attachments = $Transaction->Attachments;
+
+unless ($Attachments) { 
+    my $attachments = $Transaction->Attachments;
+    $attachments->Columns( qw( Id Filename ContentType Headers Subject Parent ContentEncoding ContentType TransactionId) );
+    $Attachments = $attachments->ItemsArrayRef();
+}
+
 
 my $titlebar_commands='&nbsp;';
 
 # If the transaction has anything attached to it at all
-if ($Transaction->Attachments->First && $ShowTitleBarCommands) {
-       if ($Transaction->TicketObj->CurrentUserHasRight('ReplyToTicket')) {
+if ($Attachments->[0] && $ShowTitleBarCommands) {
+       if ($Ticket->CurrentUserHasRight('ReplyToTicket')) {
                $titlebar_commands .= 
-                 "[<a href=\"Update.html?id=".
+                 "[<a href=\"".$UpdatePath."?id=".
                  $Transaction->Ticket . "&QuoteTransaction=".$Transaction->Id.
                  "&Action=Respond\">". loc('Reply') ."</a>]&nbsp;";
        }
-       if ($Transaction->TicketObj->CurrentUserHasRight('CommentOnTicket')) {
+       if ($Ticket->CurrentUserHasRight('CommentOnTicket')) {
             $titlebar_commands .= 
-            "[<a href=\"Update.html?id=".$Transaction->Ticket. 
+            "[<a href=\"".$UpdatePath."?id=".$Transaction->Ticket. 
             "&QuoteTransaction=".$Transaction->Id.
             "&Action=Comment\">". loc('Comment') ."</a>]";
        }