Permalink
Browse files

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...
1 parent d4e2fbf commit e6f5ebc2575abf92d63e6bcdfeffebc393cb6f8b @markstory markstory committed Jan 21, 2012
Showing with 16 additions and 6 deletions.
  1. +16 −6 lib/Cake/Network/Email/CakeEmail.php
@@ -1240,17 +1240,22 @@ protected function _createBoundary() {
/**
* 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
*/
- protected function _attachFiles() {
+ protected function _attachFiles($boundary = null) {
+ if ($boundary === null) {
+ $boundary = $this->_boundary;
+ }
+
$msg = array();
foreach ($this->_attachments as $filename => $fileInfo) {
if (!empty($fileInfo['contentId'])) {
continue;
}
$data = $this->_readFile($fileInfo['file']);
- $msg[] = '--' . $this->_boundary;
+ $msg[] = '--' . $boundary;
$msg[] = 'Content-Type: ' . $fileInfo['mimetype'];
$msg[] = 'Content-Transfer-Encoding: base64';
$msg[] = 'Content-Disposition: attachment; filename="' . $filename . '"';
@@ -1278,17 +1283,22 @@ protected function _readFile($file) {
/**
* 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
*/
- protected function _attachInlineFiles() {
+ protected function _attachInlineFiles($boundary = null) {
+ if ($boundary === null) {
+ $boundary = $this->_boundary;
+ }
+
$msg = array();
foreach ($this->_attachments as $filename => $fileInfo) {
if (empty($fileInfo['contentId'])) {
continue;
}
$data = $this->_readFile($fileInfo['file']);
- $msg[] = '--rel-' . $this->_boundary;
+ $msg[] = '--' . $boundary;
$msg[] = 'Content-Type: ' . $fileInfo['mimetype'];
$msg[] = 'Content-Transfer-Encoding: base64';
$msg[] = 'Content-ID: <' . $fileInfo['contentId'] . '>';
@@ -1365,15 +1375,15 @@ protected function _render($content) {
}
if ($hasInlineAttachments) {
- $attachments = $this->_attachInlineFiles();
+ $attachments = $this->_attachInlineFiles($relBoundary);
$msg = array_merge($msg, $attachments);
$msg[] = '';
$msg[] = '--' . $relBoundary . '--';
$msg[] = '';
}
if ($hasAttachments) {
- $attachments = $this->_attachFiles();
+ $attachments = $this->_attachFiles($boundary);
$msg = array_merge($msg, $attachments);
}
if ($hasAttachments || $hasMultipleTypes) {

0 comments on commit e6f5ebc

Please sign in to comment.