Skip to content
This repository
Browse code

Applying patch from ' matsinet', fixes #6475, EmailComponent ignoring…

… sendAs when attachments present, adding tests

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8242 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
commit caeac73562ce78cea596e63cbf0526df6cea77ff 1 parent fefbe77
Tim Koschuetzki authored July 21, 2009
16  cake/libs/controller/components/email.php
@@ -504,12 +504,16 @@ function __createHeader() {
504 504
  */
505 505
 	function __formatMessage($message) {
506 506
 		if (!empty($this->attachments)) {
507  
-			$prefix = array(
508  
-				'--' . $this->__boundary,
509  
-				'Content-Type: text/plain; charset=' . $this->charset,
510  
-				'Content-Transfer-Encoding: 7bit',
511  
-				''
512  
-			);
  507
+			$prefix[] = '--' . $this->__boundary;
  508
+			if ($this->sendAs === 'text') {
  509
+				$prefix[] = 'Content-Type: text/plain; charset=' . $this->charset;
  510
+			} elseif ($this->sendAs === 'html') {
  511
+				$prefix[] = 'Content-Type: text/html; charset=' . $this->charset;
  512
+			} elseif ($this->sendAs === 'both') {
  513
+				$prefix[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"';
  514
+			}
  515
+			$prefix[] = 'Content-Transfer-Encoding: 7bit';
  516
+			$prefix[] = '';
513 517
 			$message = array_merge($prefix, $message);
514 518
 		}
515 519
 		return $message;
36  cake/tests/cases/libs/controller/components/email.test.php
@@ -557,6 +557,42 @@ function testMultibyte() {
557 557
 		$this->assertEqual(trim($matches[1]), $subject);
558 558
 	}
559 559
 /**
  560
+ * undocumented function
  561
+ *
  562
+ * @return void
  563
+ * @access public
  564
+ */
  565
+	function testSendAsIsNotIgnoredIfAttachmentsPresent() {
  566
+		$this->Controller->EmailTest->reset();
  567
+		$this->Controller->EmailTest->to = 'postmaster@localhost';
  568
+		$this->Controller->EmailTest->from = 'noreply@example.com';
  569
+		$this->Controller->EmailTest->subject = 'Attachment Test';
  570
+		$this->Controller->EmailTest->replyTo = 'noreply@example.com';
  571
+		$this->Controller->EmailTest->template = null;
  572
+		$this->Controller->EmailTest->delivery = 'debug';
  573
+		$this->Controller->EmailTest->attachments = array(__FILE__);
  574
+		$body = '<p>This is the body of the message</p>';
  575
+
  576
+		$this->Controller->EmailTest->sendAs = 'html';
  577
+		$this->assertTrue($this->Controller->EmailTest->send($body));
  578
+		$msg = $this->Controller->Session->read('Message.email.message');
  579
+		$this->assertNoPattern('/text\/plain/', $msg);
  580
+		$this->assertPattern('/text\/html/', $msg);
  581
+
  582
+		$this->Controller->EmailTest->sendAs = 'text';
  583
+		$this->assertTrue($this->Controller->EmailTest->send($body));
  584
+		$msg = $this->Controller->Session->read('Message.email.message');
  585
+		$this->assertPattern('/text\/plain/', $msg);
  586
+		$this->assertNoPattern('/text\/html/', $msg);
  587
+
  588
+		$this->Controller->EmailTest->sendAs = 'both';
  589
+		$this->assertTrue($this->Controller->EmailTest->send($body));
  590
+		$msg = $this->Controller->Session->read('Message.email.message');
  591
+		$this->assertNoPattern('/text\/plain/', $msg);
  592
+		$this->assertNoPattern('/text\/html/', $msg);
  593
+		$this->assertPattern('/multipart\/alternative/', $msg);
  594
+	}
  595
+/**
560 596
  * testReset method
561 597
  *
562 598
  * @access public

0 notes on commit caeac73

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