1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
6 %# <jesse@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 <span class="downloadcontenttype"><% $message->ContentType %> <% $size_to_str->( $size ) %></span>
75 %# If there is sub-messages, open a dedicated div
76 % if ( scalar ( grep $_->__Value('Parent') == $message->id, @$Attachments ) ) {
77 <div class="messageattachments">
79 <div class="messagebody <% RT->Config->Get('PlainTextMono', $session{'CurrentUser'}) ? ' plain-text-white-space' : ''%>">
83 $render_attachment->( $message );
88 Parent => $message->id,
100 $DownloadableHeaders => 1
101 $ShowTitleBarCommands => 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 => {}
114 my @DisplayHeaders=qw(_all);
115 if ( $Transaction->Type =~ /EmailRecord$/ ) {
116 @DisplayHeaders = qw(To Cc Bcc);
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');
125 my $size_to_str = sub {
127 # show a download link
128 if ( $size > 1024*1024 ) {
129 $size = loc( "[_1]b", int( $size / 1024 / 102.4 ) / 10 );
131 elsif ( $size > 1024 ) {
132 $size = loc( "[_1]k", int( $size / 102.4 ) / 10 );
135 $size = loc( "[_1]b", $size );
140 my $render_attachment = sub {
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';
148 $disposition = 'inline';
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>');
158 elsif ( $max_size && $message->ContentLength > $max_size ) {
159 $m->out('<p>'. loc( 'Message body not shown because it is too large.' ) .'</p>');
162 elsif ( $disposition ne 'inline' ) {
163 $m->out('<p>'. loc( 'Message body is not shown because sender requested not to inline it.' ) .'</p>');
169 # it's a toplevel object
172 # or its parent isn't a multipart alternative
173 || ( $ParentObj->ContentType !~ m{^multipart/alternative$}i )
175 # or it's of our prefered alterative type
178 RT->Config->Get('PreferRichText')
179 && ( $message->ContentType =~ m{^text/(?:html|enriched)$} )
181 || ( !RT->Config->Get('PreferRichText')
182 && ( $message->ContentType !~ m{^text/(?:html|enriched)$} )
189 if ( $AttachmentContent->{ $message->id } ) {
190 $content = $AttachmentContent->{ $message->id }->Content;
193 $content = $message->Content;
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,
207 # if it's a text/plain show the body
208 elsif ( $message->ContentType =~ m{^(text|message)}i ) {
210 eval { require Text::Quoted; $content = Text::Quoted::extract($content); };
211 if ($@) { $RT::Logger->warning( "Text::Quoted failed: $@" ) }
217 Transaction => $Transaction
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>');
230 my $filename = $message->Filename || loc('(untitled)');
240 . $Transaction->Id . '/'
244 elsif ( $message->ContentLength > 0 ) {
246 loc( 'Message body not shown because it is not plain text.' ) .