$data->viewfullnames = $userto->viewfullnames[$forum->id];
}
+ // Not all of these variables are used in the default language
+ // string but are made available to support custom subjects.
$a = new stdClass();
- $a->courseshortname = $data->get_coursename();
- $a->forumname = $cleanforumname;
$a->subject = $data->get_subject();
+ $a->forumname = $cleanforumname;
+ $a->sitefullname = format_string($site->fullname);
+ $a->siteshortname = format_string($site->shortname);
+ $a->courseidnumber = $data->get_courseidnumber();
+ $a->coursefullname = $data->get_coursefullname();
+ $a->courseshortname = $data->get_coursename();
$postsubject = html_to_text(get_string('postmailsubject', 'forum', $a), 0);
+ $rootid = forum_get_email_message_id($discussion->firstpost, $userto->id, $hostname);
+
+ if ($post->parent) {
+ // This post is a reply, so add reply header (RFC 2822).
+ $parentid = forum_get_email_message_id($post->parent, $userto->id, $hostname);
+ $userfrom->customheaders[] = "In-Reply-To: $parentid";
+
+ // If the post is deeply nested we also reference the parent message id and
+ // the root message id (if different) to aid threading when parts of the email
+ // conversation have been deleted (RFC1036).
+ if ($post->parent != $discussion->firstpost) {
+ $userfrom->customheaders[] = "References: $rootid $parentid";
+ } else {
+ $userfrom->customheaders[] = "References: $parentid";
+ }
+ }
+
+ // 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";
+ $userfrom->customheaders[] = "Thread-Index: " . substr($rootid, 1, 28);
+
// Send the post now!
mtrace('Sending ', '');