From: Michael M Slusarz Date: Tue, 24 Aug 2010 18:21:18 +0000 (-0600) Subject: Rework compose attachment hook. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=b6d03b85926cd4f8063bbc5f6dd2277ec4810370;p=horde.git Rework compose attachment hook. Rename from 'attachmimetype' to 'compose_attach', since more than just MIME type determination can be done in the hook. Add virus scanning example to hook. --- diff --git a/imp/config/hooks.php.dist b/imp/config/hooks.php.dist index 1029c8dd8..18a1979f6 100644 --- a/imp/config/hooks.php.dist +++ b/imp/config/hooks.php.dist @@ -135,7 +135,7 @@ class IMP_Hooks /** - * Do MIME type determination for compose attachments. + * Perform actions on files uploaded for use as compose attachments. * * This hook is enabled by default. * @@ -146,9 +146,12 @@ class IMP_Hooks * @param string $type The MIME type as reported by the browser. * * @return string The MIME type of the file. + * @throws IMP_Compose_Exception */ - public function attachmimetype($filename, $tempfile, $type) + public function compose_attach($filename, $tempfile, $type) { + /* Do MIME type determination for compose attachments. */ + /* 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') { @@ -163,6 +166,24 @@ class IMP_Hooks } } +// // Example: Do a virus scan on the attachment, and reject attachment +// // if a virus is found. +// // This example uses the open source ClamAV binary (tested with +// // v0.96). See: http://www.clamav.net/ +// $clamscan = '/path/to/clamscan'; +// exec($clamscan . ' --quiet ' . escapeshellarg($tempfile), null, $return_var); +// switch ($return_var) { +// case 1: +// // Virus found. +// Horde::logMessage('Virus found in uploaded attachment', 'INFO'); +// throw new IMP_Compose_Exception('Virus found in uploaded attachment. Attachment will not be added to the compose message.'); +// +// case 2: +// // Error occurred. +// Horde::logMessage('Unknown error when scanning message for virus.', 'INFO'); +// break; +// } + return $type; } diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index 5a95ea9b6..ec4702e64 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -1829,9 +1829,9 @@ class IMP_Compose ? 'application/octet-stream' : $_FILES[$name]['type']; - /* User hook to do MIME magic determinations. */ + /* User hook to do file scanning/MIME magic determinations. */ try { - $type = Horde::callHook('attachmimetype', array($filename, $tempfile, $type), 'imp'); + $type = Horde::callHook('compose_attach', array($filename, $tempfile, $type), 'imp'); } catch (Horde_Exception_HookNotSet $e) {} $part = new Horde_Mime_Part();