From 3e14d281dfe3fe0e361d91af39740824ea690351 Mon Sep 17 00:00:00 2001 From: DarkAngelBGE Date: Wed, 22 Jul 2009 16:04:53 +0000 Subject: [PATCH] fixes #6397, removing unneeded line feed in email component headers, adding tests git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8248 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/components/email.php | 3 +- .../libs/controller/components/email.test.php | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index 1203ac20c..e4b250deb 100644 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -491,7 +491,6 @@ class EmailComponent extends Object{ $this->__header[] = 'Content-Type: text/html; charset=' . $this->charset; } elseif ($this->sendAs === 'both') { $this->__header[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"'; - $this->__header[] = ''; } $this->__header[] = 'Content-Transfer-Encoding: 7bit'; @@ -504,7 +503,7 @@ class EmailComponent extends Object{ */ function __formatMessage($message) { if (!empty($this->attachments)) { - $prefix[] = '--' . $this->__boundary; + $prefix = array('--' . $this->__boundary); if ($this->sendAs === 'text') { $prefix[] = 'Content-Type: text/plain; charset=' . $this->charset; } elseif ($this->sendAs === 'html') { diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php index 3527e7616..27086ecce 100644 --- a/cake/tests/cases/libs/controller/components/email.test.php +++ b/cake/tests/cases/libs/controller/components/email.test.php @@ -337,7 +337,8 @@ MSGBLOC; // TODO: better test for format of message sent? $this->Controller->EmailTest->sendAs = 'both'; - $expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"' . "\n", $message); + $expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"', $message); + $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message')); $this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect)); } @@ -412,10 +413,11 @@ HTMLBLOC; $this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect)); $this->Controller->EmailTest->sendAs = 'both'; - $expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"' . "\n", $header); + $expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"', $header); $expect .= '--alt-' . "\n" . 'Content-Type: text/plain; charset=UTF-8' . "\n" . 'Content-Transfer-Encoding: 7bit' . "\n\n" . $text . "\n\n"; $expect .= '--alt-' . "\n" . 'Content-Type: text/html; charset=UTF-8' . "\n" . 'Content-Transfer-Encoding: 7bit' . "\n\n" . $html . "\n\n"; $expect = '
' . $expect . '--alt---' . "\n\n" . '
'; + $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message')); $this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect)); @@ -588,10 +590,34 @@ TEXTBLOC; $this->Controller->EmailTest->sendAs = 'both'; $this->assertTrue($this->Controller->EmailTest->send($body)); $msg = $this->Controller->Session->read('Message.email.message'); + $this->assertNoPattern('/text\/plain/', $msg); $this->assertNoPattern('/text\/html/', $msg); $this->assertPattern('/multipart\/alternative/', $msg); } +/** + * undocumented function + * + * @return void + * @access public + */ + function testNoDoubleNewlinesInHeaders() { + $this->Controller->EmailTest->reset(); + $this->Controller->EmailTest->to = 'postmaster@localhost'; + $this->Controller->EmailTest->from = 'noreply@example.com'; + $this->Controller->EmailTest->subject = 'Attachment Test'; + $this->Controller->EmailTest->replyTo = 'noreply@example.com'; + $this->Controller->EmailTest->template = null; + $this->Controller->EmailTest->delivery = 'debug'; + $body = '

This is the body of the message

'; + + $this->Controller->EmailTest->sendAs = 'both'; + $this->assertTrue($this->Controller->EmailTest->send($body)); + $msg = $this->Controller->Session->read('Message.email.message'); + + $this->assertNoPattern('/\n\nContent-Transfer-Encoding/', $msg); + $this->assertPattern('/\nContent-Transfer-Encoding/', $msg); + } /** * testReset method *