Skip to content

Commit

Permalink
MDL-50907 tool_messageinbound: Use antiviruses_scan_data for attachme…
Browse files Browse the repository at this point in the history
…nts scanning.
  • Loading branch information
kabalin authored and andrewnicols committed Apr 12, 2018
1 parent ddf14b3 commit f6c5cfe
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions admin/tool/messageinbound/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit f6c5cfe

Please sign in to comment.