diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index 9a756555b..cd735ed56 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -1108,7 +1108,6 @@ class CakeEmail { $restore = mb_internal_encoding(); mb_internal_encoding($this->_appCharset); } - $text = $this->_encodeString($text, $this->headerCharset); $return = mb_encode_mimeheader($text, $this->headerCharset, 'B'); if ($internalEncoding) { mb_internal_encoding($restore); @@ -1283,6 +1282,13 @@ class CakeEmail { $prefix[] = ''; $message = array_merge($prefix, $message); } + + $tmp = array(); + foreach ($message as $msg) { + $tmp[] = $this->_encodeString($msg, $this->charset); + } + $message = $tmp; + return $message; } diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index 7659d2847..785bbd083 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -55,6 +55,13 @@ class TestCakeEmail extends CakeEmail { return $this->_boundary; } +/** + * Encode to protected method + * + */ + public function encode($text) { + return $this->_encode($text); + } } /* @@ -273,7 +280,7 @@ class CakeEmailTest extends CakeTestCase { $result = $this->CakeEmail->formatAddress(array('cake@cakephp.org' => 'ÄÖÜTest')); $expected = array('=?UTF-8?B?w4TDlsOcVGVzdA==?= '); $this->assertIdentical($expected, $result); - + $result = $this->CakeEmail->formatAddress(array('cake@cakephp.org' => '日本語Test')); $expected = array('=?UTF-8?B?5pel5pys6KqeVGVzdA==?= '); $this->assertIdentical($expected, $result); @@ -286,11 +293,20 @@ class CakeEmailTest extends CakeTestCase { */ public function testFormatAddressJapanese() { $this->skipIf(!function_exists('mb_convert_encoding')); - - $this->CakeEmail->charset = 'ISO-2022-JP'; + + $this->CakeEmail->headerCharset = 'ISO-2022-JP'; $result = $this->CakeEmail->formatAddress(array('cake@cakephp.org' => '日本語Test')); $expected = array('=?ISO-2022-JP?B?GyRCRnxLXDhsGyhCVGVzdA==?= '); $this->assertIdentical($expected, $result); + + $result = $this->CakeEmail->formatAddress(array('cake@cakephp.org' => '寿限無寿限無五劫の擦り切れ海砂利水魚の水行末雲来末風来末食う寝る処に住む処やぶら小路の藪柑子パイポパイポパイポのシューリンガンシューリンガンのグーリンダイグーリンダイのポンポコピーのポンポコナーの長久命の長助')); + $expected = array("=?ISO-2022-JP?B?GyRCPHc4Qkw1PHc4Qkw1OF45ZSROOyQkakBaJGwzJDo9TXg/ZTV7GyhC?=\r\n" + ." =?ISO-2022-JP?B?GyRCJE4/ZTlUS3YxQE1oS3ZJd01oS3Y/KSQmPzIkaz1oJEs9OyRgGyhC?=\r\n" + ." =?ISO-2022-JP?B?GyRCPWgkZCRWJGk+Lk8pJE5pLjQ7O1IlUSUkJV0lUSUkJV0lUSUkGyhC?=\r\n" + ." =?ISO-2022-JP?B?GyRCJV0kTiU3JWUhPCVqJXMlLCVzJTclZSE8JWolcyUsJXMkTiUwGyhC?=\r\n" + ." =?ISO-2022-JP?B?GyRCITwlaiVzJUAlJCUwITwlaiVzJUAlJCROJV0lcyVdJTMlVCE8GyhC?=\r\n" + ." =?ISO-2022-JP?B?GyRCJE4lXSVzJV0lMyVKITwkTkQ5NVdMPyRORDk9dRsoQg==?= "); + $this->assertIdentical($expected, $result); } /** @@ -383,6 +399,28 @@ class CakeEmailTest extends CakeTestCase { $this->assertIdentical($this->CakeEmail->subject(), $expected); } +/** + * testSubjectJapanese + * + * @return void + */ + public function testSubjectJapanese() { + $this->skipIf(!function_exists('mb_convert_encoding')); + mb_internal_encoding('UTF-8'); + + $this->CakeEmail->headerCharset = 'ISO-2022-JP'; + $this->CakeEmail->subject('日本語のSubjectにも対応するよ'); + $expected = '=?ISO-2022-JP?B?GyRCRnxLXDhsJE4bKEJTdWJqZWN0GyRCJEskYkJQMX4kOSRrJGgbKEI=?='; + $this->assertIdentical($this->CakeEmail->subject(), $expected); + + $this->CakeEmail->subject('長い長い長いSubjectの場合はfoldingするのが正しいんだけどいったいどうなるんだろう?'); + $expected = "=?ISO-2022-JP?B?GyRCRDkkJEQ5JCREOSQkGyhCU3ViamVjdBskQiROPmw5ZyRPGyhCZm9s?=\r\n" + ." =?ISO-2022-JP?B?ZGluZxskQiQ5JGskTiQsQDUkNyQkJHMkQCQxJEkkJCRDJD8kJCRJGyhC?=\r\n" + ." =?ISO-2022-JP?B?GyRCJCYkSiRrJHMkQCRtJCYhKRsoQg==?="; + $this->assertIdentical($this->CakeEmail->subject(), $expected); + } + + /** * testHeaders method * @@ -446,6 +484,20 @@ class CakeEmailTest extends CakeTestCase { ); $this->assertIdentical($this->CakeEmail->getHeaders(array('from' => true, 'to' => true)), $expected); + $this->CakeEmail->charset = 'ISO-2022-JP'; + $expected = array( + 'From' => 'CakePHP ', + 'To' => 'cake@cakephp.org, CakePHP ', + 'X-Something' => 'very nice', + 'X-Other' => 'cool', + 'X-Mailer' => 'CakePHP Email', + 'Date' => date(DATE_RFC2822), + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=ISO-2022-JP', + 'Content-Transfer-Encoding' => '7bit' + ); + $this->assertIdentical($this->CakeEmail->getHeaders(array('from' => true, 'to' => true)), $expected); + $result = $this->CakeEmail->setHeaders(array()); $this->assertIsA($result, 'CakeEmail'); } @@ -745,6 +797,31 @@ class CakeEmailTest extends CakeTestCase { $this->assertTrue((bool)strpos($result['headers'], 'To: ')); } +/** + * testSendRender method for ISO-2022-JP + * + * @return void + */ + public function testSendRenderJapanese() { + $this->skipIf(!function_exists('mb_convert_encoding')); + + $this->CakeEmail->reset(); + $this->CakeEmail->transport('debug'); + + $this->CakeEmail->from('cake@cakephp.org'); + $this->CakeEmail->to(array('you@cakephp.org' => 'You')); + $this->CakeEmail->subject('My title'); + $this->CakeEmail->config(array('empty')); + $this->CakeEmail->template('default', 'japanese'); + $this->CakeEmail->charset = 'ISO-2022-JP'; + $result = $this->CakeEmail->send(); + + $expected = mb_convert_encoding('CakePHP Framework を使って送信したメールです。 http://cakephp.org.','ISO-2022-JP'); + $this->assertTrue((bool)strpos($result['message'], $expected)); + $this->assertTrue((bool)strpos($result['headers'], 'Message-ID: ')); + $this->assertTrue((bool)strpos($result['headers'], 'To: ')); + } + /** * testSendRenderWithVars method * @@ -765,6 +842,28 @@ class CakeEmailTest extends CakeTestCase { $this->assertTrue((bool)strpos($result['message'], 'Here is your value: 12345')); } +/** + * testSendRenderWithVars method for ISO-2022-JP + * + * @return void + */ + public function testSendRenderWithVarsJapanese() { + $this->CakeEmail->reset(); + $this->CakeEmail->transport('debug'); + + $this->CakeEmail->from('cake@cakephp.org'); + $this->CakeEmail->to(array('you@cakephp.org' => 'You')); + $this->CakeEmail->subject('My title'); + $this->CakeEmail->config(array('empty')); + $this->CakeEmail->template('japanese', 'default'); + $this->CakeEmail->viewVars(array('value' => '日本語の差し込み123')); + $this->CakeEmail->charset = 'ISO-2022-JP'; + $result = $this->CakeEmail->send(); + + $expected = mb_convert_encoding('ここにあなたの設定した値が入ります: 日本語の差し込み123', 'ISO-2022-JP'); + $this->assertTrue((bool)strpos($result['message'], $expected)); + } + /** * testSendRenderWithHelpers method * @@ -958,7 +1057,7 @@ class CakeEmailTest extends CakeTestCase { $message = $this->CakeEmail->message(); $this->assertTrue(in_array('Content-Type: text/plain; charset=UTF-8', $message)); $this->assertTrue(in_array('Content-Type: text/html; charset=UTF-8', $message)); - + // UTF-8 is 8bit $this->assertTrue($this->checkContentTransferEncoding($message, '8bit')); @@ -973,6 +1072,7 @@ class CakeEmailTest extends CakeTestCase { $this->assertTrue($this->checkContentTransferEncoding($message, '7bit')); } + /** * testReset method * @@ -1212,7 +1312,7 @@ class CakeEmailTest extends CakeTestCase { $email->to('someone@example.com')->from('someone@example.com'); $result = $email->send('ってテーブルを作ってやってたらう'); $this->assertContains('Content-Type: text/plain; charset=iso-2022-jp', $result['headers']); - $this->assertContains('ってテーブルを作ってやってたらう', $result['message']); + $this->assertContains(mb_convert_encoding('ってテーブルを作ってやってたらう','ISO-2022-JP'), $result['message']); } private function checkContentTransferEncoding($message, $charset) { @@ -1240,4 +1340,24 @@ class CakeEmailTest extends CakeTestCase { } return $result['text'] && $result['html']; } + +/** + * Test CakeEmail::_encode function + * + */ + public function testEncode() { + $this->skipIf(!function_exists('mb_convert_encoding')); + + $this->CakeEmail->headerCharset = 'ISO-2022-JP'; + $result = $this->CakeEmail->encode('日本語'); + $expected = '=?ISO-2022-JP?B?GyRCRnxLXDhsGyhC?='; + $this->assertIdentical($expected, $result); + + $this->CakeEmail->headerCharset = 'ISO-2022-JP'; + $result = $this->CakeEmail->encode('長い長い長いSubjectの場合はfoldingするのが正しいんだけどいったいどうなるんだろう?'); + $expected = "=?ISO-2022-JP?B?GyRCRDkkJEQ5JCREOSQkGyhCU3ViamVjdBskQiROPmw5ZyRPGyhCZm9s?=\r\n" + . " =?ISO-2022-JP?B?ZGluZxskQiQ5JGskTiQsQDUkNyQkJHMkQCQxJEkkJCRDJD8kJCRJGyhC?=\r\n" + . " =?ISO-2022-JP?B?GyRCJCYkSiRrJHMkQCRtJCYhKRsoQg==?="; + $this->assertIdentical($expected, $result); + } } diff --git a/lib/Cake/Test/test_app/View/Emails/html/japanese.ctp b/lib/Cake/Test/test_app/View/Emails/html/japanese.ctp new file mode 100644 index 000000000..18f39bc34 --- /dev/null +++ b/lib/Cake/Test/test_app/View/Emails/html/japanese.ctp @@ -0,0 +1,22 @@ + +

