From 9eeecc8755c7998e59b66baa192e1229d60ec88f Mon Sep 17 00:00:00 2001 From: nate Date: Sun, 25 May 2008 18:08:55 +0000 Subject: [PATCH] Adding content stripping fix for email component, fixes #4753 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7043 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/components/email.php | 14 +++++++++++--- .../libs/controller/components/email.test.php | 9 +++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index 15169109d..d895bd467 100644 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -620,13 +620,21 @@ class EmailComponent extends Object{ * @access private */ function __strip($value, $message = false) { - $search = array('/%0a/i', '/%0d/i', '/Content-Type\:/i', - '/charset\=/i', '/mime-version\:/i', '/multipart\/mixed/i', - '/bcc\:.*/i','/to\:.*/i','/cc\:.*/i', '/\\r/i', '/\\n/i'); + $search = array( + '/%0a/i', '/%0d/i', '/Content-Type\:/i', '/charset\=/i', '/mime-version\:/i', + '/multipart\/mixed/i', '/bcc\:.*/i','/to\:.*/i','/cc\:.*/i', '/Content-Transfer-Encoding\:/i', + '/\\r/i', '/\\n/i' + ); if ($message === true) { $search = array_slice($search, 0, -2); } + + foreach ($search as $key) { + while (preg_match($key, $value)) { + $value = preg_replace($key, '', $value); + } + } return preg_replace($search, '', $value); } /** diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php index c709bae77..31b5c3666 100644 --- a/cake/tests/cases/libs/controller/components/email.test.php +++ b/cake/tests/cases/libs/controller/components/email.test.php @@ -164,6 +164,15 @@ TEMPDOC; $this->assertTrue($this->Controller->Email->send('This is the body of the message')); } } + + function testContentStripping() { + $content = "Previous content\n--alt-\nContent-TypeContent-Type:: text/html; charsetcharset==utf-8\nContent-Transfer-Encoding: 7bit"; + $content .= "\n\n

My own html content

"; + + $result = $this->Controller->Email->__strip($content, true); + $expected = "Previous content\n--alt-\n text/html; utf-8\n 7bit\n\n

My own html content

"; + $this->assertEqual($result, $expected); + } } ?> \ No newline at end of file