%#
%# COPYRIGHT:
%#
-%# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC
%# <sales@bestpractical.com>
%#
%# (Except where explicitly superseded by other copyright notices)
</%ARGS>
<%INIT>
use MIME::Entity;
-use LWP::MediaTypes;
use RT::Interface::REST;
-use File::Temp qw(tempfile);
-my @tmp_files;
$RT::Logger->debug("Got ticket id=$id for comment");
$RT::Logger->debug("Got args @{[keys(%changes)]}.");
goto OUTPUT;
}
-my $cgi = $m->cgi_object;
my $ent = MIME::Entity->build(
Type => "multipart/mixed",
'X-RT-Interface' => 'REST',
);
-$ent->attach(Data => $changes{Text}) if $changes{Text};
+$ent->attach(
+ Type => $changes{'Content-Type'} || 'text/plain',
+ Charset => "UTF-8",
+ Data => Encode::encode("UTF-8", $changes{Text} ),
+) if $changes{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();
- my $info = $cgi->uploadInfo($fh);
- push @tmp_files, $tmp;
-
- 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 ($status, $msg) = process_attachments($ent, @atts);
+ unless ( $status ) {
$e = 1;
- $c = "# No attachment for $att.";
+ $c = "# $msg";
goto OUTPUT;
}
-
- $i++;
}
unless ($ticket->CurrentUserHasRight('ModifyTicket') ||
OUTPUT:
-unlink @tmp_files;
return [ $c, $o, $k, $e ];
</%INIT>