Author Topic: Charset encoding bug..  (Read 3664 times)

Offline sarma

  • Newbie
  • *
  • Posts: 3
Charset encoding bug..
« on: October 18, 2007, 09:36:54 AM »
Found on log file:
PHP Warning: mb_convert_encoding() [function.mb-convert-encoding]: Illegal character encoding specified in /var/www/sites/new/public_html/program/include/main.inc on line 932

After some debuging found that it try convert charset WINDOWS-1257 to UTF-8 with mbstring but mbstring does support it..

I try do this conversion with iconv module adding some lines to code:

Quote
   if ($from == 'WINDOWS-1257' or $form == 'windows-1257'){
      $out = iconv($from, $to, $str);
         retutn $out;
   }else{
      if (($out = mb_convert_encoding($str, $to, $from)) != '')
         return $out;
   }

result - correct message view.. :)

different hack:

Quote
   if ($from == 'WINDOWS-1257' or $form == 'windows-1257'){
      $from = 'ISO-8859-13';
   }else{
      if (($out = mb_convert_encoding($str, $to, $from)) != '')
         return $out;
   }

this works..but this is dirty hack becouse charset Windows-1257 and iso-8859-13 are not same..
What says devs about this?

Offline sarma

  • Newbie
  • *
  • Posts: 3
Re: Charset encoding bug..
« Reply #1 on: October 20, 2007, 06:02:32 AM »
found that this is fixed in cvs version..
replaced coresponding function on main.inc
Code: [Select]
function rcube_charset_convert($str, $from, $to=NULL)
  {
  global $MBSTRING;
 
  $from = strtoupper($from);
  $to = $to==NULL ? strtoupper(RCMAIL_CHARSET) : strtoupper($to);
 
  if ($from==$to || $str=='' || empty($from))
   return $str;
 
  // convert charset using iconv module
  if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7')
   {
   $iconv_map = array('KS_C_5601-1987' => 'EUC-KR');
   return iconv(($iconv_map[$from] ? $iconv_map[$from] : $from), ($iconv_map[$to] ? $iconv_map[$to] : $to) . "//IGNORE", $str);
   }
 
  // convert charset using mbstring module
  if ($MBSTRING)
   {
 $mb_map = array('UTF-7' => 'UTF7-IMAP', 'KS_C_5601-1987' => 'EUC-KR');
   
   // return if convert succeeded
   if (($out = mb_convert_encoding($str, ($mb_map[$to] ? $mb_map[$to] : $to), ($mb_map[$from] ? $mb_map[$from] : $from))) != '')
    return $out;
   }
 
  $conv = new utf8();
 
  // convert string to UTF-8
  if ($from=='UTF-7')
   $str = utf7_to_utf8($str);
  else if (($from=='ISO-8859-1') && function_exists('utf8_encode'))
   $str = utf8_encode($str);
  else if ($from!='UTF-8')
   {
   $conv->loadCharset($from);
   $str = $conv->strToUtf8($str);
   }
 
  // encode string for output
  if ($to=='UTF-7')
   return utf8_to_utf7($str);
  else if ($to=='ISO-8859-1' && function_exists('utf8_decode'))
   return utf8_decode($str);
  else if ($to!='UTF-8')
 {
   $conv->loadCharset($to);
   return $conv->utf8ToStr($str);
   }
 
  // return UTF-8 string
return $str;
  }