Skip to content
This repository
Browse code

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
  • Loading branch information...
commit 3e14d281dfe3fe0e361d91af39740824ea690351 1 parent 07096f3
Tim Koschuetzki authored July 22, 2009
3  cake/libs/controller/components/email.php
@@ -491,7 +491,6 @@ function __createHeader() {
491 491
 			$this->__header[] = 'Content-Type: text/html; charset=' . $this->charset;
492 492
 		} elseif ($this->sendAs === 'both') {
493 493
 			$this->__header[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"';
494  
-			$this->__header[] = '';
495 494
 		}
496 495
 
497 496
 		$this->__header[] = 'Content-Transfer-Encoding: 7bit';
@@ -504,7 +503,7 @@ function __createHeader() {
504 503
  */
505 504
 	function __formatMessage($message) {
506 505
 		if (!empty($this->attachments)) {
507  
-			$prefix[] = '--' . $this->__boundary;
  506
+			$prefix = array('--' . $this->__boundary);
508 507
 			if ($this->sendAs === 'text') {
509 508
 				$prefix[] = 'Content-Type: text/plain; charset=' . $this->charset;
510 509
 			} elseif ($this->sendAs === 'html') {
30  cake/tests/cases/libs/controller/components/email.test.php
@@ -337,7 +337,8 @@ function testSendFormats() {
337 337
 
338 338
 		// TODO: better test for format of message sent?
339 339
 		$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
+
341 342
 		$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
342 343
 		$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
343 344
 	}
@@ -412,10 +413,11 @@ function testTemplates() {
412 413
 		$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
413 414
 
414 415
 		$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);
416 417
 		$expect .= '--alt-' . "\n" . 'Content-Type: text/plain; charset=UTF-8' . "\n" . 'Content-Transfer-Encoding: 7bit' . "\n\n" . $text . "\n\n";
417 418
 		$expect .= '--alt-' . "\n" . 'Content-Type: text/html; charset=UTF-8' . "\n" . 'Content-Transfer-Encoding: 7bit' . "\n\n" . $html . "\n\n";
418 419
 		$expect = '<pre>' . $expect . '--alt---' . "\n\n" . '</pre>';
  420
+
419 421
 		$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
420 422
 		$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
421 423
 
@@ -588,11 +590,35 @@ function testSendAsIsNotIgnoredIfAttachmentsPresent() {
588 590
 		$this->Controller->EmailTest->sendAs = 'both';
589 591
 		$this->assertTrue($this->Controller->EmailTest->send($body));
590 592
 		$msg = $this->Controller->Session->read('Message.email.message');
  593
+
591 594
 		$this->assertNoPattern('/text\/plain/', $msg);
592 595
 		$this->assertNoPattern('/text\/html/', $msg);
593 596
 		$this->assertPattern('/multipart\/alternative/', $msg);
594 597
 	}
595 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
+	}
  621
+/**
596 622
  * testReset method
597 623
  *
598 624
  * @access public

0 notes on commit 3e14d28

Please sign in to comment.
Something went wrong with that request. Please try again.