This commit was generated by cvs2svn to compensate for changes in r10640,
[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
71 % $m->callback(CallbackName => 'AfterDownloadLinks', ARGSRef => \%ARGS, Ticket => $Ticket, Transaction => $Transaction, Attachment => $message);
72
73 <br />
74 <span class="downloadcontenttype"><% $message->ContentType %> <% $size_to_str->( $size ) %></span>
75 </div>
76 %   }
77
78 %# If there is sub-messages, open a dedicated div
79 % if ( scalar ( grep $_->__Value('Parent') == $message->id, @$Attachments ) ) {
80 <div class="messageattachments">
81 % } else {
82 <div class="messagebody">
83 % }
84 <%PERL>
85
86 $render_attachment->( $message );
87
88 $m->comp(
89     $m->current_comp,
90     %ARGS,
91     Parent    => $message->id,
92     ParentObj => $message
93 );
94
95 </%PERL>
96 </div>
97 % }
98 <%ARGS>
99 $Ticket => undef
100 $Transaction => undef
101 $ShowHeaders => 0
102 $Collapsed => undef
103 $DownloadableHeaders => 1
104 $ShowTitleBarCommands => 1
105 $RowNum => 1
106 $AttachPath => RT->Config->Get('WebPath')."/Ticket/Attachment"
107 $UpdatePath => RT->Config->Get('WebPath')."/Ticket/Update.html"
108 $EmailRecordPath => RT->Config->Get('WebPath')."/Ticket/ShowEmailRecord.html"
109 $Attachments => undef
110 $AttachmentContent => {}
111 $ShowBody => 1
112 $Parent => 0
113 $ParentObj => undef
114 $WarnUnsigned => 0
115 </%ARGS>
116 <%INIT>
117 my @DisplayHeaders=qw(_all);
118 if ( $Transaction->Type =~ /EmailRecord$/ ) {
119     @DisplayHeaders = qw(To Cc Bcc);
120 }
121
122 # If the transaction has anything attached to it at all
123 elsif (!$ShowHeaders)  {
124     @DisplayHeaders = qw(To From RT-Send-Cc Cc Bcc Date Subject);
125     push @DisplayHeaders, 'RT-Send-Bcc' if RT->Config->Get('ShowBccHeader');
126 }
127
128 my $size_to_str = sub {
129     my $size = shift;
130     # show a download link
131     if ( $size > 1024*1024 ) {
132         $size = loc( "[_1]b", int( $size / 1024 / 102.4 ) / 10 );
133     }
134     elsif ( $size > 1024 ) {
135         $size = loc( "[_1]k", int( $size / 102.4 ) / 10 );
136     }
137     else {
138         $size = loc( "[_1]b", $size );
139     }
140     return $size;
141 };
142
143 my $render_attachment = sub {
144     my $message = shift;
145
146     # if it has a content-disposition: attachment, don't show inline
147     my $disposition = $message->GetHeader('Content-Disposition');
148     if ( $disposition && $disposition =~ /attachment/i && $disposition !~ /^\s*inline/ ) {
149         $disposition = 'attachemnt';
150     } else {
151         $disposition = 'inline';
152     }
153
154     # If it's text
155     if ( $message->ContentType =~ m{^(text|message)}i ) {
156         my $max_size = RT->Config->Get( 'MaxInlineBody', $session{'CurrentUser'} );
157         if ( $message->Filename && RT->Config->Get('SuppressInlineTextFiles', $session{'CurrentUser'} ) ) {
158             $m->out('<p>'. loc( 'Text file is not shown because it is disabled in preferences.' ) .'</p>');
159             return;
160         }
161         elsif ( $max_size && $message->ContentLength > $max_size ) {
162             $m->out('<p>'. loc( 'Message body not shown because it is too large.' ) .'</p>');
163             return;
164         }
165         elsif ( $disposition ne 'inline' ) {
166             $m->out('<p>'. loc( 'Message body is not shown because sender requested not to inline it.' ) .'</p>');
167             return;
168         }
169
170         if (
171
172             # it's a toplevel object
173             !$ParentObj
174
175             # or its parent isn't a multipart alternative
176             || ( $ParentObj->ContentType !~ m{^multipart/alternative$}i )
177
178             # or it's of our prefered alterative type
179             || (
180                 (
181                     RT->Config->Get('PreferRichText')
182                     && ( $message->ContentType =~ m{^text/(?:html|enriched)$} )
183                 )
184                 || ( !RT->Config->Get('PreferRichText')
185                     && ( $message->ContentType !~ m{^text/(?:html|enriched)$} )
186                 )
187             )
188           )
189         {
190
191             my $content;
192             if ( $AttachmentContent->{ $message->id } ) {
193                 $content = $AttachmentContent->{ $message->id }->Content;
194             }
195             else {
196                 $content = $message->Content;
197             }
198
199             # if it's a text/html clean the body and show it
200             if ( $message->ContentType =~ m{^text/(?:html|enriched)$}i ) {
201                 $content = $m->comp( '/Elements/ScrubHTML', Content => $content );
202                 if ( $message->ContentType eq 'text/html' ) {
203                     $m->comp('/Elements/MakeClicky', 
204                             content => \$content, html => 1,
205                             ticket => $Ticket );
206                 }
207                 $m->out( $content );
208             }
209
210             # if it's a text/plain show the body
211             elsif ( $message->ContentType =~ m{^(text|message)}i ) {
212
213                 #don't want to use this even if it is installed, its
214                 #segfaulting on weird characters and silently truncating the
215                 #ticket history output
216                 #see:
217                 # r44838@pinglin: jesse | 2006-11-14 15:53:18 -0500
218                 # * Move Text::Quoted back to being a run-time require. So that it's possible to turn off the feature if it causes your perl to segfault. (Text::Tabs is...not robust in the face of perl bugs)
219                 #eval { require Text::Quoted;  $content = Text::Quoted::extract($content); };
220                 #if ($@) { $RT::Logger->warning( "Text::Quoted failed: $@" ) }
221
222                 $m->comp(
223                     'ShowMessageStanza',
224                     Depth       => 0,
225                     Message     => $content,
226                     Transaction => $Transaction
227                 );
228             }
229         }
230     }
231
232     # if it's an image, show it as an image
233     elsif ( RT->Config->Get('ShowTransactionImages') and  $message->ContentType =~ /^image\//i ) {
234         if ( $disposition ne 'inline' ) {
235             $m->out('<p>'. loc( 'Message body is not shown because sender requested not to inline it.' ) .'</p>');
236             return;
237         }
238
239         my $filename =  $message->Filename || loc('(untitled)');
240         $m->out('<img'
241               . ' alt="'
242               . $filename
243               . '"' 
244               . ' title="'
245               . $filename
246               . '"' 
247               . ' src="'
248               . $AttachPath . '/'
249               . $Transaction->Id . '/'
250               . $message->Id
251               . '/" />' );
252     }
253     elsif ( $message->ContentLength > 0 ) {
254         $m->out( '<p>' .
255             loc( 'Message body not shown because it is not plain text.' ) .
256             '</p>'
257         );
258     }
259 };
260
261 </%INIT>