1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2011 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;
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>
71 % $m->callback(CallbackName => 'AfterDownloadLinks', ARGSRef => \%ARGS, Ticket => $Ticket, Transaction => $Transaction, Attachment => $message);
74 <span class="downloadcontenttype"><% $message->ContentType %> <% $size_to_str->( $size ) %></span>
78 %# If there is sub-messages, open a dedicated div
79 % if ( scalar ( grep $_->__Value('Parent') == $message->id, @$Attachments ) ) {
80 <div class="messageattachments">
82 <div class="messagebody">
86 $render_attachment->( $message );
91 Parent => $message->id,
100 $Transaction => undef
103 $DownloadableHeaders => 1
104 $ShowTitleBarCommands => 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 => {}
117 my @DisplayHeaders=qw(_all);
118 if ( $Transaction->Type =~ /EmailRecord$/ ) {
119 @DisplayHeaders = qw(To Cc Bcc);
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');
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 {
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';
151 $disposition = 'inline';
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>');
161 elsif ( $max_size && $message->ContentLength > $max_size ) {
162 $m->out('<p>'. loc( 'Message body not shown because it is too large.' ) .'</p>');
165 elsif ( $disposition ne 'inline' ) {
166 $m->out('<p>'. loc( 'Message body is not shown because sender requested not to inline it.' ) .'</p>');
172 # it's a toplevel object
175 # or its parent isn't a multipart alternative
176 || ( $ParentObj->ContentType !~ m{^multipart/alternative$}i )
178 # or it's of our prefered alterative type
181 RT->Config->Get('PreferRichText')
182 && ( $message->ContentType =~ m{^text/(?:html|enriched)$} )
184 || ( !RT->Config->Get('PreferRichText')
185 && ( $message->ContentType !~ m{^text/(?:html|enriched)$} )
192 if ( $AttachmentContent->{ $message->id } ) {
193 $content = $AttachmentContent->{ $message->id }->Content;
196 $content = $message->Content;
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,
210 # if it's a text/plain show the body
211 elsif ( $message->ContentType =~ m{^(text|message)}i ) {
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
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: $@" ) }
226 Transaction => $Transaction
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>');
239 my $filename = $message->Filename || loc('(untitled)');
249 . $Transaction->Id . '/'
253 elsif ( $message->ContentLength && $message->ContentLength > 0 ) {
255 loc( 'Message body not shown because it is not plain text.' ) .