Skip to content

Commit

Permalink
fixes #6397, removing unneeded line feed in email component headers, …
Browse files Browse the repository at this point in the history
…adding tests

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8248 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
DarkAngelBGE committed Jul 22, 2009
1 parent 07096f3 commit 3e14d28
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
3 changes: 1 addition & 2 deletions cake/libs/controller/components/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,6 @@ function __createHeader() {
$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';
Expand All @@ -504,7 +503,7 @@ function __createHeader() {
*/
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') {
Expand Down
30 changes: 28 additions & 2 deletions cake/tests/cases/libs/controller/components/email.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ function testSendFormats() {

// 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));
}
Expand Down Expand Up @@ -412,10 +413,11 @@ function testTemplates() {
$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 = '<pre>' . $expect . '--alt---' . "\n\n" . '</pre>';

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

Expand Down Expand Up @@ -588,10 +590,34 @@ function testSendAsIsNotIgnoredIfAttachmentsPresent() {
$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 = '<p>This is the body of the message</p>';

$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
*
Expand Down

0 comments on commit 3e14d28

Please sign in to comment.