1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
6 %# <sales@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
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
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.
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.
30 %# CONTRIBUTION SUBMISSION POLICY:
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.)
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.
47 %# END BPS TAGGED BLOCK }}}
49 # Find all the attachments which have parent $Parent
50 # For each of these attachments
51 foreach my $message ( grep $_->__Value('Parent') == $Parent, @$Attachments ) {
53 if (RT->Config->Get('GnuPG')->{'Enable'}) {
54 $m->comp( 'ShowGnuPGStatus', Attachment => $message, WarnUnsigned => $WarnUnsigned );
57 $m->comp( 'ShowMessageHeaders',
59 DisplayHeaders => \@DisplayHeaders,
62 my $size = $message->ContentLength;
63 my $name = defined $message->Filename && length $message->Filename ? $message->Filename : '';
66 <div class="downloadattachment">
67 <a href="<% $AttachPath %>/<% $Transaction->Id %>/<% $message->Id %>/<% $name | u%>"><&|/l&>Download</&> <% length $name ? $name : loc('(untitled)') %></a>\
68 % if ( $DownloadableHeaders && ! length $name && $message->ContentType =~ /text/ ) {
69 / <a href="<% $AttachPath %>/WithHeaders/<% $message->Id %>"><% loc('with headers') %></a>
71 % $m->callback(CallbackName => 'AfterDownloadLinks', ARGSRef => \%ARGS, Ticket => $Ticket, Transaction => $Transaction, Attachment => $message);
73 <span class="downloadcontenttype"><% $message->ContentType %> <% $size_to_str->( $size ) %></span>
76 %# If there is sub-messages, open a dedicated div
77 % if ( scalar ( grep $_->__Value('Parent') == $message->id, @$Attachments ) ) {
78 <div class="messageattachments">
80 <div class="messagebody">
84 $render_attachment->( $message );
89 Parent => $message->id,
101 $DownloadableHeaders => 1
102 $ShowTitleBarCommands => 1
104 $AttachPath => RT->Config->Get('WebPath')."/Ticket/Attachment"
105 $UpdatePath => RT->Config->Get('WebPath')."/Ticket/Update.html"
106 $EmailRecordPath => RT->Config->Get('WebPath')."/Ticket/ShowEmailRecord.html"
107 $Attachments => undef
108 $AttachmentContent => {}
115 my @DisplayHeaders=qw(_all);
116 if ( $Transaction->Type =~ /EmailRecord$/ ) {
117 @DisplayHeaders = qw(To Cc Bcc);
120 # If the transaction has anything attached to it at all
121 elsif (!$ShowHeaders) {
122 @DisplayHeaders = qw(To From RT-Send-Cc Cc Bcc Date Subject);
123 push @DisplayHeaders, 'RT-Send-Bcc' if RT->Config->Get('ShowBccHeader');
126 $m->callback(CallbackName => 'MassageDisplayHeaders', DisplayHeaders => \@DisplayHeaders, Transaction => $Transaction);
128 my $size_to_str = sub {
130 # show a download link
131 if ( $size > 1024*1024 ) {
132 $size = loc( "[_1]m", int( $size / 1024 / 102.4 ) / 10 );
134 elsif ( $size > 1024 ) {
135 $size = loc( "[_1]k", int( $size / 102.4 ) / 10 );
138 $size = loc( "[_1]b", $size );
143 my $render_attachment = sub {
145 my $name = defined $message->Filename && length $message->Filename ? $message->Filename : '';
147 my $content_type = lc $message->ContentType;
149 # if it has a content-disposition: attachment, don't show inline
150 my $disposition = $message->GetHeader('Content-Disposition');
152 if ( $disposition && $disposition =~ /^\s*attachment/i ) {
153 $disposition = 'attachment';
155 $disposition = 'inline';
159 if ( $content_type =~ m{^(text|message)/} ) {
160 my $max_size = RT->Config->Get( 'MaxInlineBody', $session{'CurrentUser'} );
161 if ( $disposition ne 'inline' ) {
162 $m->out('<p>'. loc( 'Message body is not shown because sender requested not to inline it.' ) .'</p>');
165 elsif ( length $name && RT->Config->Get('SuppressInlineTextFiles', $session{'CurrentUser'} ) ) {
166 $m->out('<p>'. loc( 'Text file is not shown because it is disabled in preferences.' ) .'</p>');
169 elsif ( $max_size && $message->ContentLength > $max_size ) {
170 $m->out('<p>'. loc( 'Message body is not shown because it is too large.' ) .'</p>');
176 # it's a toplevel object
179 # or its parent isn't a multipart alternative
180 || ( $ParentObj->ContentType !~ m{^multipart/(?:alternative|related)$}i )
182 # or it's of our prefered alterative type
185 RT->Config->Get('PreferRichText')
186 && ( $content_type =~ m{^text/(?:html|enriched)$} )
188 || ( !RT->Config->Get('PreferRichText')
189 && ( $content_type !~ m{^text/(?:html|enriched)$} )
195 # If we've cached the content, use it from there
196 if (my $x = $AttachmentContent->{ $Transaction->id }->{$message->id}) {
197 $content = $x->Content;
200 $content = $message->Content;
204 "Rendering attachment #". $message->id
205 ." of '$content_type' type"
208 # if it's a text/html clean the body and show it
209 if ( $content_type eq 'text/html' ) {
210 $content = $m->comp( '/Elements/ScrubHTML', Content => $content );
213 '/Elements/MakeClicky',
214 content => \$content,
219 require HTML::Quoted;
220 $content = HTML::Quoted->extract($content) unless length $name;
225 Transaction => $Transaction,
226 ContentType => 'text/html',
230 elsif ( $content_type eq 'text/enriched' ) {
231 $content = $m->comp( '/Elements/ScrubHTML', Content => $content );
235 # It's a text type we don't have special handling for
237 unless ( length $name ) {
238 eval { require Text::Quoted; $content = Text::Quoted::extract($content); };
239 if ($@) { $RT::Logger->warning( "Text::Quoted failed: $@" ) }
245 Transaction => $Transaction,
246 ContentType => 'text/plain',
252 # if it's an image, show it as an image
253 elsif ( RT->Config->Get('ShowTransactionImages') and $content_type =~ m{^image/} ) {
254 if ( $disposition ne 'inline' ) {
255 $m->out('<p>'. loc( 'Message body is not shown because sender requested not to inline it.' ) .'</p>');
259 my $filename = length $name ? $name : loc('(untitled)');
269 . $Transaction->Id . '/'
273 elsif ( $message->ContentLength && $message->ContentLength > 0 ) {
275 loc( 'Message body not shown because it is not plain text.' ) .