Skip to content

Commit 3e14d28

Browse files
author
DarkAngelBGE
committed
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
1 parent 07096f3 commit 3e14d28

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

cake/libs/controller/components/email.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,6 @@ function __createHeader() {
491491
$this->__header[] = 'Content-Type: text/html; charset=' . $this->charset;
492492
} elseif ($this->sendAs === 'both') {
493493
$this->__header[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"';
494-
$this->__header[] = '';
495494
}
496495

497496
$this->__header[] = 'Content-Transfer-Encoding: 7bit';
@@ -504,7 +503,7 @@ function __createHeader() {
504503
*/
505504
function __formatMessage($message) {
506505
if (!empty($this->attachments)) {
507-
$prefix[] = '--' . $this->__boundary;
506+
$prefix = array('--' . $this->__boundary);
508507
if ($this->sendAs === 'text') {
509508
$prefix[] = 'Content-Type: text/plain; charset=' . $this->charset;
510509
} elseif ($this->sendAs === 'html') {

cake/tests/cases/libs/controller/components/email.test.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ function testSendFormats() {
337337

338338
// TODO: better test for format of message sent?
339339
$this->Controller->EmailTest->sendAs = 'both';
340-
$expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"' . "\n", $message);
340+
$expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"', $message);
341+
341342
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
342343
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
343344
}
@@ -412,10 +413,11 @@ function testTemplates() {
412413
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
413414

414415
$this->Controller->EmailTest->sendAs = 'both';
415-
$expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"' . "\n", $header);
416+
$expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"', $header);
416417
$expect .= '--alt-' . "\n" . 'Content-Type: text/plain; charset=UTF-8' . "\n" . 'Content-Transfer-Encoding: 7bit' . "\n\n" . $text . "\n\n";
417418
$expect .= '--alt-' . "\n" . 'Content-Type: text/html; charset=UTF-8' . "\n" . 'Content-Transfer-Encoding: 7bit' . "\n\n" . $html . "\n\n";
418419
$expect = '<pre>' . $expect . '--alt---' . "\n\n" . '</pre>';
420+
419421
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
420422
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
421423

@@ -588,10 +590,34 @@ function testSendAsIsNotIgnoredIfAttachmentsPresent() {
588590
$this->Controller->EmailTest->sendAs = 'both';
589591
$this->assertTrue($this->Controller->EmailTest->send($body));
590592
$msg = $this->Controller->Session->read('Message.email.message');
593+
591594
$this->assertNoPattern('/text\/plain/', $msg);
592595
$this->assertNoPattern('/text\/html/', $msg);
593596
$this->assertPattern('/multipart\/alternative/', $msg);
594597
}
598+
/**
599+
* undocumented function
600+
*
601+
* @return void
602+
* @access public
603+
*/
604+
function testNoDoubleNewlinesInHeaders() {
605+
$this->Controller->EmailTest->reset();
606+
$this->Controller->EmailTest->to = 'postmaster@localhost';
607+
$this->Controller->EmailTest->from = 'noreply@example.com';
608+
$this->Controller->EmailTest->subject = 'Attachment Test';
609+
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
610+
$this->Controller->EmailTest->template = null;
611+
$this->Controller->EmailTest->delivery = 'debug';
612+
$body = '<p>This is the body of the message</p>';
613+
614+
$this->Controller->EmailTest->sendAs = 'both';
615+
$this->assertTrue($this->Controller->EmailTest->send($body));
616+
$msg = $this->Controller->Session->read('Message.email.message');
617+
618+
$this->assertNoPattern('/\n\nContent-Transfer-Encoding/', $msg);
619+
$this->assertPattern('/\nContent-Transfer-Encoding/', $msg);
620+
}
595621
/**
596622
* testReset method
597623
*

0 commit comments

Comments
 (0)