Skip to content
Snippets Groups Projects
Commit 35992da5 authored by Jared Hancock's avatar Jared Hancock
Browse files

validator: Verify MX record of email addresses

This allows detection of some incorrectly-typed email addresses before
tickets, users, and agents are created.
parent df7c71c8
No related branches found
No related tags found
No related merge requests found
...@@ -718,7 +718,7 @@ class TextboxField extends FormField { ...@@ -718,7 +718,7 @@ class TextboxField extends FormField {
$config = $this->getConfiguration(); $config = $this->getConfiguration();
$validators = array( $validators = array(
'' => null, '' => null,
'email' => array(array('Validator', 'is_email'), 'email' => array(array('Validator', 'is_valid_email'),
__('Enter a valid email address')), __('Enter a valid email address')),
'phone' => array(array('Validator', 'is_phone'), 'phone' => array(array('Validator', 'is_phone'),
__('Enter a valid phone number')), __('Enter a valid phone number')),
......
...@@ -454,7 +454,7 @@ implements EmailContact { ...@@ -454,7 +454,7 @@ implements EmailContact {
if(!$vars['lastname']) if(!$vars['lastname'])
$errors['lastname']=__('Last name is required'); $errors['lastname']=__('Last name is required');
if(!$vars['email'] || !Validator::is_email($vars['email'])) if(!$vars['email'] || !Validator::is_valid_email($vars['email']))
$errors['email']=__('Valid email is required'); $errors['email']=__('Valid email is required');
elseif(Email::getIdByEmail($vars['email'])) elseif(Email::getIdByEmail($vars['email']))
$errors['email']=__('Already in-use as system email'); $errors['email']=__('Already in-use as system email');
......
...@@ -140,7 +140,7 @@ class Validator { ...@@ -140,7 +140,7 @@ class Validator {
/*** Functions below can be called directly without class instance. /*** Functions below can be called directly without class instance.
Validator::func(var..); (nolint) ***/ Validator::func(var..); (nolint) ***/
function is_email($email, $list=false) { function is_email($email, $list=false, $verify=false) {
require_once PEAR_DIR . 'Mail/RFC822.php'; require_once PEAR_DIR . 'Mail/RFC822.php';
require_once PEAR_DIR . 'PEAR.php'; require_once PEAR_DIR . 'PEAR.php';
if (!($mails = Mail_RFC822::parseAddressList($email)) || PEAR::isError($mails)) if (!($mails = Mail_RFC822::parseAddressList($email)) || PEAR::isError($mails))
...@@ -156,8 +156,16 @@ class Validator { ...@@ -156,8 +156,16 @@ class Validator {
return false; return false;
} }
if ($verify && !checkdnsrr($m->host, 'MX'))
return false;
return true; return true;
} }
function is_valid_email($email) {
return self::is_email($email, false, true);
}
function is_phone($phone) { function is_phone($phone) {
/* We're not really validating the phone number but just making sure it doesn't contain illegal chars and of acceptable len */ /* We're not really validating the phone number but just making sure it doesn't contain illegal chars and of acceptable len */
$stripped=preg_replace("(\(|\)|\-|\.|\+|[ ]+)","",$phone); $stripped=preg_replace("(\(|\)|\-|\.|\+|[ ]+)","",$phone);
......
...@@ -33,7 +33,7 @@ if($_POST && !$errors && $filter){ ...@@ -33,7 +33,7 @@ if($_POST && !$errors && $filter){
case 'update': case 'update':
if(!$rule){ if(!$rule){
$errors['err']=sprintf(__('%s: Unknown or invalid'), __('ban rule')); $errors['err']=sprintf(__('%s: Unknown or invalid'), __('ban rule'));
}elseif(!$_POST['val'] || !Validator::is_email($_POST['val'])){ }elseif(!$_POST['val'] || !Validator::is_valid_email($_POST['val'])){
$errors['err']=$errors['val']=__('Valid email address required'); $errors['err']=$errors['val']=__('Valid email address required');
}elseif(!$errors){ }elseif(!$errors){
$vars=array('what'=>'email', $vars=array('what'=>'email',
...@@ -52,7 +52,7 @@ if($_POST && !$errors && $filter){ ...@@ -52,7 +52,7 @@ if($_POST && !$errors && $filter){
case 'add': case 'add':
if(!$filter) { if(!$filter) {
$errors['err']=sprintf(__('%s: Unknown or invalid'), __('ban list')); $errors['err']=sprintf(__('%s: Unknown or invalid'), __('ban list'));
}elseif(!$_POST['val'] || !Validator::is_email($_POST['val'])) { }elseif(!$_POST['val'] || !Validator::is_valid_email($_POST['val'])) {
$errors['err']=$errors['val']=__('Valid email address required'); $errors['err']=$errors['val']=__('Valid email address required');
}elseif(BanList::includes(trim($_POST['val']))) { }elseif(BanList::includes(trim($_POST['val']))) {
$errors['err']=$errors['val']=__('Email already in the ban list'); $errors['err']=$errors['val']=__('Email already in the ban list');
......
...@@ -25,8 +25,8 @@ if($_POST){ ...@@ -25,8 +25,8 @@ if($_POST){
if(!$_POST['email_id'] || !($email=Email::lookup($_POST['email_id']))) if(!$_POST['email_id'] || !($email=Email::lookup($_POST['email_id'])))
$errors['email_id']=__('Select from email address'); $errors['email_id']=__('Select from email address');
if(!$_POST['email'] || !Validator::is_email($_POST['email'])) if(!$_POST['email'] || !Validator::is_valid_email($_POST['email']))
$errors['email']=__('To email address required'); $errors['email']=__('Valid recipient email address required');
if(!$_POST['subj']) if(!$_POST['subj'])
$errors['subj']=__('Subject required'); $errors['subj']=__('Subject required');
......
...@@ -65,7 +65,7 @@ if($_POST && $_POST['s']) { ...@@ -65,7 +65,7 @@ if($_POST && $_POST['s']) {
if(!$_POST['email']) if(!$_POST['email'])
$errors['email'] = __('Required'); $errors['email'] = __('Required');
elseif(!Validator::is_email($_POST['email'])) elseif(!Validator::is_valid_email($_POST['email']))
$errors['email'] = __('Invalid'); $errors['email'] = __('Invalid');
if(!$_POST['alerts'] && !$_POST['news']) if(!$_POST['alerts'] && !$_POST['news'])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment