Skip to content

Commit

Permalink
Address CakeEmail regression when data is defined with no mimetype
Browse files Browse the repository at this point in the history
  • Loading branch information
bclay committed Aug 3, 2017
1 parent 7c2ad08 commit 3816191
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Network/Email/CakeEmail.php
Expand Up @@ -1084,7 +1084,7 @@ public function attachments($attachments = null) {
$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
35 changes: 35 additions & 0 deletions lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
Expand Up @@ -1139,6 +1139,41 @@ public function testSendNoTemplateWithDataStringAttachment() {
$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
Expand Down

0 comments on commit 3816191

Please sign in to comment.