Permalink
Browse files

Adding test cases from 'euromark' and updating how email addresses ar…

…e parsed so they are slightly more conformant to RFC 5322. Fixes #1066
  • Loading branch information...
1 parent 2809e3c commit 8a43b6d31664068e27c527ae788ac6b6301d3d3a @markstory markstory committed Sep 2, 2010
@@ -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
@@ -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
@@ -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.