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.
24 %# REST/1.0/Forms/ticket/attachments
32 my ($c, $o, $k, $e) = ("", [], {}, "");
33 my $ticket = new RT::Ticket $session{CurrentUser};
36 unless ($ticket->Id) {
37 return [ "# Ticket $id does not exist.", [], {}, 1 ];
40 my @arglist = split('/', $args);
43 if ($arglist[1] eq 'content') {
52 unless ($aid =~ /^\d+$/) {
53 return [ "# Invalid attachment id: $aid", [], {}, 1 ];
55 my $attachment = new RT::Attachment $session{CurrentUser};
56 $attachment->Load($aid);
57 unless ($attachment->Id eq $aid) {
58 return [ "# Invalid attachment id: $aid", [], {}, 1 ];
61 $c = $attachment->Content;
64 push @data, [ id => $attachment->Id ];
65 push @data, [ Subject => $attachment->Subject ];
66 push @data, [ Creator => $attachment->Creator ];
67 push @data, [ Created => $attachment->Created ];
68 push @data, [ Transaction => $attachment->TransactionId ];
69 push @data, [ Parent => $attachment->Parent ];
70 push @data, [ MessageId => $attachment->MessageId ];
71 push @data, [ Filename => $attachment->Filename ];
72 push @data, [ ContentType => $attachment->ContentType ];
73 push @data, [ ContentEncoding => $attachment->ContentEncoding ];
74 push @data, [ Headers => $attachment->Headers ];
75 push @data, [ Content => $attachment->Content ];
77 my %k = map {@$_} @data;
78 $o = [ map {$_->[0]} @data ];
85 my $transactions = $ticket->Transactions;
86 while (my $t = $transactions->Next) {
87 my $attachments = $t->Attachments;
88 while (my $a = $attachments->Next) {
89 next unless $a->Filename;
90 my $size = length($a->Content);
91 if ($size > 1024) { $size = int($size/102.4)/10 . "k" }
93 push @attachments, $a->Id.": ".$a->Filename." (".$size.")";
98 $o = [ "id", "Attachments" ];
100 id => "ticket/".$ticket->Id."/attachments",
101 Attachments => \@attachments
106 return [ $c, $o, $k, $e ];