From 3a4bb9d5b60597f13681e43dff1a37b3a2966735 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 27 Apr 2009 01:13:46 +0200 Subject: FS#1680 - improve email address validation in config plugin - setting_email and setting_richemail updated to use mail_isvalid() from inc/mail.php - _pattern improved if any plugin extends either class for its own settings (this maybe over cautious. Its probably very unlikely that any plugin does this). darcs-hash:20090426231346-f07c6-2af83d890ff4d92b14637ef6024d3fb68ba97efd.gz --- lib/plugins/config/settings/config.class.php | 31 ++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/plugins/config/settings/config.class.php b/lib/plugins/config/settings/config.class.php index 81d9224f5..ce9409438 100644 --- a/lib/plugins/config/settings/config.class.php +++ b/lib/plugins/config/settings/config.class.php @@ -528,8 +528,35 @@ if (!class_exists('setting_password')) { } if (!class_exists('setting_email')) { + + require_once(DOKU_INC.'inc/mail.php'); + if (!defined('SETTING_EMAIL_PATTERN')) define('SETTING_EMAIL_PATTERN','<^'.PREG_PATTERN_VALID_EMAIL.'$>'); + class setting_email extends setting_string { - var $_pattern = '#^\s*(([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)(,\s*([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+))*)?\s*$#i'; + var $_pattern = SETTING_EMAIL_PATTERN; // no longer required, retained for backward compatibility - FIXME, may not be necessary + + /** + * update setting with user provided value $input + * if value fails error check, save it + * + * @return 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; + + if (!mail_isvalid($input)) { + $this->_error = true; + $this->_input = $input; + return false; + } + + $this->_local = $input; + return true; + } } } @@ -563,7 +590,7 @@ if (!class_exists('setting_richemail')) { $addr = $test; } - if ($this->_pattern && !preg_match($this->_pattern,$addr)) { + if (!mail_isvalid($addr)) { $this->_error = true; $this->_input = $input; return false; -- cgit v1.2.3