diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index 9bf4d434e..8237284bb 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -1237,7 +1237,7 @@ class CakeEmail { * @param string $message Message to wrap * @return array Wrapped message */ - protected function _wrap($message) { + protected function _wrap($message, $wrapLength = CakeEmail::LINE_LENGTH_MUST) { $message = str_replace(array("\r\n", "\r"), "\n", $message); $lines = explode("\n", $message); $formatted = array(); @@ -1248,7 +1248,10 @@ class CakeEmail { continue; } if (!preg_match('/\<[a-z]/i', $line)) { - $formatted = array_merge($formatted, explode("\n", wordwrap($line, self::LINE_LENGTH_SHOULD, "\n"))); + $formatted = array_merge( + $formatted, + explode("\n", wordwrap($line, $wrapLength, "\n")) + ); continue; } @@ -1261,7 +1264,7 @@ class CakeEmail { $tag .= $char; if ($char === '>') { $tagLength = strlen($tag); - if ($tagLength + $tmpLineLength < self::LINE_LENGTH_SHOULD) { + if ($tagLength + $tmpLineLength < $wrapLength) { $tmpLine .= $tag; $tmpLineLength += $tagLength; } else { @@ -1270,7 +1273,7 @@ class CakeEmail { $tmpLine = ''; $tmpLineLength = 0; } - if ($tagLength > self::LINE_LENGTH_SHOULD) { + if ($tagLength > $wrapLength) { $formatted[] = $tag; } else { $tmpLine = $tag; @@ -1287,14 +1290,14 @@ class CakeEmail { $tag = '<'; continue; } - if ($char === ' ' && $tmpLineLength >= self::LINE_LENGTH_SHOULD) { + if ($char === ' ' && $tmpLineLength >= $wrapLength) { $formatted[] = $tmpLine; $tmpLineLength = 0; continue; } $tmpLine .= $char; $tmpLineLength++; - if ($tmpLineLength === self::LINE_LENGTH_SHOULD) { + if ($tmpLineLength === $wrapLength) { $nextChar = $line[$i + 1]; if ($nextChar === ' ' || $nextChar === '<') { $formatted[] = trim($tmpLine); diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index c4c7a814d..921d33155 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -42,8 +42,8 @@ class TestCakeEmail extends CakeEmail { * Wrap to protected method * */ - public function wrap($text) { - return parent::_wrap($text); + public function wrap($text, $length = CakeEmail::LINE_LENGTH_MUST) { + return parent::_wrap($text, $length); } /** @@ -1354,7 +1354,7 @@ class CakeEmailTest extends CakeTestCase { */ public function testWrap() { $text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac turpis orci, non commodo odio. Morbi nibh nisi, vehicula pellentesque accumsan amet.'; - $result = $this->CakeEmail->wrap($text); + $result = $this->CakeEmail->wrap($text, CakeEmail::LINE_LENGTH_SHOULD); $expected = array( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac turpis orci,', 'non commodo odio. Morbi nibh nisi, vehicula pellentesque accumsan amet.', @@ -1363,7 +1363,7 @@ class CakeEmailTest extends CakeTestCase { $this->assertSame($expected, $result); $text = 'Lorem ipsum dolor sit amet, consectetur < adipiscing elit. Donec ac turpis orci, non commodo odio. Morbi nibh nisi, vehicula > pellentesque accumsan amet.'; - $result = $this->CakeEmail->wrap($text); + $result = $this->CakeEmail->wrap($text, CakeEmail::LINE_LENGTH_SHOULD); $expected = array( 'Lorem ipsum dolor sit amet, consectetur < adipiscing elit. Donec ac turpis', 'orci, non commodo odio. Morbi nibh nisi, vehicula > pellentesque accumsan', @@ -1373,7 +1373,7 @@ class CakeEmailTest extends CakeTestCase { $this->assertSame($expected, $result); $text = '
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Donec ac turpis orci, non commodo odio.
Morbi nibh nisi, vehicula pellentesque accumsan amet.
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Donec ac',
'turpis orci, non commodo odio.
Morbi nibh nisi, vehicula',
@@ -1383,7 +1383,7 @@ class CakeEmailTest extends CakeTestCase {
$this->assertSame($expected, $result);
$text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac turpis orci, non commodo odio. Morbi nibh nisi, vehicula pellentesque accumsan amet.';
- $result = $this->CakeEmail->wrap($text);
+ $result = $this->CakeEmail->wrap($text, CakeEmail::LINE_LENGTH_SHOULD);
$expected = array(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac',
'turpis orci, non commodo odio. Morbi nibh',
@@ -1393,7 +1393,7 @@ class CakeEmailTest extends CakeTestCase {
$this->assertSame($expected, $result);
$text = 'Lorem ipsum ok';
- $result = $this->CakeEmail->wrap($text);
+ $result = $this->CakeEmail->wrap($text, CakeEmail::LINE_LENGTH_SHOULD);
$expected = array(
'Lorem ipsum',
'',
@@ -1403,7 +1403,7 @@ class CakeEmailTest extends CakeTestCase {
$this->assertSame($expected, $result);
$text = 'Lorem ipsum withonewordverybigMorethanthelineshouldsizeofrfcspecificationbyieeeavailableonieeesite ok.';
- $result = $this->CakeEmail->wrap($text);
+ $result = $this->CakeEmail->wrap($text, CakeEmail::LINE_LENGTH_SHOULD);
$expected = array(
'Lorem ipsum',
'withonewordverybigMorethanthelineshouldsizeofrfcspecificationbyieeeavailableonieeesite',