From 0ca1ba32116574401e1a9ba990ad015b83656e5c Mon Sep 17 00:00:00 2001 From: euromark Date: Wed, 26 Jun 2013 02:20:31 +0200 Subject: [PATCH 1/3] allow callbacks to modify attachements by moving the decision to calculate boundary value into the correct position inside _render() --- lib/Cake/Network/Email/CakeEmail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index a43f10f32..dc1069e41 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -1071,7 +1071,6 @@ class CakeEmail { } $this->_textMessage = $this->_htmlMessage = ''; - $this->_createBoundary(); $this->_message = $this->_render($this->_wrap($content)); $contents = $this->transportClass()->send($this); @@ -1447,6 +1446,7 @@ class CakeEmail { $content = implode("\n", $content); $rendered = $this->_renderTemplates($content); + $this->_createBoundary(); $msg = array(); $contentIds = array_filter((array)Hash::extract($this->_attachments, '{s}.contentId')); From b346c4af8e0f927e80e6166a33e402d0f703ee37 Mon Sep 17 00:00:00 2001 From: euromark Date: Sat, 29 Jun 2013 15:16:58 +0200 Subject: [PATCH 2/3] Test to proof that render itself should handle the boundary. --- .../Test/Case/Network/Email/CakeEmailTest.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index 85b9b19b4..a3ace7759 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -65,6 +65,14 @@ class TestCakeEmail extends CakeEmail { return $this->_encode($text); } +/** + * Render to protected method + * + */ + public function render($content) { + return $this->_render($content); + } + } /* @@ -1484,6 +1492,22 @@ class CakeEmailTest extends CakeTestCase { $this->assertSame($expected, $result); } +/** + * testRender method + * + * @return void + */ + public function testRenderWithLayoutAndAttachment() { + $this->CakeEmail->emailFormat('html'); + $this->CakeEmail->template('html', 'default'); + $this->CakeEmail->attachments(array(CAKE . 'basics.php')); + $result = $this->CakeEmail->render(array()); + $this->assertNotEmpty($result); + + $result = $this->CakeEmail->getBoundary(); + $this->assertNotEmpty($result); + } + /** * testConstructWithConfigArray method * From c94fe1b7299fe974b50754e3cae462556c813a20 Mon Sep 17 00:00:00 2001 From: euromark Date: Sat, 29 Jun 2013 16:23:55 +0200 Subject: [PATCH 3/3] also move protected variable resetting into the correct scope --- lib/Cake/Network/Email/CakeEmail.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index dc1069e41..eb2f07fc2 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -1070,7 +1070,6 @@ class CakeEmail { $content = implode("\n", $content) . "\n"; } - $this->_textMessage = $this->_htmlMessage = ''; $this->_message = $this->_render($this->_wrap($content)); $contents = $this->transportClass()->send($this); @@ -1443,6 +1442,8 @@ class CakeEmail { * @return array Email body ready to be sent */ protected function _render($content) { + $this->_textMessage = $this->_htmlMessage = ''; + $content = implode("\n", $content); $rendered = $this->_renderTemplates($content);