Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add some test for ISO-2022-JP charset mails

  • Loading branch information...
commit 712822ef830df0afddce1f667a47d9f54246fa79 1 parent 86a0814
@suzuki suzuki authored
View
8 lib/Cake/Network/Email/CakeEmail.php
@@ -1108,7 +1108,6 @@ protected function _encode($text) {
$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 @@ protected function _formatMessage($message) {
$prefix[] = '';
$message = array_merge($prefix, $message);
}
+
+ $tmp = array();
+ foreach ($message as $msg) {
+ $tmp[] = $this->_encodeString($msg, $this->charset);
+ }
+ $message = $tmp;
+
return $message;
}
View
130 lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
@@ -55,6 +55,13 @@ public function getBoundary() {
return $this->_boundary;
}
+/**
+ * Encode to protected method
+ *
+ */
+ public function encode($text) {
+ return $this->_encode($text);
+ }
}
/*
@@ -273,7 +280,7 @@ public function testFormatAddress() {
$result = $this->CakeEmail->formatAddress(array('cake@cakephp.org' => 'ÄÖÜTest'));
$expected = array('=?UTF-8?B?w4TDlsOcVGVzdA==?= <cake@cakephp.org>');
$this->assertIdentical($expected, $result);
-
+
$result = $this->CakeEmail->formatAddress(array('cake@cakephp.org' => '日本語Test'));
$expected = array('=?UTF-8?B?5pel5pys6KqeVGVzdA==?= <cake@cakephp.org>');
$this->assertIdentical($expected, $result);
@@ -286,11 +293,20 @@ public function testFormatAddress() {
*/
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==?= <cake@cakephp.org>');
$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==?= <cake@cakephp.org>");
+ $this->assertIdentical($expected, $result);
}
/**
@@ -384,6 +400,28 @@ public function testSubject() {
}
/**
+ * 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
*
* @return void
@@ -446,6 +484,20 @@ public function testHeaders() {
);
$this->assertIdentical($this->CakeEmail->getHeaders(array('from' => true, 'to' => true)), $expected);
+ $this->CakeEmail->charset = 'ISO-2022-JP';
+ $expected = array(
+ 'From' => 'CakePHP <cake@cakephp.org>',
+ 'To' => 'cake@cakephp.org, CakePHP <php@cakephp.org>',
+ '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');
}
@@ -746,6 +798,31 @@ public function testSendRender() {
}
/**
+ * 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
*
* @return void
@@ -766,6 +843,28 @@ public function testSendRenderWithVars() {
}
/**
+ * 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
*
* @return void
@@ -958,7 +1057,7 @@ public function testMessage() {
$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 @@ public function testMessage() {
$this->assertTrue($this->checkContentTransferEncoding($message, '7bit'));
}
+
/**
* testReset method
*
@@ -1212,7 +1312,7 @@ public function testBodyEncoding() {
$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 @@ private function checkContentTransferEncoding($message, $charset) {
}
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);
+ }
}
View
22 lib/Cake/Test/test_app/View/Emails/html/japanese.ctp
@@ -0,0 +1,22 @@
+<?php
+/**
+ *
+ * PHP 5
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
+ * Copyright 2005-2011, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
+ * @package cake.libs.view.templates.elements.email.html
+ * @since CakePHP(tm) v 0.10.0.1076
+ * @version $Revision$
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ */
+?>
+<p>ここにあなたの設定した値が入ります: <b><?php echo $value; ?></b></p>
View
22 lib/Cake/Test/test_app/View/Emails/text/japanese.ctp
@@ -0,0 +1,22 @@
+<?php
+/**
+ *
+ * PHP 5
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
+ * Copyright 2005-2011, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
+ * @package cake.libs.view.templates.elements.email.text
+ * @since CakePHP(tm) v 0.10.0.1076
+ * @version $Revision$
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ */
+?>
+ここにあなたの設定した値が入ります: <?php echo $value; ?>
View
31 lib/Cake/Test/test_app/View/Layouts/Emails/html/japanese.ctp
@@ -0,0 +1,31 @@
+<?php
+/**
+ *
+ * PHP 5
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org CakePHP(tm) Project
+ * @package cake.libs.view.templates.layouts.email.html
+ * @since CakePHP(tm) v 0.10.0.1076
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
+
+<html>
+<head>
+ <title><?php echo $title_for_layout;?></title>
+</head>
+
+<body>
+ <?php echo $content_for_layout;?>
+
+ <p>このメールは <a href="http://cakephp.org">CakePHP Framework</a> を利用して送信しました。</p>
+</body>
+</html>
View
22 lib/Cake/Test/test_app/View/Layouts/Emails/text/japanese.ctp
@@ -0,0 +1,22 @@
+<?php
+/**
+ *
+ * PHP 5
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org CakePHP(tm) Project
+ * @package cake.libs.view.templates.layouts.email.text
+ * @since CakePHP(tm) v 0.10.0.1076
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+?>
+
+<?php echo $content_for_layout;?>
+
+CakePHP Framework を使って送信したメールです。 http://cakephp.org.
Please sign in to comment.
Something went wrong with that request. Please try again.