示例#1
0
 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 = parent::EncodeHeader($str, $position);
         }
         return $encoded;
     } else {
         //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;
     }
 }
示例#2
0
 function encodeHeader($str, $position = 'text', $force = false)
 {
     if (version_compare(PHP_VERSION, '4.4.1') > 0) {
         if (function_exists('mb_convert_encoding')) {
             //Use mb_string extension if exists.
             if ($this->needs_encode || $force) {
                 $enc = mb_internal_encoding();
                 mb_internal_encoding('ISO-2022-JP');
                 $eol = $this->Mailer == 'mail' ? defined('XCUBE_MAILERLOCAL_MAIL_LE') ? XCUBE_MAILERLOCAL_MAIL_LE : "\r\n" : "\n";
                 // XXX: this for bugs in PHP mail() subject with linefeed handling
                 $encoded = mb_encode_mimeheader($str, 'ISO-2022-JP', 'B', $eol, 9);
                 // offset strlen("Subject: ") as 9
                 mb_internal_encoding($enc);
             } else {
                 $encoded = $str;
             }
         } else {
             $encoded = parent::EncodeHeader($str, $position);
         }
         return $encoded;
     } else {
         //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;
     }
 }