Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add emailRegex property to CakeEmail

  • Loading branch information...
commit 202b753c63703ea513744a060f7a60ae64a0a090 1 parent 6fdbdf5
@nojimage nojimage authored
View
25 lib/Cake/Network/Email/CakeEmail.php
@@ -319,6 +319,14 @@ class CakeEmail {
);
/**
+ * Regex for email validation
+ * If null, it will use built in regex
+ *
+ * @var string
+ */
+ protected $_emailRegex = null;
+
+/**
* Constructor
*
* @param array|string $config Array of configs, or string to load configs from email.php
@@ -522,6 +530,20 @@ public function headerCharset($charset = null) {
}
/**
+ * EmailRegex setter/getter
+ *
+ * @param string $regexp
+ * @return string|CakeEmail
+ */
+ public function emailRegex($regex = false) {
+ if ($regex === false) {
+ return $this->_emailRegex;
+ }
+ $this->_emailRegex = $regex;
+ return $this;
+ }
+
+/**
* Set email
*
* @param string $varName
@@ -1161,7 +1183,7 @@ protected function _applyConfig($config) {
$simpleMethods = array(
'from', 'sender', 'to', 'replyTo', 'readReceipt', 'returnPath', 'cc', 'bcc',
'messageId', 'domain', 'subject', 'viewRender', 'viewVars', 'attachments',
- 'transport', 'emailFormat', 'theme', 'helpers'
+ 'transport', 'emailFormat', 'theme', 'helpers', 'emailRegex'
);
foreach ($simpleMethods as $method) {
if (isset($config[$method])) {
@@ -1218,6 +1240,7 @@ public function reset() {
$this->headerCharset = null;
$this->_attachments = array();
$this->_config = array();
+ $this->_emailRegex = null;
return $this;
}
View
24 lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
@@ -265,6 +265,28 @@ public function testInvalidEmailAdd($value) {
}
/**
+ * test emailRegex method
+ *
+ * @return void
+ */
+ public function testEmailRegex() {
+ $regex = '/.+@.+\..+/i';
+ $this->assertNull($this->CakeEmail->emailRegex());
+ $this->assertSame($regex, $this->CakeEmail->emailRegex($regex)->emailRegex());
+ }
+
+/**
+ * Tests that it is possible to set email regex configuration to a CakeEmail object
+ *
+ * @return void
+ */
+ public function testConfigEmailRegex() {
+ $regex = '/.+@.+\..+/i';
+ $email = new CakeEmail(array('emailRegex' => $regex));
+ $this->assertSame($regex, $email->emailRegex());
+ }
+
+/**
* testFormatAddress method
*
* @return void
@@ -1427,11 +1449,13 @@ public function testMessage() {
public function testReset() {
$this->CakeEmail->to('cake@cakephp.org');
$this->CakeEmail->theme('TestTheme');
+ $this->CakeEmail->emailRegex('/.+@.+\..+/i');
$this->assertSame($this->CakeEmail->to(), array('cake@cakephp.org' => 'cake@cakephp.org'));
$this->CakeEmail->reset();
$this->assertSame($this->CakeEmail->to(), array());
$this->assertSame(null, $this->CakeEmail->theme());
+ $this->assertSame(null, $this->CakeEmail->emailRegex());
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.