From e17bd11ddb9407d5b8cf2a53df5a9ecf514748d4 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Wed, 9 Mar 2011 17:46:02 +0800 Subject: Bug 633776: Automatic charset detection for text attachments r=mkanat, a=mkanat --- attachment.cgi | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'attachment.cgi') diff --git a/attachment.cgi b/attachment.cgi index 9273b5f29..8ea802f44 100755 --- a/attachment.cgi +++ b/attachment.cgi @@ -53,7 +53,7 @@ use Bugzilla::Attachment::PatchReader; use Bugzilla::Token; use Bugzilla::Keyword; -use Encode qw(encode); +use Encode qw(encode find_encoding); # For most scripts we don't make $cgi and $template global variables. But # when preparing Bugzilla for mod_perl, this script used these @@ -335,6 +335,12 @@ sub view { # In order to prevent Apache from adding a charset, we have to send a # charset that's a single space. $cgi->charset(' '); + if (Bugzilla->feature('detect_charset') && $contenttype =~ /^text\//) { + my $encoding = detect_encoding($attachment->data); + if ($encoding) { + $cgi->charset(find_encoding($encoding)->mime_name); + } + } } print $cgi->header(-type=>"$contenttype; name=\"$filename\"", -content_disposition=> "$disposition; filename=\"$filename\"", -- cgit v1.2.3-24-g4f1b