import rt 3.8.7
[freeside.git] / rt / share / 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 $_->__Value('Parent') == $Parent, @$Attachments ) {
52
53     if (RT->Config->Get('GnuPG')->{'Enable'}) {
54         $m->comp( 'ShowGnuPGStatus', Attachment => $message, WarnUnsigned => $WarnUnsigned );
55     }
56
57     $m->comp( 'ShowMessageHeaders',
58               Message        => $message,
59               DisplayHeaders => \@DisplayHeaders,
60             );
61
62     my $size = $message->ContentLength;
63     if ( $size ) {
64 </%PERL>
65 <div class="downloadattachment">
66 <a href="<% $AttachPath %>/<% $Transaction->Id %>/<% $message->Id %>/<% ($message->Filename ||'')| u%>"><&|/l&>Download</&> <% $message->Filename || loc('(untitled)') %></a>
67 % if ( $DownloadableHeaders && !$message->Filename && $message->ContentType =~ /text/  ) {
68  / <a href="<% $AttachPath %>/WithHeaders/<% $message->Id %>"><% loc('with headers') %></a>
69 % }
70 <br /> 
71 <span class="downloadcontenttype"><% $message->ContentType %> <% $size_to_str->( $size ) %></span>
72 </div>
73 %   }
74
75 %# If there is sub-messages, open a dedicated div
76 % if ( scalar ( grep $_->__Value('Parent') == $message->id, @$Attachments ) ) {
77 <div class="messageattachments">
78 % } else {
79 <div class="messagebody <% RT->Config->Get('PlainTextMono', $session{'CurrentUser'}) ? ' plain-text-white-space' : ''%>">
80 % }
81 <%PERL>
82
83 $render_attachment->( $message );
84
85 $m->comp(
86     $m->current_comp,
87     %ARGS,
88     Parent    => $message->id,
89     ParentObj => $message
90 );
91
92 </%PERL>
93 </div>
94 % }
95 <%ARGS>
96 $Ticket => undef
97 $Transaction => undef
98 $ShowHeaders => 0
99 $Collapsed => undef
100 $DownloadableHeaders => 1
101 $ShowTitleBarCommands => 1
102 $RowNum => 1
103 $AttachPath => RT->Config->Get('WebPath')."/Ticket/Attachment"
104 $UpdatePath => RT->Config->Get('WebPath')."/Ticket/Update.html"
105 $EmailRecordPath => RT->Config->Get('WebPath')."/Ticket/ShowEmailRecord.html"
106 $Attachments => undef
107 $AttachmentContent => {}
108 $ShowBody => 1
109 $Parent => 0
110 $ParentObj => undef
111 $WarnUnsigned => 0
112 </%ARGS>
113 <%INIT>
114 my @DisplayHeaders=qw(_all);
115 if ( $Transaction->Type =~ /EmailRecord$/ ) {
116     @DisplayHeaders = qw(To Cc Bcc);
117 }
118
119 # If the transaction has anything attached to it at all
120 elsif (!$ShowHeaders)  {
121     @DisplayHeaders = qw(To From RT-Send-Cc Cc Bcc Date Subject);
122     push @DisplayHeaders, 'RT-Send-Bcc' if RT->Config->Get('ShowBccHeader');
123 }
124
125 my $size_to_str = sub {
126     my $size = shift;
127     # show a download link
128     if ( $size > 1024*1024 ) {
129         $size = loc( "[_1]b", int( $size / 1024 / 102.4 ) / 10 );
130     }
131     elsif ( $size > 1024 ) {
132         $size = loc( "[_1]k", int( $size / 102.4 ) / 10 );
133     }
134     else {
135         $size = loc( "[_1]b", $size );
136     }
137     return $size;
138 };
139
140 my $render_attachment = sub {
141     my $message = shift;
142
143     # if it has a content-disposition: attachment, don't show inline
144     my $disposition = $message->GetHeader('Content-Disposition');
145     if ( $disposition && $disposition =~ /attachment/i && $disposition !~ /^\s*inline/ ) {
146         $disposition = 'attachemnt';
147     } else {
148         $disposition = 'inline';
149     }
150
151     # If it's text
152     if ( $message->ContentType =~ m{^(text|message)}i ) {
153         my $max_size = RT->Config->Get( 'MaxInlineBody', $session{'CurrentUser'} );
154         if ( $message->Filename && RT->Config->Get('SuppressInlineTextFiles', $session{'CurrentUser'} ) ) {
155             $m->out('<p>'. loc( 'Text file is not shown because it is disabled in preferences.' ) .'</p>');
156             return;
157         }
158         elsif ( $max_size && $message->ContentLength > $max_size ) {
159             $m->out('<p>'. loc( 'Message body not shown because it is too large.' ) .'</p>');
160             return;
161         }
162         elsif ( $disposition ne 'inline' ) {
163             $m->out('<p>'. loc( 'Message body is not shown because sender requested not to inline it.' ) .'</p>');
164             return;
165         }
166
167         if (
168
169             # it's a toplevel object
170             !$ParentObj
171
172             # or its parent isn't a multipart alternative
173             || ( $ParentObj->ContentType !~ m{^multipart/alternative$}i )
174
175             # or it's of our prefered alterative type
176             || (
177                 (
178                     RT->Config->Get('PreferRichText')
179                     && ( $message->ContentType =~ m{^text/(?:html|enriched)$} )
180                 )
181                 || ( !RT->Config->Get('PreferRichText')
182                     && ( $message->ContentType !~ m{^text/(?:html|enriched)$} )
183                 )
184             )
185           )
186         {
187
188             my $content;
189             if ( $AttachmentContent->{ $message->id } ) {
190                 $content = $AttachmentContent->{ $message->id }->Content;
191             }
192             else {
193                 $content = $message->Content;
194             }
195
196             # if it's a text/html clean the body and show it
197             if ( $message->ContentType =~ m{^text/(?:html|enriched)$}i ) {
198                 $content = $m->comp( '/Elements/ScrubHTML', Content => $content );
199                 if ( $message->ContentType eq 'text/html' ) {
200                     $m->comp('/Elements/MakeClicky', 
201                             content => \$content, html => 1,
202                             ticket => $Ticket );
203                 }
204                 $m->out( $content );
205             }
206
207             # if it's a text/plain show the body
208             elsif ( $message->ContentType =~ m{^(text|message)}i ) {
209
210                 eval { require Text::Quoted;  $content = Text::Quoted::extract($content); };
211                 if ($@) { $RT::Logger->warning( "Text::Quoted failed: $@" ) }
212
213                 $m->comp(
214                     'ShowMessageStanza',
215                     Depth       => 0,
216                     Message     => $content,
217                     Transaction => $Transaction
218                 );
219             }
220         }
221     }
222
223     # if it's an image, show it as an image
224     elsif ( RT->Config->Get('ShowTransactionImages') and  $message->ContentType =~ /^image\//i ) {
225         if ( $disposition ne 'inline' ) {
226             $m->out('<p>'. loc( 'Message body is not shown because sender requested not to inline it.' ) .'</p>');
227             return;
228         }
229
230         my $filename =  $message->Filename || loc('(untitled)');
231         $m->out('<img'
232               . ' alt="'
233               . $filename
234               . '"' 
235               . ' title="'
236               . $filename
237               . '"' 
238               . ' src="'
239               . $AttachPath . '/'
240               . $Transaction->Id . '/'
241               . $message->Id
242               . '/" />' );
243     }
244     elsif ( $message->ContentLength > 0 ) {
245         $m->out( '<p>' .
246             loc( 'Message body not shown because it is not plain text.' ) .
247             '</p>'
248         );
249     }
250 };
251
252 </%INIT>