]> git.mjollnir.org Git - moodle.git/commitdiff
Added better headers to forum posts to allow threading, better filtering etc.
authormoodler <moodler>
Tue, 7 Sep 2004 14:04:33 +0000 (14:04 +0000)
committermoodler <moodler>
Tue, 7 Sep 2004 14:04:33 +0000 (14:04 +0000)
   Based on: http://opensource.mediagonal.ch/moodle/patches/mailheaders/

lib/moodlelib.php
mod/forum/lib.php

index 373264df56b85016ef6ce51e27c9f5f18f5a2d5f..643047585b99649c6372a611a2ace59fdde979ce 100644 (file)
@@ -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
index 41c628ce782967236c5c37da9a11b605d576b7b6..4eb2cf8a6252b600cb0d26c6e866df97208a2d3c 100644 (file)
@@ -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: <moodlecourse{$post->course}@$hostname>",
+                       "Message-Id: <moodlepost{$post->id}@$hostname>",
+                       "In-Reply-To: <moodlepost{$post->parent}@$hostname>",
+                       "References: <moodlepost{$post->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 = "<a target=\"_blank\" href=\"$CFG->wwwroot/user/view.php?id=$userfrom->id&course=$course->id\">$by->name</a>";
                             $posthtml .= '<div><a target="_blank" href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$discussion->id.'#'.$post->id.'">'.$post->subject.'</a> '.get_string("bynameondate", "forum", $by).'</div>';
-                        }
-                        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<div align=\"right\"><font size=\"1\"><a href=\"$CFG->wwwroot/mod/forum/subscribe.php?id=$forum->id\">".get_string("unsubscribe", "forum")."</a></font></div>";
-                    }
-                    else {
+                    } else {
                         $posthtml .= "\n<div align=\"right\"><font size=\"1\">".get_string("everyoneissubscribed", "forum")."</font></div>";
                     }
                     $posthtml .= '<hr size="1" noshade="noshade" /></p>';