mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-18 23:49:55 +00:00
CakeEmail be able to setting custom email validation rule
This commit is contained in:
parent
202b753c63
commit
175280ad79
2 changed files with 45 additions and 4 deletions
|
@ -554,7 +554,7 @@ class CakeEmail {
|
||||||
*/
|
*/
|
||||||
protected function _setEmail($varName, $email, $name) {
|
protected function _setEmail($varName, $email, $name) {
|
||||||
if (!is_array($email)) {
|
if (!is_array($email)) {
|
||||||
if (!Validation::email($email)) {
|
if (!Validation::email($email, false, $this->_emailRegex)) {
|
||||||
throw new SocketException(__d('cake_dev', 'Invalid email: "%s"', $email));
|
throw new SocketException(__d('cake_dev', 'Invalid email: "%s"', $email));
|
||||||
}
|
}
|
||||||
if ($name === null) {
|
if ($name === null) {
|
||||||
|
@ -568,7 +568,7 @@ class CakeEmail {
|
||||||
if (is_int($key)) {
|
if (is_int($key)) {
|
||||||
$key = $value;
|
$key = $value;
|
||||||
}
|
}
|
||||||
if (!Validation::email($key)) {
|
if (!Validation::email($key, false, $this->_emailRegex)) {
|
||||||
throw new SocketException(__d('cake_dev', 'Invalid email: "%s"', $key));
|
throw new SocketException(__d('cake_dev', 'Invalid email: "%s"', $key));
|
||||||
}
|
}
|
||||||
$list[$key] = $value;
|
$list[$key] = $value;
|
||||||
|
@ -608,7 +608,7 @@ class CakeEmail {
|
||||||
*/
|
*/
|
||||||
protected function _addEmail($varName, $email, $name) {
|
protected function _addEmail($varName, $email, $name) {
|
||||||
if (!is_array($email)) {
|
if (!is_array($email)) {
|
||||||
if (!Validation::email($email)) {
|
if (!Validation::email($email, false, $this->_emailRegex)) {
|
||||||
throw new SocketException(__d('cake_dev', 'Invalid email: "%s"', $email));
|
throw new SocketException(__d('cake_dev', 'Invalid email: "%s"', $email));
|
||||||
}
|
}
|
||||||
if ($name === null) {
|
if ($name === null) {
|
||||||
|
@ -622,7 +622,7 @@ class CakeEmail {
|
||||||
if (is_int($key)) {
|
if (is_int($key)) {
|
||||||
$key = $value;
|
$key = $value;
|
||||||
}
|
}
|
||||||
if (!Validation::email($key)) {
|
if (!Validation::email($key, false, $this->_emailRegex)) {
|
||||||
throw new SocketException(__d('cake_dev', 'Invalid email: "%s"', $key));
|
throw new SocketException(__d('cake_dev', 'Invalid email: "%s"', $key));
|
||||||
}
|
}
|
||||||
$list[$key] = $value;
|
$list[$key] = $value;
|
||||||
|
|
|
@ -286,6 +286,47 @@ class CakeEmailTest extends CakeTestCase {
|
||||||
$this->assertSame($regex, $email->emailRegex());
|
$this->assertSame($regex, $email->emailRegex());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that it is possible set custom email validation
|
||||||
|
*/
|
||||||
|
public function testCustomEmailValidation() {
|
||||||
|
$regex = '/^[\.a-z0-9!#$%&\'*+\/=?^_`{|}~-]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]{2,6}$/i';
|
||||||
|
|
||||||
|
$this->CakeEmail->emailRegex($regex)->to('pass.@example.com');
|
||||||
|
$this->assertSame(array(
|
||||||
|
'pass.@example.com' => 'pass.@example.com',
|
||||||
|
), $this->CakeEmail->to());
|
||||||
|
|
||||||
|
$this->CakeEmail->addTo('pass..old.docomo@example.com');
|
||||||
|
$this->assertSame(array(
|
||||||
|
'pass.@example.com' => 'pass.@example.com',
|
||||||
|
'pass..old.docomo@example.com' => 'pass..old.docomo@example.com',
|
||||||
|
), $this->CakeEmail->to());
|
||||||
|
|
||||||
|
$this->CakeEmail->reset();
|
||||||
|
$emails = array(
|
||||||
|
'pass.@example.com',
|
||||||
|
'pass..old.docomo@example.com'
|
||||||
|
);
|
||||||
|
$additionalEmails = array(
|
||||||
|
'.extend.@example.com',
|
||||||
|
'.docomo@example.com'
|
||||||
|
);
|
||||||
|
$this->CakeEmail->emailRegex($regex)->to($emails);
|
||||||
|
$this->assertSame(array(
|
||||||
|
'pass.@example.com' => 'pass.@example.com',
|
||||||
|
'pass..old.docomo@example.com' => 'pass..old.docomo@example.com',
|
||||||
|
), $this->CakeEmail->to());
|
||||||
|
|
||||||
|
$this->CakeEmail->addTo($additionalEmails);
|
||||||
|
$this->assertSame(array(
|
||||||
|
'pass.@example.com' => 'pass.@example.com',
|
||||||
|
'pass..old.docomo@example.com' => 'pass..old.docomo@example.com',
|
||||||
|
'.extend.@example.com' => '.extend.@example.com',
|
||||||
|
'.docomo@example.com' => '.docomo@example.com',
|
||||||
|
), $this->CakeEmail->to());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testFormatAddress method
|
* testFormatAddress method
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue