Fix legacy conversion filter for ISO-2022-KR

This commit is contained in:
Alex Dowad 2022-07-15 10:52:09 +02:00
parent 8a915ed26c
commit 6d525a425e
2 changed files with 17 additions and 12 deletions

View file

@ -190,6 +190,14 @@ int mbfl_filt_conv_wchar_2022kr(int c, mbfl_convert_filter *filter)
{ {
int c1, c2, s = 0; int c1, c2, s = 0;
if ((filter->status & 0x100) == 0) {
CK((*filter->output_function)(0x1b, filter->data)); /* ESC */
CK((*filter->output_function)('$', filter->data));
CK((*filter->output_function)(')', filter->data));
CK((*filter->output_function)('C', filter->data));
filter->status |= 0x100;
}
if (c >= ucs_a1_uhc_table_min && c < ucs_a1_uhc_table_max) { if (c >= ucs_a1_uhc_table_min && c < ucs_a1_uhc_table_max) {
s = ucs_a1_uhc_table[c - ucs_a1_uhc_table_min]; s = ucs_a1_uhc_table[c - ucs_a1_uhc_table_min];
} else if (c >= ucs_a2_uhc_table_min && c < ucs_a2_uhc_table_max) { } else if (c >= ucs_a2_uhc_table_min && c < ucs_a2_uhc_table_max) {
@ -211,9 +219,7 @@ int mbfl_filt_conv_wchar_2022kr(int c, mbfl_convert_filter *filter)
/* exclude UHC extension area */ /* exclude UHC extension area */
if (c1 < 0xa1 || c2 < 0xa1) { if (c1 < 0xa1 || c2 < 0xa1) {
s = c; s = c;
} } else if (s & 0x8000) {
if (s & 0x8000) {
s -= 0x8080; s -= 0x8080;
} }
@ -235,13 +241,6 @@ int mbfl_filt_conv_wchar_2022kr(int c, mbfl_convert_filter *filter)
} }
CK((*filter->output_function)(s, filter->data)); CK((*filter->output_function)(s, filter->data));
} else { } else {
if ((filter->status & 0x100) == 0) {
CK((*filter->output_function)(0x1b, filter->data)); /* ESC */
CK((*filter->output_function)('$', filter->data));
CK((*filter->output_function)(')', filter->data));
CK((*filter->output_function)('C', filter->data));
filter->status |= 0x100;
}
if ((filter->status & 0x10) == 0) { if ((filter->status & 0x10) == 0) {
CK((*filter->output_function)(0x0e, filter->data)); /* shift out */ CK((*filter->output_function)(0x0e, filter->data)); /* shift out */
filter->status |= 0x10; filter->status |= 0x10;
@ -259,7 +258,7 @@ int mbfl_filt_conv_wchar_2022kr(int c, mbfl_convert_filter *filter)
static int mbfl_filt_conv_any_2022kr_flush(mbfl_convert_filter *filter) static int mbfl_filt_conv_any_2022kr_flush(mbfl_convert_filter *filter)
{ {
/* back to ascii */ /* back to ascii */
if (filter->status & 0xff00) { if (filter->status & 0x10) {
CK((*filter->output_function)(0x0f, filter->data)); /* shift in */ CK((*filter->output_function)(0x0f, filter->data)); /* shift in */
} }

View file

@ -28,6 +28,12 @@ if (mb_language("korean")) {
mb_send_mail($to, "테스트 ".mb_language(), "테스트"); mb_send_mail($to, "테스트 ".mb_language(), "테스트");
readfile(__DIR__ . "/mb_send_mail07.eml"); readfile(__DIR__ . "/mb_send_mail07.eml");
} }
/* Note: The subject line below, "=?ISO-2022-KR?B?GyQpQw5FVz06Ri4PIEtvcmVhbg==?=",
* used to be "=?ISO-2022-KR?B?GyQpQw5FVz06Ri4PIEtvcmVhbg8=?=". That was because
* the Base64-encoded ISO-2022-KR string contained an extraneous 0xF ('shift out')
* byte. 'Shift out' is only needed to return to ASCII mode, but the string
* contained one despite already being in ASCII mode. */
?> ?>
--CLEAN-- --CLEAN--
<?php <?php
@ -42,7 +48,7 @@ Content-Transfer-Encoding: %s
%s %s
To: example@example.com To: example@example.com
Subject: =?ISO-2022-KR?B?GyQpQw5FVz06Ri4PIEtvcmVhbg8=?= Subject: =?ISO-2022-KR?B?GyQpQw5FVz06Ri4PIEtvcmVhbg==?=
MIME-Version: 1.0 MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-2022-KR Content-Type: text/plain; charset=ISO-2022-KR
Content-Transfer-Encoding: 7bit Content-Transfer-Encoding: 7bit