Support for CGI::Simple in RT 3.8.1

I’m currently using FCGI::Engine to provide the RT backend for my new
installation (not live yet). It uses CGI::Simple as its CGI object.
This hasn’t caused any problems thus far but I noticed today that
attachments were not working. Turns out there are subtle differences in
how to deal with uploads.

Attached is a patch to lib/RT/Interface/Web.pm which adds the variations
if it detects that the CGI object is one from CGI::Simple.

It’s only had very basic testing - i.e. I haven’t tried it in a normal
CGI environment to ensure nothing broke. But it’s a relatively simple
patch so should prove no trouble.

Olly

Index: lib/RT/Interface/Web.pm
— lib/RT/Interface/Web.pm (revision 6360)
+++ lib/RT/Interface/Web.pm (working copy)
@@ -765,26 +765,31 @@
if ( $args{‘AttachmentFieldName’} ) {

     my $cgi_object = $m->cgi_object;
  •    my ($filehandle, $filename, $mimetype);
    
  •    if ( my $filehandle = $cgi_object->upload(
    

$args{‘AttachmentFieldName’} ) ) {

  •    if (ref($cgi_object) eq 'CGI::Simple') {
    
  •       $filename =
    

$cgi_object->param($args{‘AttachmentFieldName’});

  •        $filehandle = $cgi_object->upload($filename);
    
  •        $mimetype = $cgi_object->upload_info($filename, 'mime');
    
  •    } else {
    
  •        $filehandle =
    

$cgi_object->upload($args{‘AttachmentFieldName’});

  •        $mimetype =
    

$cgi_object->uploadInfo($filehandle)->{‘Content-Type’};

  •        # Prefer the cached name first over CGI.pm stringification.
    
  •        $filename = $RT::Mason::CGI::Filename;
    
  •        $filename = "$filehandle" unless defined($filename);
    
  •    }
    
  •    if ( $filehandle ) {
           my (@content,$buffer);
           while ( my $bytesread = read( $filehandle, $buffer, 4096 )
    

) {
push @content, $buffer;
}

  •        my $uploadinfo = $cgi_object->uploadInfo($filehandle);
    
  •        # Prefer the cached name first over CGI.pm stringification.
    
  •        my $filename = $RT::Mason::CGI::Filename;
    
  •        $filename = "$filehandle" unless defined($filename);
           $filename =~ s#^.*[\\/]##;
    
           $Message->attach(
    
  •            Type     => $uploadinfo->{'Content-Type'},
    
  •            Type     => $mimetype,
               Filename => Encode::decode_utf8($filename),
               Data     => \@content,
           );
    

@@ -1491,17 +1496,26 @@
sub _UploadedFile {
my $arg = shift;
my $cgi_object = $m->cgi_object;

  • my $fh = $cgi_object->upload($arg) or return undef;
  • my $upload_info = $cgi_object->uploadInfo($fh);
  • my ($fh, $filename, $mimetype);
  • my $filename = “$fh”;
  • if (ref($cgi_object) eq ‘CGI::Simple’) {

  •    $filename = $cgi_object->param($arg);
    
  •    $fh = $cgi_object->upload($filename) or return undef;
    
  •    $mimetype = $cgi_object->upload_info($filename, 'mime');
    
  • }

  • else {

  •    $fh = $cgi_object->upload($arg) or return undef;
    
  •    $mimetype = $cgi_object->uploadInfo($fh)->{'Content-Type'};
    
  •    $filename = "$fh";
    
  • }
    $filename =~ s#^.*[\/]##;
    binmode($fh);

    return {
    Value => $filename,
    LargeContent => do { local $/; scalar <$fh> },

  •    ContentType => $upload_info->{'Content-Type'},
    
  •    ContentType => $mimetype,
    
    };
    }

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

rt-cgi-simple-patch.txt (2.74 KB)