import of rt 3.0.9
[freeside.git] / rt / html / Ticket / Attachment / dhandler
1 %# BEGIN LICENSE BLOCK
2 %# 
3 %# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
4 %# 
5 %# (Except where explictly superceded by other copyright notices)
6 %# 
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
10 %# from www.gnu.org.
11 %# 
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.
16 %# 
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.
21 %# 
22 %# 
23 %# END LICENSE BLOCK
24 <%perl>
25      my ($ticket, $trans,$attach, $filename);
26      my $arg = $m->dhandler_arg;                # get rest of path
27      if ($arg =~ '^(\d+)/(\d+)') {
28         $trans = $1;
29         $attach = $2;
30      }
31     else {
32         Abort("Corrupted attachment URL.");
33         }
34      my $AttachmentObj = new RT::Attachment($session{'CurrentUser'});
35      $AttachmentObj->Load($attach) || Abort("Attachment '$attach' could not be loaded");
36
37
38      unless ($AttachmentObj->id) {
39         Abort("Bad attachment id. Couldn't find attachment '$attach'\n");
40     }
41      unless ($AttachmentObj->TransactionId() == $trans ) {
42         Abort("Bad transaction number for attachment. $trans should be".$AttachmentObj->TransactionId() ."\n");
43
44      }
45
46      my $content_type = $AttachmentObj->ContentType || 'text/plain';
47         
48      unless ($RT::TrustHTMLAttachments) {
49          $content_type = 'text/plain' if ($content_type =~ /^text\/html/i);
50      }
51
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";
57      }
58
59      # unless ($RT::TrustMIMEAttachments) {
60      #     $content_type = 'application/octet-stream';
61      # }
62
63      $r->content_type( $content_type );
64      $m->clear_buffer();
65      $m->out($AttachmentObj->OriginalContent);
66      $m->abort; 
67 </%perl>
68 <%attr>
69 AutoFlush => 0
70 </%attr>