X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FRequest.pm;h=3b8262f2c26500adc3b29d66d993ef92b9fea83f;hb=8de8e5398d67e7afdcf42951f020b813128aea73;hp=dab57457a062080ae32fa6302c9841e4a3b2c674;hpb=40d21a2dbba64bb087ff7bd2781ed1a0707add1c;p=kivitendo-erp.git diff --git a/SL/Request.pm b/SL/Request.pm index dab57457a..3b8262f2c 100644 --- a/SL/Request.pm +++ b/SL/Request.pm @@ -51,7 +51,7 @@ sub _input_to_hash { sub _parse_multipart_formdata { my ($target, $temp_target, $input) = @_; - my ($name, $filename, $headers_done, $content_type, $boundary_found, $need_cr, $previous, $encoding, $transfer_encoding); + my ($name, $filename, $headers_done, $content_type, $boundary_found, $need_cr, $previous, $p_attachment, $encoding, $transfer_encoding); # We SHOULD honor encodings and transfer-encodings here, but as hard as I # looked I couldn't find a reasonably recent webbrowser that makes use of @@ -103,14 +103,38 @@ sub _parse_multipart_formdata { substr $line, $-[0], $+[0] - $-[0], ""; } - $previous = _store_value($filename ? $target : $temp_target, $name, '') if ($name); - $temp_target->{FILENAME} = $filename if ($filename); + if ($name) { + # legacy, some old upload routines expect this to be here + $temp_target->{FILENAME} = $filename if defined $filename; + + # name can potentially be both a normal variable or a file upload + # a file upload can be identified by its "filename" attribute + # the thing is, if a [+] clause vivifies atructur in one of the + # branches it must be done in both, or subsequent "[]" will fail + my $temp_target_slot = _store_value($temp_target, $name); + my $target_slot = _store_value($target, $name); + + # set the reference for appending of multiline data to the correct one + $previous = defined $filename ? $target_slot : $temp_target_slot; + + # for multiple uploads: save the attachments in a SL/Mailer like structure + if (defined $filename) { + my $target_attachment = _store_value($target, "ATTACHMENTS.$name", {}); + my $temp_target_attachment = _store_value($temp_target, "ATTACHMENTS.$name", {}); + + $$target_attachment->{data} = $previous; + $$temp_target_attachment->{filename} = $filename; + + $p_attachment = $$temp_target_attachment; + } + } next; } if ($line =~ m|^content-type\s*:\s*(.*?)[;\$]|i) { $content_type = $1; + $p_attachment->{content_type} = $1; if ($content_type =~ /^text/ && $line =~ m|;\s*charset\s*:\s*("?)(.*?)\1$|i) { $encoding = $2; @@ -124,6 +148,7 @@ sub _parse_multipart_formdata { if ($transfer_encoding && $transfer_encoding !~ /^[78]bit|binary$/) { die 'Transfer encodings beyond 7bit/8bit and binary are not implemented.'; } + $p_attachment->{transfer_encoding} = $transfer_encoding; next; } @@ -151,7 +176,7 @@ sub _recode_recursively { # Workaround for a bug: converting $from->{$key} directly # leads to 'undef'. I don't know why. Converting a copy works, # though. - $to->{$key} = $iconv->convert("" . $from->{$key}); + $to->{$key} = $iconv->convert("" . $from->{$key}) if defined $from->{$key} && !defined $to->{$key}; } else { $to->{$key} ||= {} if 'HASH' eq ref $from->{$key}; $to->{$key} ||= [] if 'ARRAY' eq ref $from->{$key};