Added better headers to forum posts to allow threading, better filtering etc.

Based on: http://opensource.mediagonal.ch/moodle/patches/mailheaders/
This commit is contained in:
moodler 2004-09-07 14:04:33 +00:00
parent 8deb0ff5e2
commit 857b798b90
2 changed files with 31 additions and 14 deletions

View File

@ -1543,8 +1543,14 @@ 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) {

View 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) {
$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");
@ -467,7 +478,8 @@ function forum_cron () {
continue;
}
$userfrom->precedence = "bulk"; // This gets added to the email header
$userfrom->customheaders = array ("Precedence: Bulk");
if ($userto->maildigest == 2) {
// Subjects only
$by = New stdClass;
@ -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>';