3 %# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
5 %# (Except where explictly superceded by other copyright notices)
7 %# This work is made available to you under the terms of Version 2 of
8 %# the GNU General Public License. A copy of that license should have
9 %# been provided with this software, but in any event can be snarfed
12 %# This work is distributed in the hope that it will be useful, but
13 %# WITHOUT ANY WARRANTY; without even the implied warranty of
14 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 %# General Public License for more details.
17 %# Unless otherwise specified, all modifications, corrections or
18 %# extensions to this work which alter its source code become the
19 %# property of Best Practical Solutions, LLC when submitted for
20 %# inclusion in the work.
25 my ($ticket, $trans,$attach, $filename);
26 my $arg = $m->dhandler_arg; # get rest of path
27 if ($arg =~ '^(\d+)/(\d+)') {
32 Abort("Corrupted attachment URL.");
34 my $AttachmentObj = new RT::Attachment($session{'CurrentUser'});
35 $AttachmentObj->Load($attach) || Abort("Attachment '$attach' could not be loaded");
38 unless ($AttachmentObj->id) {
39 Abort("Bad attachment id. Couldn't find attachment '$attach'\n");
41 unless ($AttachmentObj->TransactionId() == $trans ) {
42 Abort("Bad transaction number for attachment. $trans should be".$AttachmentObj->TransactionId() ."\n");
46 my $content_type = $AttachmentObj->ContentType || 'text/plain';
48 unless ($RT::TrustHTMLAttachments) {
49 $content_type = 'text/plain' if ($content_type =~ /^text\/html/i);
52 if (my $enc = $AttachmentObj->OriginalEncoding) {
53 # normalize Encode.pm convention with IANA ones
54 $enc = 'big5' if $enc eq 'big5-eten';
55 $enc = 'utf-8' if $enc eq 'utf8';
56 $content_type .= ";charset=$enc";
59 # unless ($RT::TrustMIMEAttachments) {
60 # $content_type = 'application/octet-stream';
63 $r->content_type( $content_type );
65 $m->out($AttachmentObj->OriginalContent);