summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--inc/Mailer.class.php613
-rw-r--r--inc/auth.php52
-rw-r--r--inc/common.php74
-rw-r--r--inc/load.php1
-rw-r--r--inc/media.php34
-rw-r--r--inc/subscription.php18
6 files changed, 691 insertions, 101 deletions
diff --git a/inc/Mailer.class.php b/inc/Mailer.class.php
new file mode 100644
index 000000000..09e457243
--- /dev/null
+++ b/inc/Mailer.class.php
@@ -0,0 +1,613 @@
+<?php
+/**
+ * A class to build and send multi part mails (with HTML content and embedded
+ * attachments). All mails are assumed to be in UTF-8 encoding.
+ *
+ * Attachments are handled in memory so this shouldn't be used to send huge
+ * files, but then again mail shouldn't be used to send huge files either.
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+
+// end of line for mail lines - RFC822 says CRLF but postfix (and other MTAs?)
+// think different
+if(!defined('MAILHEADER_EOL')) define('MAILHEADER_EOL',"\n");
+#define('MAILHEADER_ASCIIONLY',1);
+
+class Mailer {
+
+ private $headers = array();
+ private $attach = array();
+ private $html = '';
+ private $text = '';
+
+ private $boundary = '';
+ private $partid = '';
+ private $sendparam= null;
+
+ private $validator = null;
+
+ /**
+ * Constructor
+ *
+ * Initializes the boundary strings and part counters
+ */
+ public function __construct(){
+ if(isset($_SERVER['SERVER_NAME'])){
+ $server = $_SERVER['SERVER_NAME'];
+ }else{
+ $server = 'localhost';
+ }
+
+ $this->partid = md5(uniqid(rand(),true)).'@'.$server;
+ $this->boundary = '----------'.md5(uniqid(rand(),true));
+ }
+
+ /**
+ * Attach a file
+ *
+ * @param $path Path to the file to attach
+ * @param $mime Mimetype of the attached file
+ * @param $name The filename to use
+ * @param $embed Unique key to reference this file from the HTML part
+ */
+ public function attachFile($path,$mime,$name='',$embed=''){
+ if(!$name){
+ $name = basename($path);
+ }
+
+ $this->attach[] = array(
+ 'data' => file_get_contents($path),
+ 'mime' => $mime,
+ 'name' => $name,
+ 'embed' => $embed
+ );
+ }
+
+ /**
+ * Attach a file
+ *
+ * @param $path The file contents to attach
+ * @param $mime Mimetype of the attached file
+ * @param $name The filename to use
+ * @param $embed Unique key to reference this file from the HTML part
+ */
+ public function attachContent($data,$mime,$name='',$embed=''){
+ if(!$name){
+ list($junk,$ext) = split('/',$mime);
+ $name = count($this->attach).".$ext";
+ }
+
+ $this->attach[] = array(
+ 'data' => $data,
+ 'mime' => $mime,
+ 'name' => $name,
+ 'embed' => $embed
+ );
+ }
+
+ /**
+ * Add an arbitrary header to the mail
+ *
+ * If an empy value is passed, the header is removed
+ *
+ * @param string $header the header name (no trailing colon!)
+ * @param string $value the value of the header
+ * @param bool $clean remove all non-ASCII chars and line feeds?
+ */
+ public function setHeader($header,$value,$clean=true){
+ $header = ucwords(strtolower($header)); // streamline casing
+ if($clean){
+ $header = preg_replace('/[^\w \-\.\+\@]+/','',$header);
+ $value = preg_replace('/[^\w \-\.\+\@]+/','',$value);
+ }
+
+ // empty value deletes
+ $value = trim($value);
+ if($value === ''){
+ if(isset($this->headers[$header])) unset($this->headers[$header]);
+ }else{
+ $this->headers[$header] = $value;
+ }
+ }
+
+ /**
+ * Set additional parameters to be passed to sendmail
+ *
+ * Whatever is set here is directly passed to PHP's mail() command as last
+ * parameter. Depending on the PHP setup this might break mailing alltogether
+ */
+ public function setParameters($param){
+ $this->sendparam = $param;
+ }
+
+ /**
+ * Set the text and HTML body and apply replacements
+ *
+ * This function applies a whole bunch of default replacements in addition
+ * to the ones specidifed as parameters
+ *
+ * If you pass the HTML part or HTML replacements yourself you have to make
+ * sure you encode all HTML special chars correctly
+ *
+ * @fixme the HTML head and body still needs to be set
+ * @param string $text plain text body
+ * @param array $textrep replacements to apply on the text part
+ * @param array $htmlrep replacements to apply on the HTML part, leave null to use $textrep
+ * @param array $html the HTML body, leave null to create it from $text
+ */
+ public function setBody($text, $textrep=null, $htmlrep=null, $html=null){
+ global $INFO;
+ global $conf;
+ $htmlrep = (array) $htmlrep;
+ $textrep = (array) $textrep;
+
+ // create HTML from text if not given
+ if(is_null($html)){
+ $html = hsc($text);
+ $html = nl2br($text);
+ }
+ // copy over all replacements missing for HTML (autolink URLs)
+ foreach($textrep as $key => $value){
+ if(isset($htmlrep[$key])) continue;
+ if(preg_match('/^https?:\/\//i',$value)){
+ $htmlrep[$key] = '<a href="'.hsc($value).'">'.hsc($value).'</a>';
+ }else{
+ $htmlrep[$key] = hsc($value);
+ }
+ }
+
+ // prepare default replacements
+ $ip = clientIP();
+ $trep = array(
+ 'DATE' => dformat(),
+ 'BROWSER' => $_SERVER['HTTP_USER_AGENT'],
+ 'IPADDRESS' => $ip,
+ 'HOSTNAME' => gethostsbyaddrs($ip),
+ 'TITLE' => $conf['title'],
+ 'DOKUWIKIURL' => DOKU_URL,
+ 'USER' => $_SERVER['REMOTE_USER'],
+ 'NAME' => $INFO['userinfo']['name'],
+ 'MAIL' => $INFO['userinfo']['mail'],
+ );
+ $trep = array_merge($trep,(array) $textrep);
+ $hrep = array(
+ 'DATE' => '<i>'.hsc(dformat()).'</i>',
+ 'BROWSER' => hsc($_SERVER['HTTP_USER_AGENT']),
+ 'IPADDRESS' => '<code>'.hsc($ip).'</code>',
+ 'HOSTNAME' => '<code>'.hsc(gethostsbyaddrs($ip)).'</code>',
+ 'TITLE' => hsc($conf['title']),
+ 'DOKUWIKIURL' => '<a href="'.DOKU_URL.'">'.DOKU_URL.'</a>',
+ 'USER' => hsc($_SERVER['REMOTE_USER']),
+ 'NAME' => hsc($INFO['userinfo']['name']),
+ 'MAIL' => '<a href="mailto:"'.hsc($INFO['userinfo']['mail']).'">'.
+ hsc($INFO['userinfo']['mail']).'</a>',
+ );
+ $hrep = array_merge($hrep,(array) $htmlrep);
+
+ // Apply replacements
+ foreach ($trep as $key => $substitution) {
+ $text = str_replace('@'.strtoupper($key).'@',$substitution, $text);
+ }
+ foreach ($hrep as $key => $substitution) {
+ $html = str_replace('@'.strtoupper($key).'@',$substitution, $html);
+ }
+
+ $this->setHTML($html);
+ $this->setText($text);
+ }
+
+ /**
+ * Set the HTML part of the mail
+ *
+ * Placeholders can be used to reference embedded attachments
+ *
+ * You probably want to use setBody() instead
+ */
+ public function setHTML($html){
+ $this->html = $html;
+ }
+
+ /**
+ * Set the plain text part of the mail
+ *
+ * You probably want to use setBody() instead
+ */
+ public function setText($text){
+ $this->text = $text;
+ }
+
+ /**
+ * Add the To: recipients
+ *
+ * @see setAddress
+ * @param string $address Multiple adresses separated by commas
+ */
+ public function to($address){
+ $this->setHeader('To', $address, false);
+ }
+
+ /**
+ * Add the Cc: recipients
+ *
+ * @see setAddress
+ * @param string $address Multiple adresses separated by commas
+ */
+ public function cc($address){
+ $this->setHeader('Cc', $address, false);
+ }
+
+ /**
+ * Add the Bcc: recipients
+ *
+ * @see setAddress
+ * @param string $address Multiple adresses separated by commas
+ */
+ public function bcc($address){
+ $this->setHeader('Bcc', $address, false);
+ }
+
+ /**
+ * Add the From: address
+ *
+ * This is set to $conf['mailfrom'] when not specified so you shouldn't need
+ * to call this function
+ *
+ * @see setAddress
+ * @param string $address from address
+ */
+ public function from($address){
+ $this->setHeader('From', $address, false);
+ }
+
+ /**
+ * Add the mail's Subject: header
+ *
+ * @param string $subject the mail subject
+ */
+ public function subject($subject){
+ $this->headers['Subject'] = $subject;
+ }
+
+ /**
+ * Sets an email address header with correct encoding
+ *
+ * Unicode characters will be deaccented and encoded base64
+ * for headers. Addresses may not contain Non-ASCII data!
+ *
+ * Example:
+ * setAddress("föö <foo@bar.com>, me@somewhere.com","TBcc");
+ *
+ * @param string $address Multiple adresses separated by commas
+ * @param string returns the prepared header (can contain multiple lines)
+ */
+ public function cleanAddress($address){
+ // No named recipients for To: in Windows (see FS#652)
+ $names = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? false : true;
+
+ $address = preg_replace('/[\r\n\0]+/',' ',$address); // remove attack vectors
+
+ $headers = '';
+ $parts = explode(',',$address);
+ foreach ($parts as $part){
+ $part = trim($part);
+
+ // parse address
+ if(preg_match('#(.*?)<(.*?)>#',$part,$matches)){
+ $text = trim($matches[1]);
+ $addr = $matches[2];
+ }else{
+ $addr = $part;
+ }
+ // skip empty ones
+ if(empty($addr)){
+ continue;
+ }
+
+ // FIXME: is there a way to encode the localpart of a emailaddress?
+ if(!utf8_isASCII($addr)){
+ msg(htmlspecialchars("E-Mail address <$addr> is not ASCII"),-1);
+ continue;
+ }
+
+ if(is_null($this->validator)){
+ $this->validator = new EmailAddressValidator();
+ $this->validator->allowLocalAddresses = true;
+ }
+ if(!$this->validator->check_email_address($addr)){
+ msg(htmlspecialchars("E-Mail address <$addr> is not valid"),-1);
+ continue;
+ }
+
+ // text was given
+ if(!empty($text) && $names){
+ // add address quotes
+ $addr = "<$addr>";
+
+ if(defined('MAILHEADER_ASCIIONLY')){
+ $text = utf8_deaccent($text);
+ $text = utf8_strip($text);
+ }
+
+ if(!utf8_isASCII($text)){
+ //FIXME check if this is needed for base64 too
+ // put the quotes outside as in =?UTF-8?Q?"Elan Ruusam=C3=A4e"?= vs "=?UTF-8?Q?Elan Ruusam=C3=A4e?="
+ /*
+ if (preg_match('/^"(.+)"$/', $text, $matches)) {
+ $text = '"=?UTF-8?Q?'.mail_quotedprintable_encode($matches[1], 0).'?="';
+ } else {
+ $text = '=?UTF-8?Q?'.mail_quotedprintable_encode($text, 0).'?=';
+ }
+ */
+ $text = '=?UTF-8?B?'.base64_encode($text).'?=';
+ }
+ }else{
+ $text = '';
+ }
+
+ // add to header comma seperated
+ if($headers != ''){
+ $headers .= ', ';
+ }
+ $headers .= $text.' '.$addr;
+ }
+
+ if(empty($headers)) return false;
+
+ return $headers;
+ }
+
+
+ /**
+ * Prepare the mime multiparts for all attachments
+ *
+ * Replaces placeholders in the HTML with the correct CIDs
+ */
+ protected function prepareAttachments(){
+ $mime = '';
+ $part = 1;
+ // embedded attachments
+ foreach($this->attach as $media){
+ // create content id
+ $cid = 'part'.$part.'.'.$this->partid;
+
+ // replace wildcards
+ if($media['embed']){
+ $this->html = str_replace('%%'.$media['embed'].'%%','cid:'.$cid,$this->html);
+ }
+
+ $mime .= '--'.$this->boundary.MAILHEADER_EOL;
+ $mime .= 'Content-Type: '.$media['mime'].';'.MAILHEADER_EOL;
+ $mime .= 'Content-Transfer-Encoding: base64'.MAILHEADER_EOL;
+ $mime .= "Content-ID: <$cid>".MAILHEADER_EOL;
+ if($media['embed']){
+ $mime .= 'Content-Disposition: inline; filename="'.$media['name'].'"'.MAILHEADER_EOL;
+ }else{
+ $mime .= 'Content-Disposition: attachment; filename="'.$media['name'].'"'.MAILHEADER_EOL;
+ }
+ $mime .= MAILHEADER_EOL; //end of headers
+ $mime .= chunk_split(base64_encode($media['data']),74,MAILHEADER_EOL);
+
+ $part++;
+ }
+ return $mime;
+ }
+
+ /**
+ * Build the body and handles multi part mails
+ *
+ * Needs to be called before prepareHeaders!
+ *
+ * @return string the prepared mail body, false on errors
+ */
+ protected function prepareBody(){
+ global $conf;
+
+ // check for body
+ if(!$this->text && !$this->html){
+ return false;
+ }
+
+ // add general headers
+ $this->headers['MIME-Version'] = '1.0';
+
+ $body = '';
+
+ if(!$this->html && !count($this->attach)){ // we can send a simple single part message
+ $this->headers['Content-Type'] = 'text/plain; charset=UTF-8';
+ $this->headers['Content-Transfer-Encoding'] = 'base64';
+ $body .= chunk_split(base64_encode($this->text),74,MAILHEADER_EOL);
+ }else{ // multi part it is
+ $body .= "This is a multi-part message in MIME format.".MAILHEADER_EOL;
+
+ // prepare the attachments
+ $attachments = $this->prepareAttachments();
+
+ // do we have alternative text content?
+ if($this->text && $this->html){
+ $this->headers['Content-Type'] = 'multipart/alternative;'.MAILHEADER_EOL.
+ ' boundary="'.$this->boundary.'XX"';
+ $body .= '--'.$this->boundary.'XX'.MAILHEADER_EOL;
+ $body .= 'Content-Type: text/plain; charset=UTF-8'.MAILHEADER_EOL;
+ $body .= 'Content-Transfer-Encoding: base64'.MAILHEADER_EOL;
+ $body .= MAILHEADER_EOL;
+ $body .= chunk_split(base64_encode($this->text),74,MAILHEADER_EOL);
+ $body .= '--'.$this->boundary.'XX'.MAILHEADER_EOL;
+ $body .= 'Content-Type: multipart/related;'.MAILHEADER_EOL.
+ ' boundary="'.$this->boundary.'"'.MAILHEADER_EOL;
+ $body .= MAILHEADER_EOL;
+ }
+
+ $body .= '--'.$this->boundary.MAILHEADER_EOL;
+ $body .= 'Content-Type: text/html; charset=UTF-8'.MAILHEADER_EOL;
+ $body .= 'Content-Transfer-Encoding: base64'.MAILHEADER_EOL;
+ $body .= MAILHEADER_EOL;
+ $body .= chunk_split(base64_encode($this->html),74,MAILHEADER_EOL);
+ $body .= MAILHEADER_EOL;
+ $body .= $attachments;
+ $body .= '--'.$this->boundary.'--'.MAILHEADER_EOL;
+
+ // close open multipart/alternative boundary
+ if($this->text && $this->html){
+ $body .= '--'.$this->boundary.'XX--'.MAILHEADER_EOL;
+ }
+ }
+
+ return $body;
+ }
+
+ /**
+ * Cleanup and encode the headers array
+ */
+ protected function cleanHeaders(){
+ global $conf;
+
+ // clean up addresses
+ if(empty($this->headers['From'])) $this->from($conf['mailfrom']);
+ $addrs = array('To','From','Cc','Bcc');
+ foreach($addrs as $addr){
+ if(isset($this->headers[$addr])){
+ $this->headers[$addr] = $this->cleanAddress($this->headers[$addr]);
+ }
+ }
+
+ if(isset($subject)){
+ // add prefix to subject
+ if(empty($conf['mailprefix'])){
+ if(utf8_strlen($conf['title']) < 20) {
+ $prefix = '['.$conf['title'].']';
+ }else{
+ $prefix = '['.utf8_substr($conf['title'], 0, 20).'...]';
+ }
+ }else{
+ $prefix = '['.$conf['mailprefix'].']';
+ }
+ $len = strlen($prefix);
+ if(substr($this->headers['subject'],0,$len) != $prefix){
+ $this->headers['subject'] = $prefix.' '.$this->headers['subject'];
+ }
+
+ // encode subject
+ if(defined('MAILHEADER_ASCIIONLY')){
+ $this->headers['subject'] = utf8_deaccent($this->headers['subject']);
+ $this->headers['subject'] = utf8_strip($this->headers['subject']);
+ }
+ if(!utf8_isASCII($this->headers['Subject'])){
+ $subject = '=?UTF-8?B?'.base64_encode($this->headers['Subject']).'?=';
+ }
+ }
+
+ // wrap headers
+ foreach($this->headers as $key => $val){
+ $this->headers[$key] = wordwrap($val,78,MAILHEADER_EOL.' ');
+ }
+ }
+
+ /**
+ * Create a string from the headers array
+ *
+ * @returns string the headers
+ */
+ protected function prepareHeaders(){
+ $headers = '';
+ foreach($this->headers as $key => $val){
+ $headers .= "$key: $val".MAILHEADER_EOL;
+ }
+ return $headers;
+ }
+
+ /**
+ * return a full email with all headers
+ *
+ * This is mainly intended for debugging and testing but could also be
+ * used for MHT exports
+ *
+ * @return string the mail, false on errors
+ */
+ public function dump(){
+ $this->cleanHeaders();
+ $body = $this->prepareBody();
+ if($body === 'false') return false;
+ $headers = $this->prepareHeaders();
+
+ return $headers.MAILHEADER_EOL.$body;
+ }
+
+ /**
+ * Send the mail
+ *
+ * Call this after all data was set
+ *
+ * @triggers MAIL_MESSAGE_SEND
+ * @return bool true if the mail was successfully passed to the MTA
+ */
+ public function send(){
+ $success = false;
+
+ // prepare hook data
+ $data = array(
+ // pass the whole mail class to plugin
+ 'mail' => $this,
+ // pass references for backward compatibility
+ 'to' => &$this->headers['To'],
+ 'cc' => &$this->headers['Cc'],
+ 'bcc' => &$this->headers['Bcc'],
+ 'from' => &$this->headers['From'],
+ 'subject' => &$this->headers['Subject'],
+ 'body' => &$this->text,
+ 'params' => &$this->sendparams,
+ 'headers' => '', // plugins shouldn't use this
+ // signal if we mailed successfully to AFTER event
+ 'success' => &$success,
+ );
+
+ // do our thing if BEFORE hook approves
+ $evt = new Doku_Event('MAIL_MESSAGE_SEND', $data);
+ if ($evt->advise_before(true)) {
+ // clean up before using the headers
+ $this->cleanHeaders();
+
+ // any recipients?
+ if(trim($this->headers['To']) === '' &&
+ trim($this->headers['Cc']) === '' &&
+ trim($this->headers['Bcc']) === '') return false;
+
+ // The To: header is special
+ if(isset($this->headers['To'])){
+ $to = $this->headers['To'];
+ unset($this->headers['To']);
+ }else{
+ $to = '';
+ }
+
+ // so is the subject
+ if(isset($this->headers['Subject'])){
+ $subject = $this->headers['Subject'];
+ unset($this->headers['Subject']);
+ }else{
+ $subject = '';
+ }
+
+ // make the body
+ $body = $this->prepareBody();
+ if($body === 'false') return false;
+
+ // cook the headers
+ $headers = $this->prepareHeaders();
+ // add any headers set by legacy plugins
+ if(trim($data['headers'])){
+ $headers .= MAILHEADER_EOL.trim($data['headers']);
+ }
+
+ // send the thing
+ if(is_null($this->sendparam)){
+ $success = @mail($to,$subject,$body,$headers);
+ }else{
+ $success = @mail($to,$subject,$body,$headers,$this->sendparam);
+ }
+ }
+ // any AFTER actions?
+ $evt->advise_after();
+ return $success;
+ }
+}
diff --git a/inc/auth.php b/inc/auth.php
index e0f58e5f2..49346a84f 100644
--- a/inc/auth.php
+++ b/inc/auth.php
@@ -667,22 +667,17 @@ function auth_sendPassword($user,$password){
if(!$userinfo['mail']) return false;
$text = rawLocale('password');
- $text = str_replace('@DOKUWIKIURL@',DOKU_URL,$text);
- $text = str_replace('@FULLNAME@',$userinfo['name'],$text);
- $text = str_replace('@LOGIN@',$user,$text);
- $text = str_replace('@PASSWORD@',$password,$text);
- $text = str_replace('@TITLE@',$conf['title'],$text);
-
- if(empty($conf['mailprefix'])) {
- $subject = $lang['regpwmail'];
- } else {
- $subject = '['.$conf['mailprefix'].'] '.$lang['regpwmail'];
- }
+ $trep = array(
+ 'FULLNAME' => $userinfo['name'],
+ 'LOGIN' => $user,
+ 'PASSWORD' => $password
+ );
- return mail_send($userinfo['name'].' <'.$userinfo['mail'].'>',
- $subject,
- $text,
- $conf['mailfrom']);
+ $mail = new Mailer();
+ $mail->to($userinfo['name'].' <'.$userinfo['mail'].'>');
+ $mail->subject($lang['regpwmail']);
+ $mail->setBody($text,$trep);
+ return $mail->send();
}
/**
@@ -912,22 +907,17 @@ function act_resendpwd(){
io_saveFile($tfile,$user);
$text = rawLocale('pwconfirm');
- $text = str_replace('@DOKUWIKIURL@',DOKU_URL,$text);
- $text = str_replace('@FULLNAME@',$userinfo['name'],$text);
- $text = str_replace('@LOGIN@',$user,$text);
- $text = str_replace('@TITLE@',$conf['title'],$text);
- $text = str_replace('@CONFIRM@',$url,$text);
-
- if(empty($conf['mailprefix'])) {
- $subject = $lang['regpwmail'];
- } else {
- $subject = '['.$conf['mailprefix'].'] '.$lang['regpwmail'];
- }
-
- if(mail_send($userinfo['name'].' <'.$userinfo['mail'].'>',
- $subject,
- $text,
- $conf['mailfrom'])){
+ $trep = array(
+ 'FULLNAME' => $userinfo['name'],
+ 'LOGIN' => $user,
+ 'CONFIRM' => $url
+ );
+
+ $mail = new Mailer();
+ $mail->to($userinfo['name'].' <'.$userinfo['mail'].'>');
+ $mail->subject($lang['regpwmail']);
+ $mail->setBody($text,$trep);
+ if($mail->send()){
msg($lang['resendpwdconfirm'],1);
}else{
msg($lang['regmailfail'],-1);
diff --git a/inc/common.php b/inc/common.php
index 0c769c50d..b624c334c 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -1087,7 +1087,7 @@ function notify($id,$who,$rev='',$summary='',$minor=false,$replace=array()){
global $conf;
global $INFO;
- // decide if there is something to do
+ // decide if there is something to do, eg. whom to mail
if($who == 'admin'){
if(empty($conf['notify'])) return; //notify enabled?
$text = rawLocale('mailtext');
@@ -1112,49 +1112,43 @@ function notify($id,$who,$rev='',$summary='',$minor=false,$replace=array()){
return; //just to be safe
}
- $ip = clientIP();
- $text = str_replace('@DATE@',dformat(),$text);
- $text = str_replace('@BROWSER@',$_SERVER['HTTP_USER_AGENT'],$text);
- $text = str_replace('@IPADDRESS@',$ip,$text);
- $text = str_replace('@HOSTNAME@',gethostsbyaddrs($ip),$text);
- $text = str_replace('@NEWPAGE@',wl($id,'',true,'&'),$text);
- $text = str_replace('@PAGE@',$id,$text);
- $text = str_replace('@TITLE@',$conf['title'],$text);
- $text = str_replace('@DOKUWIKIURL@',DOKU_URL,$text);
- $text = str_replace('@SUMMARY@',$summary,$text);
- $text = str_replace('@USER@',$_SERVER['REMOTE_USER'],$text);
- $text = str_replace('@NAME@',$INFO['userinfo']['name'],$text);
- $text = str_replace('@MAIL@',$INFO['userinfo']['mail'],$text);
-
- foreach ($replace as $key => $substitution) {
- $text = str_replace('@'.strtoupper($key).'@',$substitution, $text);
- }
+ // prepare replacements (keys not set in hrep will be taken from trep)
+ $trep = array(
+ 'NEWPAGE' => wl($id,'',true,'&'),
+ 'PAGE' => $id,
+ 'SUMMARY' => $summary
+ );
+ $trep = array_merge($trep,$replace);
+ $hrep = array();
+ // prepare content
if($who == 'register'){
- $subject = $lang['mail_new_user'].' '.$summary;
+ $subject = $lang['mail_new_user'].' '.$summary;
}elseif($rev){
- $subject = $lang['mail_changed'].' '.$id;
- $text = str_replace('@OLDPAGE@',wl($id,"rev=$rev",true,'&'),$text);
- $df = new Diff(explode("\n",rawWiki($id,$rev)),
- explode("\n",rawWiki($id)));
- $dformat = new UnifiedDiffFormatter();
- $diff = $dformat->format($df);
+ $subject = $lang['mail_changed'].' '.$id;
+ $trep['OLDPAGE'] = wl($id,"rev=$rev",true,'&');
+ $df = new Diff(explode("\n",rawWiki($id,$rev)),
+ explode("\n",rawWiki($id)));
+ $dformat = new UnifiedDiffFormatter();
+ $tdiff = $dformat->format($df);
+ $dformat = new InlineDiffFormatter();
+ $hdiff = $dformat->format($df);
}else{
- $subject=$lang['mail_newpage'].' '.$id;
- $text = str_replace('@OLDPAGE@','none',$text);
- $diff = rawWiki($id);
- }
- $text = str_replace('@DIFF@',$diff,$text);
- if(empty($conf['mailprefix'])) {
- if(utf8_strlen($conf['title']) < 20) {
- $subject = '['.$conf['title'].'] '.$subject;
- }else{
- $subject = '['.utf8_substr($conf['title'], 0, 20).'...] '.$subject;
- }
- }else{
- $subject = '['.$conf['mailprefix'].'] '.$subject;
- }
- mail_send($to,$subject,$text,$conf['mailfrom'],'',$bcc);
+ $subject = $lang['mail_newpage'].' '.$id;
+ $trep['OLDPAGE'] = '---';
+ $tdiff = rawWiki($id);
+ $hdiff = nl2br(hsc($tdiff));
+ }
+ $trep['DIFF'] = $tdiff;
+ $hrep['DIFF'] = $hdiff;
+
+ // send mail
+ $mail = new Mailer();
+ $mail->to($to);
+ $mail->bcc($bcc);
+ $mail->subject($subject);
+ $mail->setBody($text,$trep);
+ return $mail->send();
}
/**
diff --git a/inc/load.php b/inc/load.php
index d30397f6e..b5cfd4273 100644
--- a/inc/load.php
+++ b/inc/load.php
@@ -76,6 +76,7 @@ function load_autoload($name){
'SafeFN' => DOKU_INC.'inc/SafeFN.class.php',
'Sitemapper' => DOKU_INC.'inc/Sitemapper.php',
'PassHash' => DOKU_INC.'inc/PassHash.class.php',
+ 'Mailer' => DOKU_INC.'inc/Mailer.class.php',
'DokuWiki_Action_Plugin' => DOKU_PLUGIN.'action.php',
'DokuWiki_Admin_Plugin' => DOKU_PLUGIN.'admin.php',
diff --git a/inc/media.php b/inc/media.php
index 9d3e90a54..4e014877b 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -514,6 +514,7 @@ function media_contentcheck($file,$mime){
* Send a notify mail on uploads
*
* @author Andreas Gohr <andi@splitbrain.org>
+ * @fixme this should embed thumbnails of images in HTML version
*/
function media_notify($id,$file,$mime,$old_rev=false){
global $lang;
@@ -521,31 +522,24 @@ function media_notify($id,$file,$mime,$old_rev=false){
global $INFO;
if(empty($conf['notify'])) return; //notify enabled?
- $ip = clientIP();
-
$text = rawLocale('uploadmail');
- $text = str_replace('@DATE@',dformat(),$text);
- $text = str_replace('@BROWSER@',$_SERVER['HTTP_USER_AGENT'],$text);
- $text = str_replace('@IPADDRESS@',$ip,$text);
- $text = str_replace('@HOSTNAME@',gethostsbyaddrs($ip),$text);
- $text = str_replace('@DOKUWIKIURL@',DOKU_URL,$text);
- $text = str_replace('@USER@',$_SERVER['REMOTE_USER'],$text);
- $text = str_replace('@MIME@',$mime,$text);
- $text = str_replace('@MEDIA@',ml($id,'',true,'&',true),$text);
- $text = str_replace('@SIZE@',filesize_h(filesize($file)),$text);
- if ($old_rev && $conf['mediarevisions']) {
- $text = str_replace('@OLD@', ml($id, "rev=$old_rev", true, '&', true), $text);
- } else {
- $text = str_replace('@OLD@', '', $text);
- }
+ $trep = array(
+ 'MIME' => $mime,
+ 'MEDIA' => ml($id,'',true,'&',true),
+ 'SIZE' => filesize_h(filesize($file)),
+ );
- if(empty($conf['mailprefix'])) {
- $subject = '['.$conf['title'].'] '.$lang['mail_upload'].' '.$id;
+ if ($old_rev && $conf['mediarevisions']) {
+ $trep['OLD'] = ml($id, "rev=$old_rev", true, '&', true);
} else {
- $subject = '['.$conf['mailprefix'].'] '.$lang['mail_upload'].' '.$id;
+ $trep['OLD'] = '---';
}
- mail_send($conf['notify'],$subject,$text,$conf['mailfrom']);
+ $mail = new Mailer();
+ $mail->to($conf['notify']);
+ $mail->subject($lang['mail_upload'].' '.$id);
+ $mail->setBody($text,$trep);
+ return $mail->send();
}
/**
diff --git a/inc/subscription.php b/inc/subscription.php
index c94f17ad0..e9f17bc28 100644
--- a/inc/subscription.php
+++ b/inc/subscription.php
@@ -377,18 +377,16 @@ function subscription_send_list($subscriber_mail, $ids, $ns_id) {
*/
function subscription_send($subscriber_mail, $replaces, $subject, $id, $template) {
global $conf;
+ global $lang;
$text = rawLocale($template);
- $replaces = array_merge($replaces, array('TITLE' => $conf['title'],
- 'DOKUWIKIURL' => DOKU_URL,
- 'PAGE' => $id));
-
- foreach ($replaces as $key => $substitution) {
- $text = str_replace('@'.strtoupper($key).'@', $substitution, $text);
- }
+ $trep = array_merge($replaces, array('PAGE' => $id));
- global $lang;
$subject = $lang['mail_' . $subject] . ' ' . $id;
- mail_send('', '['.$conf['title'].'] '. $subject, $text,
- $conf['mailfrom'], '', $subscriber_mail);
+ $mail = new Mailer();
+ $mail->bcc($subscriber_mail);
+ $mail->subject($subject);
+ $mail->setBody($text,$trep);
+
+ return $mail->send();
}