// }
// }
+
/**
* AJAX HOOK: Add user-defined AJAX action handlers.
*
// 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)
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).
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());