diff options
Diffstat (limited to 'inc/subscription.php')
-rw-r--r-- | inc/subscription.php | 74 |
1 files changed, 72 insertions, 2 deletions
diff --git a/inc/subscription.php b/inc/subscription.php index 62cfd1509..2989de032 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -424,13 +424,55 @@ 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 ); } /** + * Send the diff for some media change + * + * @fixme this should embed thumbnails of images in HTML version + * @param string $subscriber_mail The target mail address + * @param string $template Mail template ('uploadmail', ...) + * @param string $id Media file for which the notification is + * @param int|bool $rev Old revision if any + * @return bool true if successfully sent + */ + public function send_media_diff($subscriber_mail, $template, $id, $rev = false) { + global $conf; + + $file = mediaFN($id); + list($mime, $ext) = mimetype($id); + + $trep = array( + 'MIME' => $mime, + 'MEDIA' => ml($id,'',true,'&',true), + 'SIZE' => filesize_h(filesize($file)), + ); + + if ($rev && $conf['mediarevisions']) { + $trep['OLD'] = ml($id, "rev=$rev", true, '&', true); + } else { + $trep['OLD'] = '---'; + } + + $headers = array('Message-Id' => $this->getMessageID($id, @filemtime($file))); + if ($rev) { + $headers['In-Reply-To'] = $this->getMessageID($id, $rev); + } + + $this->send($subscriber_mail, 'upload', $id, $template, $trep, null, $headers); + + } + + /** * Send a notify mail on new registration * * @author Andreas Gohr <andi@splitbrain.org> @@ -542,9 +584,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,10 +603,37 @@ 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 * * Aggregates all email addresses of user who have subscribed the given page with 'every' style |