Skip to content
Permalink
Browse files

Fixing wrap for html mode in e-mails. Fixes #663

  • Loading branch information...
jrbasso committed Jun 21, 2010
1 parent 2a4489c commit 26d20b6d6281b2f796401a6a1f5183dc6b988d32
@@ -356,7 +356,11 @@ function send($content = null, $template = null, $layout = null) {
}
}
$message = $this->_wrap($content);
if ($this->sendAs === 'text') {
$message = $this->_wrap($content);
} else {
$message = $this->_wrap($content, 998);
}
if ($this->template === null) {
$message = $this->_formatMessage($message);
@@ -676,10 +680,11 @@ function _findFiles($attachment) {
* Wrap the message using EmailComponent::$lineLength
*
* @param string $message Message to wrap
* @param integer $lineLength Max length of line
* @return array Wrapped message
* @access private
* @access protected
*/
function _wrap($message) {
function _wrap($message, $lineLength = null) {
$message = $this->_strip($message, true);
$message = str_replace(array("\r\n","\r"), "\n", $message);
$lines = explode("\n", $message);
@@ -690,11 +695,15 @@ function _wrap($message) {
$this->lineLength = $this->_lineLength;
}
if (!$lineLength) {
$lineLength = $this->lineLength;
}
foreach ($lines as $line) {
if (substr($line, 0, 1) == '.') {
$line = '.' . $line;
}
$formatted = array_merge($formatted, explode("\n", wordwrap($line, $this->lineLength, "\n", true)));
$formatted = array_merge($formatted, explode("\n", wordwrap($line, $lineLength, "\n", true)));
}
$formatted[] = '';
return $formatted;
@@ -109,6 +109,16 @@ function getMessage() {
return $this->__message;
}
/**
* Convenience getter for testing.
*
* @access protected
* @return string
*/
function _getMessage() {
return $this->__message;
}
/**
* Convenience method for testing.
*
@@ -1078,4 +1088,35 @@ function testMessageId() {
$this->assertNoPattern('/Message-ID:/', $result);
}
/**
* testSendMessage method
*
* @access public
* @return void
*/
function testSendMessage() {
$this->Controller->EmailTest->delivery = 'getMessage';
$this->Controller->EmailTest->lineLength = 70;
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
$this->Controller->EmailTest->sendAs = 'text';
$result = $this->Controller->EmailTest->send($text);
$expected = array(
'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do',
'eiusmod tempor incididunt ut labore et dolore magna aliqua.',
'',
''
);
$this->assertEqual($expected, $result);
$text = 'Lorem ipsum dolor sit amet, <b>consectetur</b> adipisicing elit, sed do <span>eiusmod tempor</span> incididunt ut labore et dolore magna aliqua.';
$this->Controller->EmailTest->sendAs = 'html';
$result = $this->Controller->EmailTest->send($text);
$expected = array(
$text,
'',
''
);
$this->assertEqual($expected, $result);
}
}

0 comments on commit 26d20b6

Please sign in to comment.
You can’t perform that action at this time.