Skip to content

Commit

Permalink
Handle data attachments without warnings.
Browse files Browse the repository at this point in the history
Don't attempt to detect mimetypes on 'data' attachments.

Refs #12297
  • Loading branch information
markstory committed Jun 28, 2018
1 parent f8fb7b6 commit 6c0d8df
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Mailer/Email.php
Expand Up @@ -1833,7 +1833,7 @@ public function setAttachments($attachments)
$name = basename($fileInfo['file']);
}
}
if (!isset($fileInfo['mimetype']) && function_exists('mime_content_type')) {
if (!isset($fileInfo['mimetype']) && isset($fileInfo['file']) && function_exists('mime_content_type')) {
$fileInfo['mimetype'] = mime_content_type($fileInfo['file']);
}
if (!isset($fileInfo['mimetype'])) {
Expand Down
23 changes: 21 additions & 2 deletions tests/TestCase/Mailer/EmailTest.php
Expand Up @@ -857,7 +857,7 @@ public function testViewVars()
*
* @return void
*/
public function testAttachments()
public function testSetAttachments()
{
$this->Email->setAttachments(CAKE . 'basics.php');
$expected = [
Expand Down Expand Up @@ -891,6 +891,26 @@ public function testAttachments()
$this->Email->setAttachments([['nofile' => CAKE . 'basics.php', 'mimetype' => 'text/plain']]);
}

/**
* Test send() with no template and data string attachment and no mimetype
*
* @return void
*/
public function testSetAttachmentDataNoMimetype()
{
$this->Email->setAttachments(['cake.icon.gif' => [
'data' => 'test',
]]);
$result = $this->Email->getAttachments();
$expected = [
'cake.icon.gif' => [
'data' => base64_encode('test') . "\r\n",
'mimetype' => 'application/octet-stream'
],
];
$this->assertSame($expected, $this->Email->getAttachments());
}

/**
* testTransport method
*
Expand Down Expand Up @@ -1317,7 +1337,6 @@ public function testSendNoTemplateWithAttachments()
*
* @return void
*/

public function testSendNoTemplateWithDataStringAttachment()
{
$this->Email->setTransport('debug');
Expand Down

0 comments on commit 6c0d8df

Please sign in to comment.