From afcae55712fd3a26a7fe569dbebb197d2b226938 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Mon, 10 Nov 2014 14:12:52 +0800 Subject: [PATCH] MDL-48148 mod_forum: Use the standard forum reply subject as default When a user replies by e-mail, the course name has been included in the original e-mail. As a result, the reply subject becomes longer and longer. In cases whether either: * the discussion name; or * the replied-to-post subject is present in the mail subject, the standard reply subject is instead used. --- .../classes/message/inbound/reply_handler.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/mod/forum/classes/message/inbound/reply_handler.php b/mod/forum/classes/message/inbound/reply_handler.php index 67e7b08cd2c..90a80456f36 100644 --- a/mod/forum/classes/message/inbound/reply_handler.php +++ b/mod/forum/classes/message/inbound/reply_handler.php @@ -133,12 +133,32 @@ class reply_handler extends \core\message\inbound\handler { throw new \core\message\inbound\processing_failed_exception('messageinboundthresholdhit', 'mod_forum', $data); } + $subject = clean_param($messagedata->envelope->subject, PARAM_TEXT); + $restring = get_string('re', 'forum'); + if (strpos($subject, $discussion->name)) { + // The discussion name is mentioned in the e-mail subject. This is probably just the standard reply. Use the + // standard reply subject instead. + $newsubject = $restring . ' ' . $discussion->name; + mtrace("--> Note: Post subject matched discussion name. Optimising from {$subject} to {$newsubject}"); + $subject = $newsubject; + } else if (strpos($subject, $post->subject)) { + // The replied-to post's subject is mentioned in the e-mail subject. + // Use the previous post's subject instead of the e-mail subject. + $newsubject = $post->subject; + if (!strpos($restring, $post->subject)) { + // The previous post did not contain a re string, add it. + $newsubject = $restring . ' ' . $subject; + } + mtrace("--> Note: Post subject matched original post subject. Optimising from {$subject} to {$newsubject}"); + $subject = $newsubject; + } + $addpost = new \stdClass(); $addpost->course = $course->id; $addpost->forum = $forum->id; $addpost->discussion = $discussion->id; $addpost->modified = $messagedata->timestamp; - $addpost->subject = clean_param($messagedata->envelope->subject, PARAM_TEXT); + $addpost->subject = $subject; $addpost->parent = $post->id; $addpost->itemid = file_get_unused_draft_itemid();