import rt 3.8.10
[freeside.git] / rt / html / Ticket / Elements / ShowTransactionAttachments
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC 
6 %#                                          <jesse@bestpractical.com>
7 %# 
8 %# (Except where explicitly superseded by other copyright notices)
9 %# 
10 %# 
11 %# LICENSE:
12 %# 
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
16 %# from www.gnu.org.
17 %# 
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 %# General Public License for more details.
22 %# 
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28 %# 
29 %# 
30 %# CONTRIBUTION SUBMISSION POLICY:
31 %# 
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
37 %# 
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
46 %# 
47 %# END BPS TAGGED BLOCK }}}
48 <%perl>
49 # Find all the attachments which have parent $Parent
50 # For each of these attachments
51 foreach my $message ( grep { $_->Parent == $Parent } @$Attachments ) {
52
53     # {{{    show the headers
54     my $headers = $message->Headers;
55     chomp $headers;
56
57     # localize the common headers (like 'Subject:'), too.
58     $headers =~ s/^([^:]+)(?=:)/loc($1)/em;
59     $m->comp(
60         'ShowMessageHeaders',
61         Headers        => $headers,
62         Transaction    => $Transaction,
63         DisplayHeaders => \@DisplayHeaders
64     );
65
66     # }}}
67     # {{{ if there's any size at all, show the download link
68     my $size = $message->ContentLength;
69     if ($size) {
70         
71 </%perl> 
72 <div class="downloadattachment">
73 <%perl>
74
75      #     show a download link
76      if ( $size > 1024 ) {
77          $size = loc( "[_1]k", int( $size / 102.4 ) / 10 );
78      }
79      else {
80         $size = loc( "[_1]b", $size );
81      }
82         
83 </%PERL> 
84 <a href="<%$AttachPath%>/<%$Transaction->Id%>/<%$message->Id%>/<%$message->Filename | u%>"><&|/l&>Download</&> <%$message->Filename || loc('(untitled)') %></a>
85 <span class="downloadcontenttype">
86 [<%$message->ContentType%> <% $size %>]
87 </span> 
88 </div>
89 % }
90 % # }}}
91 <div class="messagebody">
92 <%perl>
93 # {{{   if it has a content-disposition: attachment, don't show inline
94 unless ( ($message->GetHeader('Content-Disposition')||"") =~ /attachment/i ) {
95
96     my $content;
97
98     # If it's text
99     if (   $message->ContentType =~ m{^(text|message)}i
100         && !($RT::SuppressInlineTextFiles && $message->Filename)
101         && $message->ContentLength <= $RT::MaxInlineBody )
102     {
103
104         if (
105
106             # it's a toplevel object
107             !$ParentObj
108
109             # or its parent isn't a multipart alternative
110             || ( $ParentObj->ContentType !~ m{^multipart/alternative$}i )
111
112             # or it's of our prefered alterative type
113             || (
114                 (
115                     $RT::PreferRichText
116                     && ( $message->ContentType =~ m{^text/(?:html|enriched)$} )
117                 )
118                 || ( !$RT::PreferRichText
119                     && ( $message->ContentType !~ m{^text/(?:html|enriched)$} )
120                 )
121             )
122           )
123         {
124
125             if ( $AttachmentContent->{ $message->id } ) {
126                 $content = $AttachmentContent->{ $message->id }->Content;
127             }
128             else {
129                 $content = $message->Content;
130             }
131
132             # if it's a text/html clean the body and show it
133             if ( $message->ContentType =~ m{^text/(?:html|enriched)$}i ) {
134                 $content =
135                   $m->comp( '/Elements/ScrubHTML', Content => $content );
136                 $m->out($content);
137             }
138
139             # if it's a text/plain show the body
140             elsif ( $message->ContentType =~ m{^(text|message|text)}i ) {
141
142                 eval { require Text::Quoted;  $content = Text::Quoted::extract($content); };
143                 if ($@) { 1; }
144
145                 $m->comp(
146                     'ShowMessageStanza',
147                     Depth       => 0,
148                     Message     => $content,
149                     Transaction => $Transaction
150                 );
151             }
152         }
153
154     }
155
156     # if it's an image, show it as an image
157     elsif ( $RT::ShowTransactionImages and  $message->ContentType =~ /^image\//i ) {
158         $m->out('<img src="'
159               . $AttachPath . '/'
160               . $Transaction->Id . '/'
161               . $message->Id
162               . '/" />' );
163     }
164     elsif ( $message->ContentLength > 0 ) {
165         $m->out(
166             loc( 'Message body not shown because it is too large or is not plain text.' )
167         );
168     }
169 }
170
171 # }}}
172
173 $m->comp(
174     'ShowTransactionAttachments', %ARGS,
175     Parent    => $message->id,
176     ParentObj => $message
177 );
178
179 </%PERL>
180 </div>
181 % }
182 <%ARGS>
183 $Ticket => undef
184 $Transaction => undef
185 $ShowHeaders => 0
186 $Collapsed => undef
187 $ShowTitleBarCommands => 1
188 $RowNum => 1
189 $AttachPath => $RT::WebPath."/Ticket/Attachment"
190 $UpdatePath => $RT::WebPath."/Ticket/Update.html"
191 $EmailRecordPath => $RT::WebPath."/Ticket/ShowEmailRecord.html"
192 $Attachments => undef
193 $AttachmentContent => undef
194 $ShowBody => 1
195 $Parent => 0
196 $ParentObj => 0
197 </%ARGS>
198 <%INIT>
199 my @DisplayHeaders=qw( _all);
200
201 if ( $Transaction->Type =~ /EmailRecord$/ ) {
202     @DisplayHeaders = qw(To Cc Bcc);
203 }
204
205 # If the transaction has anything attached to it at all
206 elsif (!$ShowHeaders)  {
207         @DisplayHeaders = qw(To From RT-Send-Cc Cc Bcc Date Subject);
208 }
209 </%INIT>