Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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-kos tim-kos authored
View
16 cake/libs/controller/components/email.php
@@ -504,12 +504,16 @@ function __createHeader() {
*/
function __formatMessage($message) {
if (!empty($this->attachments)) {
- $prefix = array(
- '--' . $this->__boundary,
- 'Content-Type: text/plain; charset=' . $this->charset,
- 'Content-Transfer-Encoding: 7bit',
- ''
- );
+ $prefix[] = '--' . $this->__boundary;
+ if ($this->sendAs === 'text') {
+ $prefix[] = 'Content-Type: text/plain; charset=' . $this->charset;
+ } elseif ($this->sendAs === 'html') {
+ $prefix[] = 'Content-Type: text/html; charset=' . $this->charset;
+ } elseif ($this->sendAs === 'both') {
+ $prefix[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"';
+ }
+ $prefix[] = 'Content-Transfer-Encoding: 7bit';
+ $prefix[] = '';
$message = array_merge($prefix, $message);
}
return $message;
View
36 cake/tests/cases/libs/controller/components/email.test.php
@@ -557,6 +557,42 @@ function testMultibyte() {
$this->assertEqual(trim($matches[1]), $subject);
}
/**
+ * undocumented function
+ *
+ * @return void
+ * @access public
+ */
+ function testSendAsIsNotIgnoredIfAttachmentsPresent() {
+ $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';
+ $this->Controller->EmailTest->attachments = array(__FILE__);
+ $body = '<p>This is the body of the message</p>';
+
+ $this->Controller->EmailTest->sendAs = 'html';
+ $this->assertTrue($this->Controller->EmailTest->send($body));
+ $msg = $this->Controller->Session->read('Message.email.message');
+ $this->assertNoPattern('/text\/plain/', $msg);
+ $this->assertPattern('/text\/html/', $msg);
+
+ $this->Controller->EmailTest->sendAs = 'text';
+ $this->assertTrue($this->Controller->EmailTest->send($body));
+ $msg = $this->Controller->Session->read('Message.email.message');
+ $this->assertPattern('/text\/plain/', $msg);
+ $this->assertNoPattern('/text\/html/', $msg);
+
+ $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);
+ }
+/**
* testReset method
*
* @access public
Please sign in to comment.
Something went wrong with that request. Please try again.