From 73e4f14d1b98a1bf88dbef8d3d50bb4e913c9cb7 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Thu, 26 Oct 2017 13:32:54 +0800 Subject: [PATCH] MDL-60591 mod_forum: inline attachments are not displayed in plain text --- .../classes/message/inbound/reply_handler.php | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/mod/forum/classes/message/inbound/reply_handler.php b/mod/forum/classes/message/inbound/reply_handler.php index 874626a3f76d7..cd369e52bdced 100644 --- a/mod/forum/classes/message/inbound/reply_handler.php +++ b/mod/forum/classes/message/inbound/reply_handler.php @@ -170,9 +170,20 @@ public function process_message(\stdClass $record, \stdClass $messagedata) { // We don't trust text coming from e-mail. $addpost->messagetrust = false; + // Find all attachments. If format is plain text, treat inline attachments as regular ones. + $attachments = !empty($messagedata->attachments['attachment']) ? $messagedata->attachments['attachment'] : []; + $inlineattachments = []; + if (!empty($messagedata->attachments['inline'])) { + if ($addpost->messageformat == FORMAT_HTML) { + $inlineattachments = $messagedata->attachments['inline']; + } else { + $attachments = array_merge($attachments, $messagedata->attachments['inline']); + } + } + // Add attachments to the post. - if (!empty($messagedata->attachments['attachment']) && count($messagedata->attachments['attachment'])) { - $attachmentcount = count($messagedata->attachments['attachment']); + if ($attachments) { + $attachmentcount = count($attachments); if (!forum_can_create_attachment($forum, $modcontext)) { // Attachments are not allowed. mtrace("--> User does not have permission to attach files in this forum. Rejecting e-mail."); @@ -196,7 +207,7 @@ public function process_message(\stdClass $record, \stdClass $messagedata) { $filesize = 0; $addpost->attachments = file_get_unused_draft_itemid(); - foreach ($messagedata->attachments['attachment'] as $attachment) { + foreach ($attachments as $attachment) { mtrace("--> Processing {$attachment->filename} as an attachment."); $this->process_attachment('*', $usercontext, $addpost->attachments, $attachment); $filesize += $attachment->filesize; @@ -215,8 +226,8 @@ public function process_message(\stdClass $record, \stdClass $messagedata) { } // Process any files in the message itself. - if (!empty($messagedata->attachments['inline'])) { - foreach ($messagedata->attachments['inline'] as $attachment) { + if ($inlineattachments) { + foreach ($inlineattachments as $attachment) { mtrace("--> Processing {$attachment->filename} as an inline attachment."); $this->process_attachment('*', $usercontext, $addpost->itemid, $attachment);