MDL-50907 tool_messageinbound: Use antiviruses_scan_data for attachments scanning.
This commit is contained in:
committed by
Andrew Nicols
parent
ddf14b32fe
commit
f6c5cfef77
@@ -666,25 +666,9 @@ class manager {
|
||||
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user