Skip to content

Commit

Permalink
allow richer email addresses in notify and registernotify FS#2689
Browse files Browse the repository at this point in the history
This deprecates the "richemail" config class
  • Loading branch information
splitbrain committed Feb 16, 2013
1 parent 6a1f928 commit a9b6a8b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 52 deletions.
85 changes: 38 additions & 47 deletions lib/plugins/config/settings/config.class.php
Expand Up @@ -79,7 +79,7 @@ function retrieve_settings() {
array_shift($param);
} else {
$class = 'setting_undefined';
$param = NULL;
$param = null;
}

if (!in_array($class, $no_default_check) && !isset($default[$key])) {
Expand Down Expand Up @@ -353,21 +353,21 @@ function get_plugintpl_default($tpl){
class setting {

var $_key = '';
var $_default = NULL;
var $_local = NULL;
var $_protected = NULL;
var $_default = null;
var $_local = null;
var $_protected = null;

var $_pattern = '';
var $_error = false; // only used by those classes which error check
var $_input = NULL; // only used by those classes which error check
var $_input = null; // only used by those classes which error check

var $_cautionList = array(
'basedir' => 'danger', 'baseurl' => 'danger', 'savedir' => 'danger', 'cookiedir' => 'danger', 'useacl' => 'danger', 'authtype' => 'danger', 'superuser' => 'danger', 'userewrite' => 'danger',
'start' => 'warning', 'camelcase' => 'warning', 'deaccent' => 'warning', 'sepchar' => 'warning', 'compression' => 'warning', 'xsendfile' => 'warning', 'renderer_xhtml' => 'warning', 'fnencode' => 'warning',
'allowdebug' => 'security', 'htmlok' => 'security', 'phpok' => 'security', 'iexssprotect' => 'security', 'xmlrpc' => 'security', 'fullpath' => 'security'
);

function setting($key, $params=NULL) {
function setting($key, $params=null) {
$this->_key = $key;

if (is_array($params)) {
Expand Down Expand Up @@ -656,6 +656,7 @@ function html(&$plugin, $echo=false) {
class setting_email extends setting_string {
var $_pattern = SETTING_EMAIL_PATTERN; // no longer required, retained for backward compatibility - FIXME, may not be necessary
var $_multiple = false;
var $_placeholders = false;

/**
* update setting with user provided value $input
Expand All @@ -669,15 +670,36 @@ function update($input) {

$value = is_null($this->_local) ? $this->_default : $this->_local;
if ($value == $input) return false;
if($input === ''){
$this->_local = $input;
return true;
}
$mail = $input;

if($this->_placeholders){
// replace variables with pseudo values
$mail = str_replace('@USER@','joe',$mail);
$mail = str_replace('@NAME@','Joe Schmoe',$mail);
$mail = str_replace('@MAIL@','joe@example.com',$mail);
}

// multiple mail addresses?
if ($this->_multiple) {
$mails = array_filter(array_map('trim', explode(',', $input)));
$mails = array_filter(array_map('trim', explode(',', $mail)));
} else {
$mails = array($input);
$mails = array($mail);
}

// check them all
foreach ($mails as $mail) {
if (!mail_isvalid($mail)) {
// only check the address part
if(preg_match('#(.*?)<(.*?)>#', $mail, $matches)){
$addr = $matches[2];
}else{
$addr = $mail;
}

if (!mail_isvalid($addr)) {
$this->_error = true;
$this->_input = $input;
return false;
Expand All @@ -690,46 +712,15 @@ function update($input) {
}
}

/**
* @deprecated 2013-02-16
*/
if (!class_exists('setting_richemail')) {
class setting_richemail extends setting_email {

/**
* update setting with user provided value $input
* if value fails error check, save it
*
* @return boolean true if changed, false otherwise (incl. on error)
*/
function update($input) {
if (is_null($input)) return false;
if ($this->is_protected()) return false;

$value = is_null($this->_local) ? $this->_default : $this->_local;
if ($value == $input) return false;

// replace variables with pseudo values
$test = $input;
$test = str_replace('@USER@','joe',$test);
$test = str_replace('@NAME@','Joe Schmoe',$test);
$test = str_replace('@MAIL@','joe@example.com',$test);

// now only check the address part
if(preg_match('#(.*?)<(.*?)>#',$test,$matches)){
$text = trim($matches[1]);
$addr = $matches[2];
}else{
$addr = $test;
}

if ($test !== '' && !mail_isvalid($addr)) {
$this->_error = true;
$this->_input = $input;
return false;
}

$this->_local = $input;
return true;
}

function update($input) {
$this->_placeholders = true;
return parent::update($input);
}
}
}

Expand Down
8 changes: 3 additions & 5 deletions lib/plugins/config/settings/config.metadata.php
Expand Up @@ -20,9 +20,7 @@
* 'numericopt' - like above, but accepts empty values
* 'onoff' - checkbox input, setting output 0|1
* 'multichoice' - select input (single choice), setting output with quotes, required _choices parameter
* 'email' - text input, input must conform to email address format, setting output in quotes
* 'richemail' - text input, input must conform to email address format but accepts variables and
* emails with a real name prepended (when email address is given in <>)
* 'email' - text input, input must conform to email address format
* 'password' - password input, minimal input validation, setting output text in quotes, maybe encoded
* according to the _code parameter
* 'dirchoice' - as multichoice, selection choices based on folders found at location specified in _dir
Expand Down Expand Up @@ -177,8 +175,8 @@
$meta['subscribers'] = array('onoff');
$meta['subscribe_time'] = array('numeric');
$meta['notify'] = array('email', '_multiple' => true);
$meta['registernotify'] = array('email');
$meta['mailfrom'] = array('richemail');
$meta['registernotify'] = array('email', '_multiple' => true);
$meta['mailfrom'] = array('email', '_placeholders' => true);
$meta['mailprefix'] = array('string');
$meta['htmlmail'] = array('onoff');

Expand Down

0 comments on commit a9b6a8b

Please sign in to comment.