From 38161917eb02f78aa546512e99b7f6893ec81820 Mon Sep 17 00:00:00 2001 From: bclay Date: Thu, 3 Aug 2017 17:00:58 -0400 Subject: [PATCH] Address CakeEmail regression when data is defined with no mimetype --- lib/Cake/Network/Email/CakeEmail.php | 2 +- .../Test/Case/Network/Email/CakeEmailTest.php | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index 8d71e7833..5946e31af 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -1084,7 +1084,7 @@ class CakeEmail { $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'])) { diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index 809b092ba..4d0091ed3 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -1139,6 +1139,41 @@ class CakeEmailTest extends CakeTestCase { $expected .= chunk_split(base64_encode($data), 76, "\r\n"); $this->assertContains($expected, $result['message']); } + +/** + * Test send() with no template and data string attachment, no mimetype + * + * @return void + */ + public function testSendNoTemplateWithDataStringAttachmentNoMime() { + $this->CakeEmail->transport('debug'); + $this->CakeEmail->from('cake@cakephp.org'); + $this->CakeEmail->to('cake@cakephp.org'); + $this->CakeEmail->subject('My title'); + $this->CakeEmail->emailFormat('text'); + $data = file_get_contents(CAKE . 'Console/Templates/skel/webroot/img/cake.icon.png'); + $this->CakeEmail->attachments(array('cake.icon.png' => array( + 'data' => $data + ))); + $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: text/plain; charset=UTF-8\r\n" . + "Content-Transfer-Encoding: 8bit\r\n" . + "\r\n" . + "Hello" . + "\r\n" . + "\r\n" . + "\r\n" . + "--$boundary\r\n" . + "Content-Type: application/octet-stream\r\n" . + "Content-Transfer-Encoding: base64\r\n" . + "Content-Disposition: attachment; filename=\"cake.icon.png\"\r\n\r\n"; + $expected .= chunk_split(base64_encode($data), 76, "\r\n"); + $this->assertContains($expected, $result['message']); + } /** * Test send() with no template as both