diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php
index 4397a5f3862..b341f396596 100755
--- a/cake/libs/controller/components/email.php
+++ b/cake/libs/controller/components/email.php
@@ -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;
diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php
index 512dfe97e3d..521a3fbb9e0 100755
--- a/cake/tests/cases/libs/controller/components/email.test.php
+++ b/cake/tests/cases/libs/controller/components/email.test.php
@@ -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, consectetur adipisicing elit, sed do eiusmod tempor 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);
+ }
}