跳到主要內容

OpenWebMail中文檔名附件問題

最近鳥事很多,加上放假都去看車,所以沒有更新Blog。(對,我懶:P)

OpenWebMail自從2.53版後UTF-8做得相當好,但是在IE卻會發生中文檔名附件無法下載;用Big5介面則無此問題,但這樣實在太鳥了,尤其是敝公司有幾位員工名字有unicode字元,這樣就不能正常顯示,決定動手去硬改完全不懂的Openwebmail Perl程式碼。

把openwebmail-viewatt.pl改掉,在269列前,加上
} elsif ( $ENV{'HTTP_USER_AGENT'}=~/MSIE/ or $ENV{'HTTP_USER_AGENT'}=~/Chrome/ ) {
my $filename_encoded = uri_escape($filename);
$attheader.=qq|Content-Disposition: attachment; filename="$filename_encoded"\n|;
最前面也要加上
use URI::Escape;


由於小弟手賤,把所有員工的openwebmailrc都改成utf-8,就不管以上hack在big5是否正常了:P (會變亂碼,但仍然可以下載...)

Update :做成patch file,如下:

--- openwebmail-viewatt.pl 2009-01-06 16:48:24.000000000 +0800
+++ /usr/local/www/cgi-bin/openwebmail/openwebmail-viewatt.pl 2009-01-06 16:14:24.000000000 +0800
@@ -4,6 +4,8 @@
#

use vars qw($SCRIPT_DIR);
+use URI::Escape;
+
if ( $0 =~ m!^(\S*)/[\w\d\-\.]+\.pl! ) { local $1; $SCRIPT_DIR=$1 }
if ($SCRIPT_DIR eq '' && open(F, '/etc/openwebmail_path.conf')) {
$_=; close(F); if ( $_=~/^(\S*)/) { local $1; $SCRIPT_DIR=$1 }
@@ -161,9 +163,13 @@
if ( $ENV{'HTTP_USER_AGENT'}=~/MSIE 5.5/ ) { # ie5.5 is broken with content-disposition: attachment
$attheader.=qq|Content-Disposition: filename="$subject.msg"\n|;
} else {
+# } elsif ( $ENV{'HTTP_USER_AGENT'}=~/MSIE 7.0/ ) { # ie7.0 is broken with content-disposition: attachment
+# $attheader.=qq|Content-Disposition: filename="aaa.msg"\n|;
+# } else {
$attheader.=qq|Content-Disposition: attachment; filename="$subject.msg"\n|;
}

+
# allow cache for msg in folder other than saved-drafts
if ($folder ne 'saved-drafts') {
$attheader.=qq|Expires: |.CGI::expires('+900s').qq|\n|.
@@ -266,6 +272,10 @@
# disposition:attachment default to save
if ( $ENV{'HTTP_USER_AGENT'}=~/MSIE 5.5/ ) { # ie5.5 is broken with content-disposition: attachment
$attheader.=qq|Content-Disposition: filename="$filename"\n|;
+# } else {
+ } elsif ( $ENV{'HTTP_USER_AGENT'}=~/MSIE/ or $ENV{'HTTP_USER_AGENT'}=~/Chrome/ ) { # ie7.0 is broken with utf-8
+ my $filename_encoded = uri_escape($filename);
+ $attheader.=qq|Content-Disposition: attachment; filename="$filename_encoded"\n|;
} else {
$attheader.=qq|Content-Disposition: attachment; filename="$filename"\n|;
}

留言

HAMMER寫道…
謝謝大大

不過您大概打太快了,
語法裏有小小的錯誤。

^_________^
鳥毅寫道…
光仔,我從來都沒學過駱駝文呀!請告訴我該怎麼寫吧...
HAMMER寫道…
大大,請看一下 =.=

} elsif ( $ENV{'HTTP_USER_AGENT'}=~/MSIE/ or $ENV{'HTTP_USER_AGENT'}=~/Chrome/ ) {
my $filename_encoded = uri_escape($filename);
$attheader.=qq|Content-Disposition: attachment; filename="$filename_encoded"\n|;
鳥毅寫道…
感謝光仔,原始的code沒錯,貼上來時不小心把一個 { 刪掉了,至於另一個filename為何會變成filenname我也想不出來,可能是不小心點到吧:P

光仔具有肉眼debug的能力,實在是高手呀!(或者該說人腦compiler呢?)
Unknown寫道…
小弟是用openwebmail3.0beta4 utf8(August 6, 2014 Rev 79bb7cc)但卻發現原本之前版本在chrome附件很正常,更新了這版本卻發現附件下載都變亂碼了,可否懇請大大幫忙修改是不是哪裡出錯了!如果需要我的檔案的話懇請您發個mail讓我把問題的檔案寄給您!拜託了幫個忙一下,小弟對程式實在弱到不行!有看沒有懂!mail是regrcna6@hotmail.com
鳥毅寫道…
li Yung : 我早就沒在用Openwebmail,你還是等pct大大改吧 XD

這個網誌中的熱門文章

自然人憑證讀卡機驅動程式

鳥毅用的是第一代的自然人憑證讀卡機,EZ100PU(後來有同事買EZmini可以讀SIM卡似乎更好),每年報稅時用一次。 本來只是要申請些政府業務,一時之間找不到光碟,沒想到在 驅動程式下載 居然看到Linux和Mac的驅動程式,剩下的就是政府單位的網頁和程式應該改版了吧!!!

DBeaver 介面語言

DBeaver是我個人頗常用的一套跨平台Database管理工具,最近升級後發現Windows版本居然變成簡體中文,而且無法切換為英文。

如何將較高版本SQL Server複製到低版本SQL Server (降級為舊版)並保留權限及資料庫圖表

一般若是要將SQL Server裡的Database轉往其他Server時,最簡單的方式就是備份(Backup)後再還原(Restore),或者是䣃離(detach)後附加(attach)。 但是很不幸地,若是由較低版本(e.g. 2008)到較高版本(e.g. 2012)要怎麼辦呢?