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
This commit is contained in:
mark_story 2012-12-17 20:54:38 -05:00
parent f326058a6d
commit 7ad11f59bb
2 changed files with 17 additions and 14 deletions

View file

@ -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);

View file

@ -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 = '<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 @@ class CakeEmailTest extends CakeTestCase {
$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 @@ class CakeEmailTest extends CakeTestCase {
$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 @@ 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',