Skip to content

Commit

Permalink
Adding test cases from 'euromark' and updating how email addresses ar…
Browse files Browse the repository at this point in the history
…e parsed so they are slightly more conformant to RFC 5322. Fixes #1066
  • Loading branch information
markstory committed Sep 2, 2010
1 parent 2809e3c commit 8a43b6d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
13 changes: 5 additions & 8 deletions cake/libs/controller/components/email.php
Expand Up @@ -617,18 +617,15 @@ function __encode($subject) {
* @access private
*/
function __formatAddress($string, $smtp = false) {
if (strpos($string, '<') !== false) {
$value = explode('<', $string);
if ($smtp) {
$string = '<' . $value[1];
} else {
$string = $this->__encode($value[0]) . ' <' . $value[1];
}
$hasAlias = preg_match('/(.+)\s<(.+)>/', $string, $matches);
if ($hasAlias) {
return $this->__strip($matches[1] . ' <' . $matches[2] . '>');
}
return $this->__strip($string);
}
/**
* Remove certain elements (such as bcc:, to:, %0a) from given value
* Remove certain elements (such as bcc:, to:, %0a) from given value.
* Helps prevent header injection / mainipulation on user content.
*
* @param string $value Value to strip
* @param boolean $message Set to true to indicate main message content
Expand Down
28 changes: 28 additions & 0 deletions cake/tests/cases/libs/controller/components/email.test.php
Expand Up @@ -112,6 +112,15 @@ function getMessage() {
function strip($content, $message = false) {
return parent::__strip($content, $message);
}

/**
* Wrapper for testing.
*
* @return void
*/
function formatAddress($string, $smtp = false) {
return parent::__formatAddress($string, $smtp);
}
}
/**
* EmailTestController class
Expand Down Expand Up @@ -665,5 +674,24 @@ function testReset() {
function __osFix($string) {
return str_replace(array("\r\n", "\r"), "\n", $string);
}

/**
* Test that _formatName doesn't jack up email addresses with alias parts.
*
* @return void
*/
function testFormatAddressAliases() {
$result = $this->Controller->EmailTest->formatAddress('email@example.com');
$this->assertEqual($result, 'email@example.com');

$result = $this->Controller->EmailTest->formatAddress('alias <email@example.com>');
$this->assertEqual($result, 'alias <email@example.com>');

$result = $this->Controller->EmailTest->formatAddress('email@example.com');
$this->assertEqual($result, 'email@example.com');

$result = $this->Controller->EmailTest->formatAddress('<email@example.com>');
$this->assertEqual($result, '<email@example.com>');
}
}
?>

0 comments on commit 8a43b6d

Please sign in to comment.