summaryrefslogtreecommitdiffstats
path: root/extensions/TypeSniffer
diff options
context:
space:
mode:
authorByron Jones <bjones@mozilla.com>2013-04-23 09:35:15 +0200
committerByron Jones <bjones@mozilla.com>2013-04-23 09:35:15 +0200
commita2e6439211e3db08bbb2a2cfe1b391b3ff907b47 (patch)
tree75583879c8fdfdd613e6cb54197e4a5ccf58fb82 /extensions/TypeSniffer
parent4fd093696a157b42f797b429d99820d46a0edd0c (diff)
downloadbugzilla-a2e6439211e3db08bbb2a2cfe1b391b3ff907b47.tar.gz
bugzilla-a2e6439211e3db08bbb2a2cfe1b391b3ff907b47.tar.xz
Bug 864200: use text/plain mime type for attachments with a .lang extension
Diffstat (limited to 'extensions/TypeSniffer')
-rw-r--r--extensions/TypeSniffer/Extension.pm28
1 files changed, 26 insertions, 2 deletions
diff --git a/extensions/TypeSniffer/Extension.pm b/extensions/TypeSniffer/Extension.pm
index 78ecdcbef..c593b76e8 100644
--- a/extensions/TypeSniffer/Extension.pm
+++ b/extensions/TypeSniffer/Extension.pm
@@ -26,7 +26,13 @@ use base qw(Bugzilla::Extension);
use File::MimeInfo::Magic;
use IO::Scalar;
-our $VERSION = '0.02';
+our $VERSION = '1';
+
+# These extensions override/supplement File::MimeInfo::Magic's detection.
+our %EXTENSION_OVERRIDES = (
+ '.lang' => 'text/plain',
+);
+
################################################################################
# This extension uses magic to guess MIME types for data where the browser has
# told us it's application/octet-stream (probably because there's no file
@@ -43,6 +49,24 @@ sub attachment_process_data {
$params->{'contenttypemethod'} eq 'autodetect' &&
$attributes->{'mimetype'} eq 'application/octet-stream')
{
+ my $filename = $attributes->{'filename'} . '';
+
+ # Check for an override first
+ if ($filename =~ /^.+(\..+$)/) {
+ my $ext = lc($1);
+ if (exists $EXTENSION_OVERRIDES{$ext}) {
+ $attributes->{'mimetype'} = $EXTENSION_OVERRIDES{$ext};
+ return;
+ }
+ }
+
+ # Then try file extension detection
+ my $mimetype = mimetype($filename);
+ if ($mimetype) {
+ $attributes->{'mimetype'} = $mimetype;
+ return;
+ }
+
# data attribute can be either scalar data or filehandle
# bugzilla.org/docs/3.6/en/html/api/Bugzilla/Attachment.html#create
my $fh = $attributes->{'data'};
@@ -65,7 +89,7 @@ sub attachment_process_data {
}
}
- my $mimetype = mimetype($fh);
+ $mimetype = mimetype($fh);
$fh->seek(0, 0);
if ($mimetype) {
$attributes->{'mimetype'} = $mimetype;