Encode FileName when download in Internet Explorer

Locked
ULiX
Znuny newbie
Posts: 16
Joined: 07 Jul 2010, 23:04
Znuny Version: 2.4.7

Encode FileName when download in Internet Explorer

Post by ULiX »

When download files, in name which contains symbols of the cyrillics, in InternetExplorer simbols in name on save file are displayed wrong.
OTRS use encode UTF-8 in FileName but in IE this encode causes problems.
In OTRS version 2.4.7 this problem tried to solve but not definitively.

Problems of the decoding the filenames remained in package Filemanager and FAQ.
This packages used function Attachment in module Kernel::Output::HTML::Layout

In OTRS version 2.4.7 in this function added changes for decode filename attachment in some OTRS (exclude filename from header and include in url) but other package not support.
I offer more universal patch.
I used the object EncodeObject ($Self->{EncodeObject}) for forced decoding the filename in coding windows-1251.
Decoding is produced if it is used IE only.

diff:

Code: Select all

--- /opt/Paths/ORIGIN/Layout.pm 2010-02-06 09:42:17.000000000 +1000
+++ /opt/otrs/Kernel/Output/HTML/Layout.pm      2010-07-07 17:04:53.000000000 +1100
@@ -3160,6 +3160,7 @@
     }
 
     # clean filename to get no problems with some browsers
+    my $ConvertName = "BagFileNameDecode";
     if ( $Param{Filename} ) {
 
         # detect if IE workaround is used (solution for IE problem with multi byte filename)
@@ -3178,7 +3179,18 @@
 
         # only deliver filename if needed
         if ($FilenameInHeader) {
-            $Output .= " filename=\"$Param{Filename}\"";
+            if ( $Self->{BrowserBreakDispositionHeader} ) {
+               $ConvertName = $Self->{EncodeObject}->Convert(
+                   Text => $Param{Filename},
+                   From => 'utf-8',
+                   To   => 'windows-1251',
+                   Force => 1,
+               );
+               $Output .= " filename=\"<OTRS_FILE_NAME>\"";
+            }
+            else {
+                $Output .= " filename=\"$Param{Filename}\"";
+            }
         }
     }
     $Output .= "\n";
@@ -3207,6 +3219,9 @@
 
     # disable utf8 flag, to write binary to output
     $Self->{EncodeObject}->EncodeOutput( \$Output );
+    if ( $Self->{BrowserBreakDispositionHeader} ) {
+        $Output =~ s/<OTRS_FILE_NAME>/$ConvertName/gi;
+    }
     $Self->{EncodeObject}->EncodeOutput( \$Param{Content} );
 
     # fix for firefox HEAD problem
When use given mechanism possible to abandon to acting and exclude check url

Code: Select all

    # clean filename to get no problems with some browsers
    my $ConvertName = "BagFileNameDecode";
    if ( $Param{Filename} ) {

        # detect if IE workaround is used (solution for IE problem with multi byte filename)
        # to solve this kind of problems use the following in dtl for attachment downloads:
        # <a href="$Env{"CGIHandle"}/$LQData{"Filename"}?Action=...">xxx</a>
        my $FilenameInHeader = 1;

        # check if browser is broken
#        if ( $Self->{BrowserBreakDispositionHeader} && $ENV{REQUEST_URI} ) {

            # check if IE workaround is used
#            if ( $ENV{REQUEST_URI} =~ /\Q$Self->{CGIHandle}\E\/.+?\?Action=/ ) {
#                $FilenameInHeader = 0;
#            }
#        }

        # only deliver filename if needed
#        if ($FilenameInHeader) {
            if ( $Self->{BrowserBreakDispositionHeader} ) {
                $ConvertName = $Self->{EncodeObject}->Convert(
                    Text => $Param{Filename},
                    From => 'utf-8',
                    To   => 'windows-1251',
                    Force => 1,
                );
                $Output .= " filename=\"<OTRS_FILE_NAME>\"";
            }
            else {
                $Output .= " filename=\"$Param{Filename}\"";
            }
#        }
    }
    $Output .= "\n";
Delete all spare and shall get clean code

Code: Select all

    # clean filename to get no problems with some browsers
    my $ConvertName = "BagFileNameDecode";
    if ( $Param{Filename} ) {
        # check if browser is broken
        if ( $Self->{BrowserBreakDispositionHeader} ) {
            $ConvertName = $Self->{EncodeObject}->Convert(
                Text => $Param{Filename},
                From => 'utf-8',
                To   => 'windows-1251',
                Force => 1,
            );
            $Output .= " filename=\"<OTRS_FILE_NAME>\"";
        }
        else {
            $Output .= " filename=\"$Param{Filename}\"";
        }
    }
    $Output .= "\n";
And not forgot change tag on convert name

Code: Select all

    # disable utf8 flag, to write binary to output
    $Self->{EncodeObject}->EncodeOutput( \$Output );
    if ( $Self->{BrowserBreakDispositionHeader} ) {
        $Output =~ s/<OTRS_FILE_NAME>/$ConvertName/gi;
    }
    $Self->{EncodeObject}->EncodeOutput( \$Param{Content} );
I hope this patch include in new release.
I have tired patched after each upgrade OTRS.

Der patch arbaiten good!
You do not have the required permissions to view the files attached to this post.
Locked