Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge changes from hmic/CakeEmail-2.0
Adds parameters for file attachments instead of having
boundary prefixes in multiple places.

Fixes #GH433
  • Loading branch information
markstory committed Jan 21, 2012
1 parent d4e2fbf commit e6f5ebc
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/Cake/Network/Email/CakeEmail.php
Expand Up @@ -1240,17 +1240,22 @@ protected function _createBoundary() {
/** /**
* Attach non-embedded files by adding file contents inside boundaries. * Attach non-embedded files by adding file contents inside boundaries.
* *
* @param string $boundary Boundary to use. If null, will default to $this->_boundary
* @return array An array of lines to add to the message * @return array An array of lines to add to the message
*/ */
protected function _attachFiles() { protected function _attachFiles($boundary = null) {
if ($boundary === null) {
$boundary = $this->_boundary;
}

$msg = array(); $msg = array();
foreach ($this->_attachments as $filename => $fileInfo) { foreach ($this->_attachments as $filename => $fileInfo) {
if (!empty($fileInfo['contentId'])) { if (!empty($fileInfo['contentId'])) {
continue; continue;
} }
$data = $this->_readFile($fileInfo['file']); $data = $this->_readFile($fileInfo['file']);


$msg[] = '--' . $this->_boundary; $msg[] = '--' . $boundary;
$msg[] = 'Content-Type: ' . $fileInfo['mimetype']; $msg[] = 'Content-Type: ' . $fileInfo['mimetype'];
$msg[] = 'Content-Transfer-Encoding: base64'; $msg[] = 'Content-Transfer-Encoding: base64';
$msg[] = 'Content-Disposition: attachment; filename="' . $filename . '"'; $msg[] = 'Content-Disposition: attachment; filename="' . $filename . '"';
Expand Down Expand Up @@ -1278,17 +1283,22 @@ protected function _readFile($file) {
/** /**
* Attach inline/embedded files to the message. * Attach inline/embedded files to the message.
* *
* @param string $boundary Boundary to use. If null, will default to $this->_boundary
* @return array An array of lines to add to the message * @return array An array of lines to add to the message
*/ */
protected function _attachInlineFiles() { protected function _attachInlineFiles($boundary = null) {
if ($boundary === null) {
$boundary = $this->_boundary;
}

$msg = array(); $msg = array();
foreach ($this->_attachments as $filename => $fileInfo) { foreach ($this->_attachments as $filename => $fileInfo) {
if (empty($fileInfo['contentId'])) { if (empty($fileInfo['contentId'])) {
continue; continue;
} }
$data = $this->_readFile($fileInfo['file']); $data = $this->_readFile($fileInfo['file']);


$msg[] = '--rel-' . $this->_boundary; $msg[] = '--' . $boundary;
$msg[] = 'Content-Type: ' . $fileInfo['mimetype']; $msg[] = 'Content-Type: ' . $fileInfo['mimetype'];
$msg[] = 'Content-Transfer-Encoding: base64'; $msg[] = 'Content-Transfer-Encoding: base64';
$msg[] = 'Content-ID: <' . $fileInfo['contentId'] . '>'; $msg[] = 'Content-ID: <' . $fileInfo['contentId'] . '>';
Expand Down Expand Up @@ -1365,15 +1375,15 @@ protected function _render($content) {
} }


if ($hasInlineAttachments) { if ($hasInlineAttachments) {
$attachments = $this->_attachInlineFiles(); $attachments = $this->_attachInlineFiles($relBoundary);
$msg = array_merge($msg, $attachments); $msg = array_merge($msg, $attachments);
$msg[] = ''; $msg[] = '';
$msg[] = '--' . $relBoundary . '--'; $msg[] = '--' . $relBoundary . '--';
$msg[] = ''; $msg[] = '';
} }


if ($hasAttachments) { if ($hasAttachments) {
$attachments = $this->_attachFiles(); $attachments = $this->_attachFiles($boundary);
$msg = array_merge($msg, $attachments); $msg = array_merge($msg, $attachments);
} }
if ($hasAttachments || $hasMultipleTypes) { if ($hasAttachments || $hasMultipleTypes) {
Expand Down

0 comments on commit e6f5ebc

Please sign in to comment.