ここにあなたの設定した値が入ります:

diff --git a/lib/Cake/Test/test_app/View/Emails/text/japanese.ctp b/lib/Cake/Test/test_app/View/Emails/text/japanese.ctp new file mode 100644 index 000000000..75298d8d5 --- /dev/null +++ b/lib/Cake/Test/test_app/View/Emails/text/japanese.ctp @@ -0,0 +1,22 @@ + +ここにあなたの設定した値が入ります: diff --git a/lib/Cake/Test/test_app/View/Layouts/Emails/html/japanese.ctp b/lib/Cake/Test/test_app/View/Layouts/Emails/html/japanese.ctp new file mode 100644 index 000000000..da3cfa4e9 --- /dev/null +++ b/lib/Cake/Test/test_app/View/Layouts/Emails/html/japanese.ctp @@ -0,0 +1,31 @@ + + + + + + <?php echo $title_for_layout;?> + + + + + +

このメールは CakePHP Framework を利用して送信しました。

+ + \ No newline at end of file diff --git a/lib/Cake/Test/test_app/View/Layouts/Emails/text/japanese.ctp b/lib/Cake/Test/test_app/View/Layouts/Emails/text/japanese.ctp new file mode 100644 index 000000000..2200bcfc0 --- /dev/null +++ b/lib/Cake/Test/test_app/View/Layouts/Emails/text/japanese.ctp @@ -0,0 +1,22 @@ + + + + +CakePHP Framework を使って送信したメールです。 http://cakephp.org. \ No newline at end of file