Browse Source

Handle data attachments without warnings.

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

Refs #12297
Mark Story 7 years ago
parent
commit
6c0d8dfa1f
2 changed files with 22 additions and 3 deletions
  1. 1 1
      src/Mailer/Email.php
  2. 21 2
      tests/TestCase/Mailer/EmailTest.php

+ 1 - 1
src/Mailer/Email.php

@@ -1833,7 +1833,7 @@ class Email implements JsonSerializable, Serializable
                     $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'])) {

+ 21 - 2
tests/TestCase/Mailer/EmailTest.php

@@ -857,7 +857,7 @@ class EmailTest extends TestCase
      *
      * @return void
      */
-    public function testAttachments()
+    public function testSetAttachments()
     {
         $this->Email->setAttachments(CAKE . 'basics.php');
         $expected = [
@@ -892,6 +892,26 @@ class EmailTest extends TestCase
     }
 
     /**
+     * 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
      *
      * @return void
@@ -1317,7 +1337,6 @@ class EmailTest extends TestCase
      *
      * @return void
      */
-
     public function testSendNoTemplateWithDataStringAttachment()
     {
         $this->Email->setTransport('debug');