Skip to content
Permalink
Browse files

Change line length in emails.

Use LINE_LENGTH_MUST instead of LINE_LENGTH_SHOULD. This
fixes a number of text wrapping issues caused by the narrower wrap
length.

Fixes #3151
Fixes #3473
  • Loading branch information...
markstory committed Dec 18, 2012
1 parent f326058 commit 7ad11f59bbad6a66a06054dc0daa6bc0a31b7479
Showing with 17 additions and 14 deletions.
  1. +9 −6 lib/Cake/Network/Email/CakeEmail.php
  2. +8 −8 lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
@@ -1237,7 +1237,7 @@ protected function _encodeString($text, $charset) {
* @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 @@ protected function _wrap($message) {
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 @@ protected function _wrap($message) {
$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 @@ protected function _wrap($message) {
$tmpLine = '';
$tmpLineLength = 0;
}
if ($tagLength > self::LINE_LENGTH_SHOULD) {
if ($tagLength > $wrapLength) {
$formatted[] = $tag;
} else {
$tmpLine = $tag;
@@ -1287,14 +1290,14 @@ protected function _wrap($message) {
$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);
@@ -42,8 +42,8 @@ public function formatAddress($address) {
* 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 @@ public function testResetWithCharset() {
*/
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 @@ public function testWrap() {
$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 @@ public function testWrap() {
$this->assertSame($expected, $result);
$text = '<p>Lorem ipsum dolor sit amet,<br> consectetur adipiscing elit.<br> Donec ac turpis orci, non <b>commodo</b> odio. <br /> Morbi nibh nisi, vehicula pellentesque accumsan amet.<hr></p>';
$result = $this->CakeEmail->wrap($text);
$result = $this->CakeEmail->wrap($text, CakeEmail::LINE_LENGTH_SHOULD);
$expected = array(
'<p>Lorem ipsum dolor sit amet,<br> consectetur adipiscing elit.<br> Donec ac',
'turpis orci, non <b>commodo</b> odio. <br /> Morbi nibh nisi, vehicula',
@@ -1383,7 +1383,7 @@ public function testWrap() {
$this->assertSame($expected, $result);
$text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac <a href="http://cakephp.org">turpis</a> 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',
'<a href="http://cakephp.org">turpis</a> orci, non commodo odio. Morbi nibh',
@@ -1393,7 +1393,7 @@ public function testWrap() {
$this->assertSame($expected, $result);
$text = 'Lorem ipsum <a href="http://www.cakephp.org/controller/action/param1/param2" class="nice cool fine amazing awesome">ok</a>';
$result = $this->CakeEmail->wrap($text);
$result = $this->CakeEmail->wrap($text, CakeEmail::LINE_LENGTH_SHOULD);
$expected = array(
'Lorem ipsum',
'<a href="http://www.cakephp.org/controller/action/param1/param2" class="nice cool fine amazing awesome">',
@@ -1403,7 +1403,7 @@ public function testWrap() {
$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',

0 comments on commit 7ad11f5

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.