Menu

#250 mail subject problem in japasese

2.1.8
open
nobody
None
5
2015-02-15
2010-04-16
ohwada
No

■ 問題
環境によって、メールの題名が文字化けします。

html/language/japanese/xoopsmailerlocal.php
html/language/japanese/xoopsmailerlocal.php

ここで SJIS に変換していて
-----
function encodeSubject($text){
if ($this->multimailer->needs_encode) {
return $this->STRtoJIS($text,_CHARSET);
} else {
return $text;
}
}
-----

ここで SJIS から _CHARSET(EUC-JP or UTF-8) に戻してから、
mime エンコードしています。
-----
function EncodeHeader ($str, $position = 'text', $force=false) {
if (!preg_match('/^4\.4\.[01]([^0-9]+|$)/',PHP_VERSION)) {
if (function_exists('mb_convert_encoding')) { //Use mb_string extension if exists.
if ($this->needs_encode || $force) {
$encoded = mb_convert_encoding($str, _CHARSET, mb_detect_encoding($str));
$encoded = mb_encode_mimeheader($encoded, "ISO-2022-JP", "B", "\n");
-----

mb_detect_encoding は mb_detect_order により文字コードを判定します。
mb_detect_order は環境によって 2通りあるようです。

(1) ASCII JIS UTF-8 EUC-JP SJIS
(2) ASCII UTF-8

(2) のときは、SJIS のはずが、UTF-8 と判定され、ご変換されます。

■ 対策

-----
function encodeSubject($text){

// 下記を追加する
if ( function_exists('mb_detect_order') ) {
if ( !in_array( 'SJIS', mb_detect_order() ) ) {
return $text;
}
}

if ($this->multimailer->needs_encode) {
return $this->STRtoJIS($text,_CHARSET);
} else {
return $text;
}
}
-----

■ 補足

2つほど、気になることが。

(1) _CHARSET から SJIS にして _CHARSET に戻するのは、」無駄だと思うが。
何らかの理由でこうなっているんでしょうね。

(2) mb_detect_encoding は誤変換の元だから、使いたくないなぁ。

Discussion

  • ohwada

    ohwada - 2010-04-19

    > ここで SJIS に変換していて
    > ここで SJIS から _CHARSET(EUC-JP or UTF-8) に戻してから、
    > if ( !in_array( 'SJIS', mb_detect_order() ) ) {

    typoです。
    SJIS -> JIS と読み替えてね。

     
  • minahito

    minahito - 2010-05-09
    • milestone: --> 2.1.8
     

Log in to post a comment.