$count = CRM_Memberdashboard_BAO_EmailAlias::countForContact($contactId);
if(CRM_Utils_Rule::email($forward)) {
- if($count < MEMBERDASHBOARD_MAX_EMAIL_ALIASES) {
- try {
- $params = array(
- 'contact_id' => $contactId,
- 'localpart' => $localpart,
- 'forward' => $forward
- );
- CRM_Memberdashboard_BAO_EmailAlias::create($params);
- CRM_Core_Session::setStatus('Email alias added!',
- 'Success', 'success');
- } catch (Exception $e) {
- CRM_Core_Session::setStatus('Failed to create email alias',
+ if(CRM_Utils_Rule::email("$localpart@example.com")) {
+ if($count < MEMBERDASHBOARD_MAX_EMAIL_ALIASES) {
+ try {
+ $params = array(
+ 'contact_id' => $contactId,
+ 'localpart' => $localpart,
+ 'forward' => $forward
+ );
+ CRM_Memberdashboard_BAO_EmailAlias::create($params);
+ CRM_Core_Session::setStatus('Email alias added!',
+ 'Success', 'success');
+ } catch (Exception $e) {
+ CRM_Core_Session::setStatus('Failed to create email alias',
+ 'Error', 'error');
+ }
+ } else {
+ CRM_Core_Session::setStatus('You cannot have more than 5 email aliases',
'Error', 'error');
}
} else {
- CRM_Core_Session::setStatus('You cannot have more than 5 email aliases',
+ CRM_Core_Session::setStatus('Invalid local part',
'Error', 'error');
}
} else {
if($alias->contactId != $this->contact['id']) {
$error .= '<li>You cannot alter email aliases that don\'t belong to you!</li>';
} else if(CRM_Utils_Rule::email($forward)) {
- $alias->localpart = $localpart;
- $alias->forward = $forward;
- $alias->save();
+ if(CRM_Utils_Rule::email("$localpart@example.com")) {
+ $alias->localpart = $localpart;
+ $alias->forward = $forward;
+ $alias->save();
+ } else {
+ $error .= "<li>Invalid local part: $localpart</li>";
+ }
} else {
$error .= "<li>Invalid email forwarding address: $forward</li>";
}