mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-61738 messageinbound: Fix quota checks & filesize for email uploads
Private files uploaded by email will now honour the file quota limit, because the filesize is set correctly and checked against users' remaining personal quota limit. Previously, attachment size was always set to zero, and quota was checked against the draft area (this is not valid for email uploads, because each file is moved out of the draft area as it is processed, so multiple files totalling greater than the remaining quota would still pass the check).
This commit is contained in:
parent
c509d10821
commit
cbe5c5fed4
@ -672,7 +672,7 @@ class manager {
|
||||
$attachment->charset = $partdata->getCharset();
|
||||
$attachment->description = $partdata->getDescription();
|
||||
$attachment->contentid = $partdata->getContentId();
|
||||
$attachment->filesize = $messagedata->getBodyPartSize($part);
|
||||
$attachment->filesize = $partdata->getBytes();
|
||||
|
||||
if (!empty($CFG->antiviruses)) {
|
||||
mtrace("--> Attempting virus scan of '{$attachment->filename}'");
|
||||
|
@ -26,6 +26,8 @@ namespace core\message\inbound;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir . '/filelib.php');
|
||||
|
||||
/**
|
||||
* A Handler to store attachments sent in e-mails as private files.
|
||||
*
|
||||
@ -98,15 +100,17 @@ class private_files_handler extends handler {
|
||||
$uploadedfiles = array();
|
||||
$failedfiles = array();
|
||||
|
||||
$usedspace = file_get_user_used_space();
|
||||
$fs = get_file_storage();
|
||||
foreach ($data->attachments as $attachmenttype => $attachments) {
|
||||
foreach ($attachments as $attachment) {
|
||||
mtrace("--- Processing attachment '{$attachment->filename}'");
|
||||
|
||||
if (file_is_draft_area_limit_reached($itemid, $maxbytes, $attachment->filesize)) {
|
||||
if ($maxbytes != USER_CAN_IGNORE_FILE_SIZE_LIMITS &&
|
||||
($attachment->filesize + $usedspace) > $maxbytes) {
|
||||
// The user quota will be exceeded if this file is included.
|
||||
$skippedfiles[] = $attachment;
|
||||
mtrace("---- Skipping attacment. User will be over quota.");
|
||||
mtrace("---- Skipping attachment. User will be over quota.");
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -132,8 +136,9 @@ class private_files_handler extends handler {
|
||||
// File created successfully.
|
||||
mtrace("---- File uploaded successfully as {$record->filename}.");
|
||||
$uploadedfiles[] = $attachment;
|
||||
$usedspace += $attachment->filesize;
|
||||
} else {
|
||||
mtrace("---- Skipping attacment. Unknown failure during creation.");
|
||||
mtrace("---- Skipping attachment. Unknown failure during creation.");
|
||||
$failedfiles[] = $attachment;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user