rt 4.2.14 (#13852)
[freeside.git] / rt / share / html / REST / 1.0 / ticket / comment
index 475e3a8..65cad21 100755 (executable)
@@ -2,7 +2,7 @@
 %#
 %# COPYRIGHT:
 %#
-%# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2017 Best Practical Solutions, LLC
 %#                                          <sales@bestpractical.com>
 %#
 %# (Except where explicitly superseded by other copyright notices)
@@ -52,10 +52,7 @@ $content
 </%ARGS>
 <%INIT>
 use MIME::Entity;
-use LWP::MediaTypes;
 use RT::Interface::REST;
-use File::Temp qw(tempfile);
-my @tmp_files;
 
 my $ticket = RT::Ticket->new($session{CurrentUser});
 my $object = $r->path_info;
@@ -111,39 +108,19 @@ my $ent = MIME::Entity->build(
     Type => "multipart/mixed",
     'X-RT-Interface' => 'REST',
 );
-$ent->attach(Data => $k->{Text}) if $k->{Text};
+$ent->attach(
+    Type    => "text/plain",
+    Charset => "UTF-8",
+    Data    => Encode::encode( "UTF-8", $k->{Text} ),
+) if $k->{Text};
 
-my $i = 1;
-foreach my $att (@atts) {
-    local $/=undef;
-    my $file = $att;
-    $file =~ s#^.*[\\/]##;
-
-    my $fh = $cgi->upload("attachment_$i");
-    if ($fh) {
-        my $buf;
-        my ($w, $tmp) = tempfile();
-        push @tmp_files, $tmp;
-        my $info = $cgi->uploadInfo();
-
-        while (sysread($fh, $buf, 8192)) {
-            syswrite($w, $buf);
-        }
-
-        $ent->attach(
-            Path => $tmp,
-            Type => $info->{'Content-Type'} || guess_media_type($tmp),
-            Filename => $file,
-            Disposition => "attachment"
-        );
-    }
-    else {
+{
+    my ($res, $msg) = process_attachments($ent, @atts);
+    unless ( $res ) {
         $status = "400 Bad Request";
-        $output = "No attachment for $att.\n";
+        $output = "$msg\n";
         goto OUTPUT;
     }
-
-    $i++;
 }
 
 $ticket->Load($object);
@@ -177,7 +154,6 @@ if ($k->{Status}) {
 
 OUTPUT:
 
-unlink @tmp_files;
 </%INIT>
 RT/<% $RT::VERSION %> <% $status %>