handle mailfrom replacements in a central place FS#2091

This commit is contained in:
Andreas Gohr 2010-11-05 11:18:31 +01:00
parent 317d85c9da
commit 5ec3fefc5f
4 changed files with 37 additions and 12 deletions

View File

@ -1134,12 +1134,7 @@ function notify($id,$who,$rev='',$summary='',$minor=false,$replace=array()){
$subject = '['.utf8_substr($conf['title'], 0, 20).'...] '.$subject;
}
$from = $conf['mailfrom'];
$from = str_replace('@USER@',$_SERVER['REMOTE_USER'],$from);
$from = str_replace('@NAME@',$INFO['userinfo']['name'],$from);
$from = str_replace('@MAIL@',$INFO['userinfo']['mail'],$from);
mail_send($to,$subject,$text,$from,'',$bcc);
mail_send($to,$subject,$text,$conf['mailfrom'],'',$bcc);
}
/**

View File

@ -220,6 +220,9 @@ if (!defined('NOSESSION')) {
auth_setup();
}
// setup mail system
mail_setup();
/**
* Checks paths from config file
*/

View File

@ -30,7 +30,39 @@ if(!defined('QUOTEDPRINTABLE_EOL')) define('QUOTEDPRINTABLE_EOL',"\015\012");
if (!defined('RFC2822_ATEXT')) define('RFC2822_ATEXT',"0-9a-zA-Z!#$%&'*+/=?^_`{|}~-");
if (!defined('PREG_PATTERN_VALID_EMAIL')) define('PREG_PATTERN_VALID_EMAIL', '['.RFC2822_ATEXT.']+(?:\.['.RFC2822_ATEXT.']+)*@(?i:[0-9a-z][0-9a-z-]*\.)+(?i:[a-z]{2,4}|museum|travel)');
/**
* Prepare mailfrom replacement patterns
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function mail_setup(){
global $conf;
global $INFO;
$replace = array();
if(!empty($INFO['userinfo']['mail'])){
$replace['@MAIL@'] = $INFO['userinfo']['mail'];
}else{
$replace['@MAIL@'] = 'noreply@'.parse_url(DOKU_URL,PHP_URL_HOST);
}
if(!empty($_SERVER['REMOTE_USER'])){
$replace['@USER@'] = $_SERVER['REMOTE_USER'];
}else{
$replace['@USER@'] = 'noreply';
}
if(!empty($INFO['userinfo']['name'])){
$replace['@NAME@'] = $INFO['userinfo']['name'];
}else{
$replace['@NAME@'] = '';
}
$conf['mailfrom'] = str_replace(array_keys($replace),
array_values($replace),
$conf['mailfrom']);
}
/**
* UTF-8 autoencoding replacement for PHPs mail function

View File

@ -407,14 +407,9 @@ function media_notify($id,$file,$mime){
$text = str_replace('@MEDIA@',ml($id,'',true,'&',true),$text);
$text = str_replace('@SIZE@',filesize_h(filesize($file)),$text);
$from = $conf['mailfrom'];
$from = str_replace('@USER@',$_SERVER['REMOTE_USER'],$from);
$from = str_replace('@NAME@',$INFO['userinfo']['name'],$from);
$from = str_replace('@MAIL@',$INFO['userinfo']['mail'],$from);
$subject = '['.$conf['title'].'] '.$lang['mail_upload'].' '.$id;
mail_send($conf['notify'],$subject,$text,$from);
mail_send($conf['notify'],$subject,$text,$conf['mailfrom']);
}
/**