From: Michael M Slusarz Date: Thu, 21 Jan 2010 19:03:27 +0000 (-0700) Subject: Add attachmimetype hook X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=25541bba013406b30731ba262336157e0ddf7c60;p=horde.git Add attachmimetype hook --- diff --git a/imp/config/hooks.php.dist b/imp/config/hooks.php.dist index fb9e90c56..c6c65448f 100644 --- a/imp/config/hooks.php.dist +++ b/imp/config/hooks.php.dist @@ -105,6 +105,7 @@ class IMP_Hooks // } // } + /** * AJAX HOOK: Add user-defined AJAX action handlers. * @@ -124,10 +125,42 @@ class IMP_Hooks // throw new Horde_Ajax_Exception('Unknown action'); // } + + /** + * Do MIME type determination for compose attachments. + * + * @param string $filename The filename. + * @param string $tempfile The location on the local server of the + * temporary file that contains the attachment + * data. + * @param string $type The MIME type as reported by the browser. + * + * @return string The MIME type of the file. + / + function attachmimetype($filename, $tempfile, $type) + { + /* By default, we trust the MIME type reported by the browser if it is + * something other than the generic octet-stream type. */ + if ($type == 'application/octet-stream') { + /* Try to determine the MIME type from 1) analysis of the file + * (if available) and, if that fails, 2) from the extension. We + * do it in this order here because, most likely, if a browser + * can't identify the type of a file, it is because the file + * extension isn't available and/or recognized. */ + $type = Horde_Mime_Magic::analyzeFile($tempfile, !empty($GLOBALS['conf']['mime']['magic_db']) ? $GLOBALS['conf']['mime']['magic_db'] : null); + if (!$type) { + $type = Horde_Mime_Magic::filenameToMIME($filename, false); + } + } + + return $type; + } + + /** * Perform an action after a message has been sent successfully. * - * @param Horde_Mime_Part $message The message content object. + * @param Horde_Mime_Part $message The message content object. * @param Horde_Mime_Headers $message The message headers object. */ // function postsent($message, $headers) diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index bb0aef326..b6e36c779 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -2,6 +2,7 @@ v5.0-git -------- +[mms] Add hook to allow determination of compose attachments MIME type. [mms] Move AJAX processing framework to Horde (Request #4561). [mms] If selected message(s) disappear from mailbox, gracefully handle in the user interface (DIMP). diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index f72073b45..41e25366d 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -1686,21 +1686,16 @@ class IMP_Compose throw new IMP_Compose_Exception(sprintf(_("Attached file \"%s\" exceeds the attachment size limits. File NOT attached."), $filename), 'horde.error'); } - /* Store the data in a Horde_Mime_Part. Some browsers do not send the - * MIME type so try an educated guess. */ - if (!empty($_FILES[$name]['type']) && - ($_FILES[$name]['type'] != 'application/octet-stream')) { - $type = $_FILES[$name]['type']; - } else { - /* Try to determine the MIME type from 1) analysis of the file - * (if available) and, if that fails, 2) from the extension. We - * do it in this order here because, most likely, if a browser - * can't identify the type of a file, it is because the file - * extension isn't available and/or recognized. */ - if (!($type = Horde_Mime_Magic::analyzeFile($tempfile, !empty($conf['mime']['magic_db']) ? $conf['mime']['magic_db'] : null))) { - $type = Horde_Mime_Magic::filenameToMIME($filename, false); - } - } + /* Determine the MIME type of the data. */ + $type = empty($_FILES[$name]['type']) + ? 'application/octet-stream' + : $_FILES[$name]['type']; + + /* User hook to do MIME magic determinations. */ + try { + $type = Horde::callHook('attachmimetype', array($filename, $tempfile, $type), 'imp'); + } catch (Horde_Exception_HookNotSet $e) {} + $part = new Horde_Mime_Part(); $part->setType($type); $part->setCharset(Horde_Nls::getCharset());