Skip to content

Commit

Permalink
handle mailfrom replacements in a central place FS#2091
Browse files Browse the repository at this point in the history
  • Loading branch information
splitbrain committed Nov 5, 2010
1 parent 317d85c commit 5ec3fef
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
7 changes: 1 addition & 6 deletions inc/common.php
Expand Up @@ -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);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions inc/init.php
Expand Up @@ -220,6 +220,9 @@ function_exists('ob_gzhandler')) {
auth_setup();
}

// setup mail system
mail_setup();

/**
* Checks paths from config file
*/
Expand Down
32 changes: 32 additions & 0 deletions inc/mail.php
Expand Up @@ -30,7 +30,39 @@
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
Expand Down
7 changes: 1 addition & 6 deletions inc/media.php
Expand Up @@ -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']);
}

/**
Expand Down

2 comments on commit 5ec3fef

@senorandy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Andi...as a result of this commit it looks like my @mail@ setting in mailfrom doesn´t work anymore... All mails are now sent out with noreply e-mail address. I use swiftmail and authentication backend ad, is this a known issue? .. Cheers, Andy

@splitbrain
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it isn't. please open a bug report with the swiftmail plugin

Please sign in to comment.