From 10eac6731852014bcef1a0d16c59a4f6f77d8e31 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Sat, 26 Jan 2013 15:09:43 +0100 Subject: Add threading headers to change notification mails as proposed in PR #120 --- inc/subscription.php | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/subscription.php b/inc/subscription.php index 62cfd1509..31e3e08e1 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -424,9 +424,14 @@ class Subscription { $trep['DIFF'] = $tdiff; $hrep['DIFF'] = $hdiff; + $headers = array('Message-Id' => $this->getMessageID($id)); + if ($rev) { + $headers['In-Reply-To'] = $this->getMessageID($id, $rev); + } + return $this->send( $subscriber_mail, $subject, $id, - $template, $trep, $hrep + $template, $trep, $hrep, $headers ); } @@ -542,9 +547,10 @@ class Subscription { * template (in text format) * @param array $hrep Predefined parameters used to parse the * template (in HTML format), null to default to $trep + * @param array $headers Additional mail headers in the form 'name' => 'value' * @return bool */ - protected function send($subscriber_mail, $subject, $context, $template, $trep, $hrep = null) { + protected function send($subscriber_mail, $subject, $context, $template, $trep, $hrep = null, $headers = array()) { global $lang; global $conf; @@ -560,9 +566,36 @@ class Subscription { if(isset($trep['SUBSCRIBE'])) { $mail->setHeader('List-Unsubscribe', '<'.$trep['SUBSCRIBE'].'>', false); } + + foreach ($headers as $header => $value) { + $mail->setHeader($header, $value); + } + return $mail->send(); } + /** + * Get a valid message id for a certain $id and revision (or the current revision) + * @param string $id The id of the page (or media file) the message id should be for + * @param string $rev The revision of the page, set to the current revision of the page $id if not set + * @return string + */ + protected function getMessageID($id, $rev = NULL) { + static $listid = null; + if (is_null($listid)) { + $server = parse_url(DOKU_URL, PHP_URL_HOST); + $listid = join('.', array_reverse(explode('/', DOKU_BASE))).$server; + $listid = urlencode($listid); + $listid = strtolower(trim($listid, '.')); + } + + if (is_null($rev)) { + $rev = @filemtime(wikiFN($id)); + } + + return "<$id?rev=$rev@$listid>"; + } + /** * Default callback for COMMON_NOTIFY_ADDRESSLIST * -- cgit v1.2.3