[Svn] r2313 - in trunk/roundcubemail: . config program/include program/steps/mail

trac at roundcube.net trac at roundcube.net
Fri Feb 27 11:18:18 CET 2009


Author: thomasb
Date: 2009-02-27 04:18:18 -0600 (Fri, 27 Feb 2009)
New Revision: 2313

Added:
   trunk/roundcubemail/config/mimetypes.php
Modified:
   trunk/roundcubemail/CHANGELOG
   trunk/roundcubemail/program/include/rcube_shared.inc
   trunk/roundcubemail/program/steps/mail/attachments.inc
Log:
Fix mime-type detection using a hard-coded map (#1485311)

Modified: trunk/roundcubemail/CHANGELOG
===================================================================
--- trunk/roundcubemail/CHANGELOG	2009-02-27 09:54:41 UTC (rev 2312)
+++ trunk/roundcubemail/CHANGELOG	2009-02-27 10:18:18 UTC (rev 2313)
@@ -1,6 +1,10 @@
 CHANGELOG RoundCube Webmail
 ---------------------------
 
+2009/02/27 (thomasb)
+----------
+- Fix mime-type detection using a hard-coded map (#1485311)
+
 2009/02/26 (alec)
 ----------
 - Fix new lines stripped from message footer (#1485751)

Added: trunk/roundcubemail/config/mimetypes.php
===================================================================
--- trunk/roundcubemail/config/mimetypes.php	                        (rev 0)
+++ trunk/roundcubemail/config/mimetypes.php	2009-02-27 10:18:18 UTC (rev 2313)
@@ -0,0 +1,45 @@
+<?php
+
+return array(
+  'xls' => 'application/vnd.ms-excel',
+  'xlm' => 'application/vnd.ms-excel',
+  'xla' => 'application/vnd.ms-excel',
+  'xlc' => 'application/vnd.ms-excel',
+  'xlt' => 'application/vnd.ms-excel',
+  'xlw' => 'application/vnd.ms-excel',
+  'ppt' => 'application/vnd.ms-powerpoint',
+  'pps' => 'application/vnd.ms-powerpoint',
+  'pot' => 'application/vnd.ms-powerpoint',
+  'doc' => 'application/msword',
+  'dot' => 'application/msword',
+  'odc' => 'application/vnd.oasis.opendocument.chart',
+  'otc' => 'application/vnd.oasis.opendocument.chart-template',
+  'odf' => 'application/vnd.oasis.opendocument.formula',
+  'otf' => 'application/vnd.oasis.opendocument.formula-template',
+  'odg' => 'application/vnd.oasis.opendocument.graphics',
+  'otg' => 'application/vnd.oasis.opendocument.graphics-template',
+  'odi' => 'application/vnd.oasis.opendocument.image',
+  'oti' => 'application/vnd.oasis.opendocument.image-template',
+  'odp' => 'application/vnd.oasis.opendocument.presentation',
+  'otp' => 'application/vnd.oasis.opendocument.presentation-template',
+  'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
+  'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
+  'odt' => 'application/vnd.oasis.opendocument.text',
+  'otm' => 'application/vnd.oasis.opendocument.text-master',
+  'ott' => 'application/vnd.oasis.opendocument.text-template',
+  'oth' => 'application/vnd.oasis.opendocument.text-web',
+  'docm' => 'application/vnd.ms-word.document.macroEnabled.12',
+  'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
+  'dotm' => 'application/vnd.ms-word.template.macroEnabled.12',
+  'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
+  'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
+  'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
+  'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
+  'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
+  'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
+  'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12',
+  'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
+  'xps' => 'application/vnd.ms-xpsdocument',
+);
+
+?>
\ No newline at end of file

Modified: trunk/roundcubemail/program/include/rcube_shared.inc
===================================================================
--- trunk/roundcubemail/program/include/rcube_shared.inc	2009-02-27 09:54:41 UTC (rev 2312)
+++ trunk/roundcubemail/program/include/rcube_shared.inc	2009-02-27 10:18:18 UTC (rev 2313)
@@ -535,6 +535,7 @@
  * 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 @@
  * @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;
     }

Modified: trunk/roundcubemail/program/steps/mail/attachments.inc
===================================================================
--- trunk/roundcubemail/program/steps/mail/attachments.inc	2009-02-27 09:54:41 UTC (rev 2312)
+++ trunk/roundcubemail/program/steps/mail/attachments.inc	2009-02-27 10:18:18 UTC (rev 2313)
@@ -77,7 +77,7 @@
       $id = count($_SESSION['compose']['attachments']);
       $_SESSION['compose']['attachments'][] = array(
         'name' => $_FILES['_attachments']['name'][$i],
-        'mimetype' => rc_mime_content_type($tmpfname, $_FILES['_attachments']['type'][$i]),
+        'mimetype' => rc_mime_content_type($tmpfname, $_FILES['_attachments']['name'][$i], $_FILES['_attachments']['type'][$i]),
         'path' => $tmpfname,
       );
 

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list