Skip to content
Permalink
Browse files

Handle data attachments without warnings.

Don't attempt to detect mimetypes on 'data' attachments.

Refs #12297
  • Loading branch information...
markstory committed Jun 28, 2018
1 parent f8fb7b6 commit 6c0d8dfa1f294f5da88c306f2ae464b9ac66d559
Showing with 22 additions and 3 deletions.
  1. +1 −1 src/Mailer/Email.php
  2. +21 −2 tests/TestCase/Mailer/EmailTest.php
@@ -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'])) {
@@ -857,7 +857,7 @@ public function testViewVars()
*
* @return void
*/
public function testAttachments()
public function testSetAttachments()
{
$this->Email->setAttachments(CAKE . 'basics.php');
$expected = [
@@ -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
*
@@ -1317,7 +1337,6 @@ public function testSendNoTemplateWithAttachments()
*
* @return void
*/
public function testSendNoTemplateWithDataStringAttachment()
{
$this->Email->setTransport('debug');

0 comments on commit 6c0d8df

Please sign in to comment.
You can’t perform that action at this time.