Commit 0498da87 authored by Melissa Draper's avatar Melissa Draper

Add X-Mahara- headers to forum emails (Bug #882891)

Forum email subjects are unwieldy so move forum name and group name to
custom headers so users can filter as well as have a more concise
subject line. Values in headers trimmed to 100 char based on information
at http://stackoverflow.com/questions/2721605/maximum-size-of-email-x-headers

Change-Id: Iad9c7c3101ff81f19f3beafbe1811f28f3d3faa5
Signed-off-by: default avatarMelissa Draper <melissa@catalyst.net.nz>
parent f4a0e178
......@@ -107,7 +107,7 @@ $string['moderatorsdescription'] = 'Moderators can edit and delete topics and po
$string['name'] = 'Forum';
$string['nameplural'] = 'Forums';
$string['newforum'] = 'New forum';
$string['newforumpostnotificationsubject'] = '%s: %s: %s';
$string['newforumpostnotificationsubjectline'] = '%s';
$string['newpost'] = 'New post: ';
$string['newtopic'] = 'New topic';
$string['noforumpostsyet'] = 'There are no posts in this group yet';
......@@ -131,7 +131,7 @@ $string['potentialmoderators'] = 'Potential Moderators';
$string['re'] ='Re: %s';
$string['regulartopics'] = 'Regular topics';
$string['Reply'] = 'Reply';
$string['replyforumpostnotificationsubject'] = 'Re: %s: %s: %s';
$string['replyforumpostnotificationsubjectline'] = 'Re: %s';
$string['replyto'] = 'Reply to: ';
$string['Sticky'] = 'Sticky';
$string['stickydescription'] = 'Sticky topics are at the top of every page';
......
......@@ -781,11 +781,16 @@ class ActivityTypeInteractionForumNewPost extends ActivityTypePlugin {
// When emailing forum posts, create Message-Id headers for threaded display by email clients
$urlinfo = parse_url(get_config('wwwroot'));
$hostname = $urlinfo['host'];
$cleanforumname = str_replace('"', "'", strip_tags($post->forumtitle));
$cleanforumname = clean_email_headers($post->forumtitle);
$cleangroupname = clean_email_headers($post->groupname);
$cleanforumname = str_replace('"', "'", strip_tags($cleanforumname));
$cleangroupname = str_replace('"', "'", strip_tags($cleangroupname));
$this->customheaders = array(
'List-Id: "' . $cleanforumname . '" <forum' . $post->forumid . '@' . $hostname . '>',
'List-Help: ' . get_config('wwwroot') . 'interaction/forum/view.php?id=' . $post->forumid,
'Message-ID: <forumpost' . $this->postid . '@' . $hostname . '>',
'X-Mahara-Group: ' . $cleangroupname,
'X-Mahara-Forum: ' . $cleanforumname
);
if ($post->parent) {
$this->customheaders[] = 'In-Reply-To: <forumpost' . $post->parent . '@' . $hostname . '>';
......@@ -805,9 +810,9 @@ class ActivityTypeInteractionForumNewPost extends ActivityTypePlugin {
));
$this->strings->subject = (object) array(
'key' => $post->parent ? 'replyforumpostnotificationsubject' : 'newforumpostnotificationsubject',
'key' => $post->parent ? 'replyforumpostnotificationsubjectline' : 'newforumpostnotificationsubjectline',
'section' => 'interaction.forum',
'args' => array($post->groupname, $post->forumtitle, $post->parent ? $post->topicsubject : $post->subject),
'args' => array($post->parent ? $post->topicsubject : $post->subject),
);
foreach ($this->users as &$user) {
......
......@@ -3320,3 +3320,16 @@ function sanitize_url($url) {
}
return $url;
}
/**
* Sanitises header text per rfc5322
*
* @return string A string with undesired characters filtered out
*/
function clean_email_headers($headertext) {
$decoloned = str_replace(':', '', $headertext);
$filtered = filter_var($decoloned, FILTER_SANITIZE_STRING, array(FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH));
return substr($filtered, 0, 100);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment