onokazu
onoka****@users*****
2006年 7月 27日 (木) 09:17:18 JST
Index: xoops2jp/html/language/japanese/xoopsmailerlocal.php diff -u xoops2jp/html/language/japanese/xoopsmailerlocal.php:1.2 xoops2jp/html/language/japanese/xoopsmailerlocal.php:1.3 --- xoops2jp/html/language/japanese/xoopsmailerlocal.php:1.2 Mon Sep 5 05:46:09 2005 +++ xoops2jp/html/language/japanese/xoopsmailerlocal.php Thu Jul 27 09:17:18 2006 @@ -1,5 +1,5 @@ <?php -// $Id: xoopsmailerlocal.php,v 1.2 2005/09/04 20:46:09 onokazu Exp $ +// $Id: xoopsmailerlocal.php,v 1.3 2006/07/27 00:17:18 onokazu Exp $ // ------------------------------------------------------------------------ // // XOOPS - PHP Content Management System // // Copyright (c) 2000 XOOPS.org // @@ -35,6 +35,7 @@ $this->reset(); $this->charSet = 'iso-2022-jp'; $this->encoding = '7bit'; + $this->multimailer->CharSet = $this->charSet; } function encodeFromName($text){ @@ -62,7 +63,7 @@ --------------------------------------*/ function STRtoJIS($str, $from_charset){ if (function_exists('mb_convert_encoding')) { //Use mb_string extension if exists. - $str_JIS = mb_convert_encoding($str, "ISO-2022-JP", $from_charset); + $str_JIS = mb_convert_encoding($str, "ISO-2022-JP", $from_charset); } else if ($from_charset=='EUC-JP') { $str_JIS = ''; $mode = 0; @@ -115,27 +116,71 @@ } } - function addr_format($addr) { + function AddrFormat($addr) { if(empty($addr[1])) { $formatted = $addr[0]; } else { - $formatted = sprintf('%s <%s>', $this->encode_header($addr[1], 'text', true), $addr[0]); + $formatted = $this->EncodeHeader($addr[1], 'text') . " <" . + $addr[0] . ">"; } return $formatted; } - function encode_header ($str, $position = 'text', $force=false) { - 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"); + 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"); + } else { + $encoded = $str; + } } else { - $encoded = $str; + $encoded = parent::EncodeHeader($str, $position); } + return $encoded; } else { - $encoded = parent::encode_header($str, $position); - } - return $encoded; + //Following Logic are made for recovering PHP4.4.0 and 4.4.1 mb_encode_mimeheader() bug. + //TODO: If mb_encode_mimeheader() bug is fixed. Replace this to simple logic. + $encode_charset = strtoupper($this->CharSet); + if (function_exists('mb_convert_encoding')) { //Using mb_string extension if exists. + if ($this->needs_encode || $force) { + $str_encoding = mb_detect_encoding($str, 'ASCII,'.$encode_charset ); + if ($str_encoding == 'ASCII') { // Return original if string from only ASCII chars. + return $str; + } else if ($str_encoding != $encode_charset) { // Maybe this case may not occur. + $str = mb_convert_encoding($str, $encode_charset, $str_encoding); + } + $cut_start = 0; + $encoded =''; + $cut_length = floor((76-strlen('Subject: =?'.$encode_charset.'?B?'.'?='))/4)*3; + while($cut_start < strlen($str)) { + $partstr = mb_strcut ( $str, $cut_start, $cut_length, $encode_charset); + $partstr_length = strlen($partstr); + if (!$partstr_length) break; + if ($encode_charset == 'ISO-2022-JP') { + //Should Adjust next cutting place for SO & SI char insertion. + if ((substr($partstr, 0, 3)===chr(27).'$B') + && (substr($str, $cut_start, 3) !== chr(27).'$B')) { + $partstr_length -= 3; + } + if ((substr($partstr,-3)===chr(27).'(B') + && (substr($str, $cut_start+$partstr_length-3, 3) !== chr(27).'(B')) { + $partstr_length -= 3; + } + } + if ($cut_start) $encoded .= "\r\n\t"; + $encoded .= '=?' . $encode_charset . '?B?' . base64_encode($partstr) . '?='; + $cut_start += $partstr_length; + } + } else { + $encoded = $str; + } + } else { + $encoded = parent::EncodeHeader($str, $position); + } + return $encoded; + } } } ?> \ No newline at end of file