diff --git a/mod/forum/lib.php b/mod/forum/lib.php index a1e90692680..5aec1baf397 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -826,8 +826,8 @@ function forum_cron() { // MS Outlook / Office uses poorly documented and non standard headers, including // Thread-Topic which overrides the Subject and shouldn't contain Re: or Fwd: etc. $a->subject = $discussion->name; - $postsubject = html_to_text(get_string('postmailsubject', 'forum', $a), 0); - $userfrom->customheaders[] = "Thread-Topic: $postsubject"; + $threadtopic = html_to_text(get_string('postmailsubject', 'forum', $a), 0); + $userfrom->customheaders[] = "Thread-Topic: $threadtopic"; $userfrom->customheaders[] = "Thread-Index: " . substr($rootid, 1, 28); // Send the post now! diff --git a/mod/forum/tests/mail_test.php b/mod/forum/tests/mail_test.php index d979a4f271a..40f5be489fb 100644 --- a/mod/forum/tests/mail_test.php +++ b/mod/forum/tests/mail_test.php @@ -184,6 +184,8 @@ class mod_forum_mail_testcase extends advanced_testcase { // Add a post to the discussion. $record = new stdClass(); $record->course = $forum->course; + $strre = get_string('re', 'forum'); + $record->subject = $strre . ' ' . $discussion->subject; $record->userid = $author->id; $record->forum = $forum->id; $record->discussion = $discussion->id; @@ -834,6 +836,33 @@ class mod_forum_mail_testcase extends advanced_testcase { $this->assertEquals($expectedsubject, $message->subject); } + /** + * Test inital email and reply email subjects + */ + public function test_subjects() { + $this->resetAfterTest(true); + + $course = $this->getDataGenerator()->create_course(); + + $options = array('course' => $course->id, 'forcesubscribe' => FORUM_FORCESUBSCRIBE); + $forum = $this->getDataGenerator()->create_module('forum', $options); + + list($author) = $this->helper_create_users($course, 1); + list($commenter) = $this->helper_create_users($course, 1); + + $strre = get_string('re', 'forum'); + + // New posts should not have Re: in the subject. + list($discussion, $post) = $this->helper_post_to_forum($forum, $author); + $messages = $this->helper_run_cron_check_count($post, 2); + $this->assertNotContains($strre, $messages[0]->subject); + + // Replies should have Re: in the subject. + $reply = $this->helper_post_to_discussion($forum, $discussion, $commenter); + $messages = $this->helper_run_cron_check_count($reply, 2); + $this->assertContains($strre, $messages[0]->subject); + } + /** * dataProvider for test_forum_post_email_templates(). */