diff options
author | Byron Jones <bjones@mozilla.com> | 2011-03-09 17:46:02 +0800 |
---|---|---|
committer | Byron Jones <bjones@mozilla.com> | 2011-03-09 17:46:02 +0800 |
commit | e17bd11ddb9407d5b8cf2a53df5a9ecf514748d4 (patch) | |
tree | 0c50e3fbaa6db66c20d6e54101af5f9a5aecb013 /attachment.cgi | |
parent | Bug 634310: Remove WCAG 2.0 violations from the index.cgi to make it (diff) | |
download | bugzilla-e17bd11ddb9407d5b8cf2a53df5a9ecf514748d4.tar.gz bugzilla-e17bd11ddb9407d5b8cf2a53df5a9ecf514748d4.tar.bz2 bugzilla-e17bd11ddb9407d5b8cf2a53df5a9ecf514748d4.zip |
Bug 633776: Automatic charset detection for text attachments
r=mkanat, a=mkanat
Diffstat (limited to 'attachment.cgi')
-rwxr-xr-x | attachment.cgi | 8 |
1 files changed, 7 insertions, 1 deletions
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\"", |