Fix inline attachments being broken when only sending an HTML text body.

The rel boundary was closed too early causing inline images to be
incorrectly included in the email message.

Refs #3474
This commit is contained in:
mark_story 2014-05-14 09:42:25 -04:00
parent 5ab02a0ed1
commit 20ef10aca2
2 changed files with 43 additions and 1 deletions

View file

@ -1567,7 +1567,7 @@ class CakeEmail {
$msg[] = '';
}
if ($textBoundary !== $boundary) {
if ($textBoundary !== $relBoundary) {
$msg[] = '--' . $textBoundary . '--';
$msg[] = '';
}

View file

@ -1167,6 +1167,48 @@ class CakeEmailTest extends CakeTestCase {
$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.
*