From: moodler Date: Tue, 7 Sep 2004 14:04:33 +0000 (+0000) Subject: Added better headers to forum posts to allow threading, better filtering etc. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=857b798b90f3b21e57b925f33a89bc2df191021b;p=moodle.git Added better headers to forum posts to allow threading, better filtering etc. Based on: http://opensource.mediagonal.ch/moodle/patches/mailheaders/ --- diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 373264df56..643047585b 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -1543,10 +1543,16 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml="", $a $mail->WordWrap = 79; // set word wrap - if (!empty($from->precedence)) { - $mail->Precedence = $from->precedence; // set precedence level eg "bulk" "list" or "junk" + if (!empty($from->customheaders)) { // Add custom headers + if (is_array($from->customheaders)) { + foreach ($from->customheaders as $customheader) { + $mail->AddCustomHeader($customheader); + } + } else { + $mail->AddCustomHeader($from->customheaders); + } } - + if ($messagehtml) { $mail->IsHTML(true); $mail->Encoding = "quoted-printable"; // Encoding to use diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 41c628ce78..4eb2cf8a62 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -195,13 +195,13 @@ function forum_cron () { /// Finds all posts that have yet to be mailed out, and mails them /// out to all subscribers + global $CFG, $USER, $THEME; static $strforums = NULL; - if($strforums === NULL) { + + if ($strforums === NULL) { $strforums = get_string('forums', 'forum'); } - global $CFG, $USER, $THEME; - if (!empty($USER)) { // Remember real USER account if necessary $realuser = $USER; } @@ -228,6 +228,9 @@ function forum_cron () { @set_time_limit(0); /// so that script does not get timed out when posting to many users + $urlinfo = parse_url($CFG->wwwroot); + $hostname = $urlinfo['host']; + foreach ($posts as $post) { mtrace(get_string("processingpost", "forum", $post->id), ''); @@ -237,7 +240,15 @@ function forum_cron () { continue; } - $userfrom->precedence = "bulk"; // This gets added to the email header + + $userfrom->customheaders = array ( // Headers to make emails easier to track + "Precedence: Bulk", + "List-id: course}@$hostname>", + "Message-Id: id}@$hostname>", + "In-Reply-To: parent}@$hostname>", + "References: parent}@$hostname>" + ); + if (! $discussion = get_record("forum_discussions", "id", "$post->discussion")) { mtrace("Could not find discussion $post->discussion"); @@ -457,7 +468,7 @@ function forum_cron () { $postsarray = $discussionposts[$discussionid]; sort($postsarray); - foreach($postsarray as $postid) { + foreach ($postsarray as $postid) { if (! $post = get_record("forum_posts", "id", "$postid")) { mtrace("Error: Could not find post $postid"); continue; @@ -467,8 +478,9 @@ function forum_cron () { continue; } - $userfrom->precedence = "bulk"; // This gets added to the email header - if($userto->maildigest == 2) { + $userfrom->customheaders = array ("Precedence: Bulk"); + + if ($userto->maildigest == 2) { // Subjects only $by = New stdClass; $by->name = fullname($userfrom); @@ -478,8 +490,8 @@ function forum_cron () { $by->name = "wwwroot/user/view.php?id=$userfrom->id&course=$course->id\">$by->name"; $posthtml .= '
'.$post->subject.' '.get_string("bynameondate", "forum", $by).'
'; - } - else { + + } else { // The full treatment $posttext .= forum_make_mail_text($course, $forum, $discussion, $post, $userfrom, $userto, true); $posthtml .= forum_make_mail_post($post, $userfrom, $userto, $course, false, $canreply, false, false); @@ -487,8 +499,7 @@ function forum_cron () { } if ($canunsubscribe) { $posthtml .= "\n"; - } - else { + } else { $posthtml .= "\n
".get_string("everyoneissubscribed", "forum")."
"; } $posthtml .= '

';