From f6c5cfef777cfec1d2135d8a032d7d2f97cfa92d Mon Sep 17 00:00:00 2001 From: Ruslan Kabalin Date: Wed, 19 Aug 2015 14:20:29 +0100 Subject: [PATCH] MDL-50907 tool_messageinbound: Use antiviruses_scan_data for attachments scanning. --- admin/tool/messageinbound/classes/manager.php | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/admin/tool/messageinbound/classes/manager.php b/admin/tool/messageinbound/classes/manager.php index c9925e498a5f1..c8ef59f4169c5 100644 --- a/admin/tool/messageinbound/classes/manager.php +++ b/admin/tool/messageinbound/classes/manager.php @@ -666,25 +666,9 @@ private function process_message_part_attachment($messagedata, $partdata, $part, if (!empty($CFG->antiviruses)) { mtrace("--> Attempting virus scan of '{$attachment->filename}'"); - - // Store the file on disk - it will need to be virus scanned first. - $itemid = rand(1, 999999999);; - $directory = make_temp_directory("/messageinbound/{$itemid}", false); - $filepath = $directory . "/" . $attachment->filename; - if (!$fp = fopen($filepath, "w")) { - // Unable to open the temporary file to write this to disk. - mtrace("--> Unable to save the file to disk for virus scanning. Check file permissions."); - - throw new \core\message\inbound\processing_failed_exception('attachmentfilepermissionsfailed', - 'tool_messageinbound'); - } - - fwrite($fp, $attachment->content); - fclose($fp); - // Perform a virus scan now. try { - \core\antivirus\manager::scan_file($filepath, $attachment->filename, true); + \core\antivirus\manager::scan_data($attachment->content); } catch (\core\antivirus\scanner_exception $e) { mtrace("--> A virus was found in the attachment '{$attachment->filename}'."); $this->inform_attachment_virus();