diff options
author | thomascube <thomas@roundcube.net> | 2009-02-27 10:18:18 +0000 |
---|---|---|
committer | thomascube <thomas@roundcube.net> | 2009-02-27 10:18:18 +0000 |
commit | 0ea569c29f9bdab35ccb429733279db730cd6abd (patch) | |
tree | 56fc044fca704ebc5cbdf58dae57aa48b88025c8 /program/include | |
parent | d68678ee256cbeba8e492f23a2c793cbde18dd90 (diff) |
Fix mime-type detection using a hard-coded map (#1485311)
Diffstat (limited to 'program/include')
-rw-r--r-- | program/include/rcube_shared.inc | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/program/include/rcube_shared.inc b/program/include/rcube_shared.inc index 74bfdbafe..f1cbb19c3 100644 --- a/program/include/rcube_shared.inc +++ b/program/include/rcube_shared.inc @@ -535,6 +535,7 @@ function get_offset_time($offset_str, $factor=1) * A method to guess the mime_type of an attachment. * * @param string $path Path to the file. + * @param string $name File name (with suffix) * @param string $failover Mime type supplied for failover. * * @return string @@ -542,25 +543,34 @@ function get_offset_time($offset_str, $factor=1) * @see http://de2.php.net/manual/en/ref.fileinfo.php * @see http://de2.php.net/mime_content_type */ -function rc_mime_content_type($path, $failover = 'application/octet-stream') +function rc_mime_content_type($path, $name, $failover = 'application/octet-stream') { $mime_type = null; $mime_magic = rcmail::get_instance()->config->get('mime_magic'); + $mime_ext = @include(RCMAIL_CONFIG_DIR . '/mimetypes.php'); + $suffix = $name ? substr($name, strrpos($name, '.')+1) : '*'; - if (!extension_loaded('fileinfo')) { - @dl('fileinfo.' . PHP_SHLIB_SUFFIX); + // use file name suffix with hard-coded mime-type map + if (is_array($mime_ext)) { + $mime_type = $mime_ext[$suffix]; } - - if (function_exists('finfo_open')) { - if ($finfo = finfo_open(FILEINFO_MIME, $mime_magic)) { - $mime_type = finfo_file($finfo, $path); - finfo_close($finfo); + // try fileinfo extension if available + if (!$mime_type) { + if (!extension_loaded('fileinfo')) { + @dl('fileinfo.' . PHP_SHLIB_SUFFIX); + } + if (function_exists('finfo_open')) { + if ($finfo = finfo_open(FILEINFO_MIME, $mime_magic)) { + $mime_type = finfo_file($finfo, $path); + finfo_close($finfo); + } } } + // try PHP's mime_content_type if (!$mime_type && function_exists('mime_content_type')) { $mime_type = mime_content_type($path); } - + // fall back to user-submitted string if (!$mime_type) { $mime_type = $failover; } |