mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-06 19:42:41 +00:00
Added test for content transfer encoding for iso-2022-jp. Thanks @suzuki
This commit is contained in:
parent
cef441c16b
commit
e3898585be
1 changed files with 39 additions and 0 deletions
|
@ -958,6 +958,19 @@ 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'));
|
||||
|
||||
|
||||
$this->CakeEmail->charset = 'ISO-2022-JP';
|
||||
$this->CakeEmail->send();
|
||||
$message = $this->CakeEmail->message();
|
||||
$this->assertTrue(in_array('Content-Type: text/plain; charset=ISO-2022-JP', $message));
|
||||
$this->assertTrue(in_array('Content-Type: text/html; charset=ISO-2022-JP', $message));
|
||||
|
||||
// ISO-2022-JP is 7bit
|
||||
$this->assertTrue($this->checkContentTransferEncoding($message, '7bit'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1201,4 +1214,30 @@ class CakeEmailTest extends CakeTestCase {
|
|||
$this->assertContains('Content-Type: text/plain; charset=iso-2022-jp', $result['headers']);
|
||||
$this->assertContains('ってテーブルを作ってやってたらう', $result['message']);
|
||||
}
|
||||
|
||||
private function checkContentTransferEncoding($message, $charset) {
|
||||
$boundary = '--alt-' . $this->CakeEmail->getBoundary();
|
||||
$result['text'] = false;
|
||||
$result['html'] = false;
|
||||
for ($i = 0; $i < count($message); ++$i) {
|
||||
if ($message[$i] == $boundary) {
|
||||
$flag = false;
|
||||
$type = '';
|
||||
while (!preg_match('/^$/', $message[$i])) {
|
||||
if (preg_match('/^Content-Type: text\/plain/', $message[$i])) {
|
||||
$type = 'text';
|
||||
}
|
||||
if (preg_match('/^Content-Type: text\/html/', $message[$i])) {
|
||||
$type = 'html';
|
||||
}
|
||||
if ($message[$i] === 'Content-Transfer-Encoding: ' . $charset) {
|
||||
$flag = true;
|
||||
}
|
||||
++$i;
|
||||
}
|
||||
$result[$type] = $flag;
|
||||
}
|
||||
}
|
||||
return $result['text'] && $result['html'];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue