Skip to content

Commit

Permalink
Fix inline attachments being broken when only sending an HTML text body.
Browse files Browse the repository at this point in the history
The rel boundary was closed too early causing inline images to be
incorrectly included in the email message.

Refs #3474
  • Loading branch information
markstory committed May 14, 2014
1 parent 5ab02a0 commit 20ef10a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Network/Email/CakeEmail.php
Expand Up @@ -1567,7 +1567,7 @@ protected function _render($content) {
$msg[] = '';
}

if ($textBoundary !== $boundary) {
if ($textBoundary !== $relBoundary) {
$msg[] = '--' . $textBoundary . '--';
$msg[] = '';
}
Expand Down
42 changes: 42 additions & 0 deletions lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
Expand Up @@ -1167,6 +1167,48 @@ public function testSendWithInlineAttachments() {
$this->assertContains('--' . $boundary . '--', $result['message']);
}

/**
* Test setting inline attachments and HTML only messages.
*
* @return void
*/
public function testSendWithInlineAttachmentsHtmlOnly() {
$this->CakeEmail->transport('debug');
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to('cake@cakephp.org');
$this->CakeEmail->subject('My title');
$this->CakeEmail->emailFormat('html');
$this->CakeEmail->attachments(array(
'cake.png' => array(
'file' => CAKE . 'VERSION.txt',
'contentId' => 'abc123'
)
));
$result = $this->CakeEmail->send('Hello');

$boundary = $this->CakeEmail->getBoundary();
$this->assertContains('Content-Type: multipart/mixed; boundary="' . $boundary . '"', $result['headers']);
$expected = "--$boundary\r\n" .
"Content-Type: multipart/related; boundary=\"rel-$boundary\"\r\n" .
"\r\n" .
"--rel-$boundary\r\n" .
"Content-Type: text/html; charset=UTF-8\r\n" .
"Content-Transfer-Encoding: 8bit\r\n" .
"\r\n" .
"Hello" .
"\r\n" .
"\r\n" .
"\r\n" .
"--rel-$boundary\r\n" .
"Content-Type: application/octet-stream\r\n" .
"Content-Transfer-Encoding: base64\r\n" .
"Content-ID: <abc123>\r\n" .
"Content-Disposition: inline; filename=\"cake.png\"\r\n\r\n";
$this->assertContains($expected, $result['message']);
$this->assertContains('--rel-' . $boundary . '--', $result['message']);
$this->assertContains('--' . $boundary . '--', $result['message']);
}

/**
* Test disabling content-disposition.
*
Expand Down

1 comment on commit 20ef10a

@dereuromark
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Works perfect again :)

Please sign in to comment.