Ticket #1484730: roundcube-charset-new.diff

File roundcube-charset-new.diff, 5.6 kB (added by Javer, 11 months ago)

Fixed version of the patch

  • config/main.inc.php.dist

    diff -ur roundcube.r955/config/main.inc.php.dist roundcube/config/main.inc.php.dist
    old new  
    120120// the default locale setting 
    121121$rcmail_config['locale_string'] = 'en'; 
    122122 
     123// the default locale charset 
     124$rcmail_config['locale_charset'] = 'ISO-8859-1'; 
     125 
    123126// use this format for short date display 
    124127$rcmail_config['date_short'] = 'D H:i'; 
    125128 
  • program/include/main.inc

    diff -ur roundcube.r955/program/include/main.inc roundcube/program/include/main.inc
    old new  
    126126 */ 
    127127function rcmail_load_config() 
    128128  { 
    129   global $INSTALL_PATH; 
     129  global $INSTALL_PATH, $utf8_maps; 
    130130 
    131131  // load config file 
    132132  include_once('config/main.inc.php'); 
     
    141141  include_once('config/db.inc.php'); 
    142142  $conf = array_merge($conf, $rcmail_config); 
    143143 
     144  if (empty($conf['locale_charset'])) 
     145    $conf['locale_charset'] = 'ISO-8859-1'; 
     146 
     147  $utf8_maps['KOI8-R'] = UTF8_MAP_DIR . "/KOI8R.map"; 
     148  $utf8_maps['KOI8_R'] = UTF8_MAP_DIR . "/KOI8R.map"; 
     149  $utf8_maps['KOI8R'] = UTF8_MAP_DIR . "/KOI8R.map"; 
     150 
    144151  if (empty($conf['log_dir'])) 
    145152    $conf['log_dir'] = $INSTALL_PATH.'logs'; 
    146153  else 
     
    255262  $IMAP = new rcube_imap($DB); 
    256263  $IMAP->debug_level = $CONFIG['debug_level']; 
    257264  $IMAP->skip_deleted = $CONFIG['skip_deleted']; 
     265  $IMAP->setDefaultCharset($CONFIG['locale_charset']); 
    258266 
    259267 
    260268  // connect with stored session data 
     
    901909 */ 
    902910function rcube_charset_convert($str, $from, $to=NULL) 
    903911  { 
    904   global $MBSTRING; 
     912  global $MBSTRING, $CONFIG; 
    905913 
    906914  $from = strtoupper($from); 
    907915  $to = $to==NULL ? strtoupper(RCMAIL_CHARSET) : strtoupper($to); 
     
    926934      return $out; 
    927935    } 
    928936 
    929   $conv = new utf8(); 
     937  $conv = new utf8($CONFIG['locale_charset']); 
    930938 
    931939  // convert string to UTF-8 
    932940  if ($from=='UTF-7') 
  • program/include/rcube_imap.inc

    diff -ur roundcube.r955/program/include/rcube_imap.inc roundcube/program/include/rcube_imap.inc
    old new  
    6666  var $search_charset = ''; 
    6767  var $debug_level = 1; 
    6868  var $error_code = 0; 
     69  var $charset = ''; 
     70  static $default_charset = 'ISO-8859-1'; 
    6971 
    7072 
    7173  /** 
     
    7880    $this->db = $db_conn; 
    7981    } 
    8082 
     83  function setCharset($charset) { 
     84    if(!empty($charset)) $this->charset = $charset; 
     85    else $this->charset = rcube_imap::$default_charset; 
     86    } 
     87 
     88  function setDefaultCharset($charset) { 
     89    rcube_imap::$default_charset = $charset; 
     90    $this->setCharset($charset); 
     91    } 
    8192 
    8293  /** 
    8394   * PHP 4 object constructor 
     
    889900      $results = $this->_search_index($mailbox, $search); 
    890901 
    891902      // try search with ISO charset (should be supported by server) 
    892       if (empty($results) && !empty($charset) && $charset!='ISO-8859-1') 
    893         $results = $this->search($mbox_name, $criteria, rcube_charset_convert($str, $charset, 'ISO-8859-1'), 'ISO-8859-1'); 
     903      if (empty($results) && !empty($charset) && $charset!=$this->charset) 
     904        $results = $this->search($mbox_name, $criteria, rcube_charset_convert($str, $charset, $this->charset), $this->charset); 
    894905       
    895906      $this->set_search_set($criteria, $str, $results, $charset); 
    896907      return $results; 
     
    12271238      // convert charset (if text or message part) 
    12281239      if ($o_part->ctype_primary=='text' || $o_part->ctype_primary=='message') 
    12291240        { 
    1230         // assume ISO-8859-1 if no charset specified 
     1241        // assume default locale charset if no charset specified 
    12311242        if (empty($o_part->charset)) 
    1232           $o_part->charset = 'ISO-8859-1'; 
     1243          $o_part->charset = $this->charset; 
    12331244 
    12341245        $body = rcube_charset_convert($body, $o_part->charset); 
    12351246        } 
     
    22792290   */ 
    22802291  function decode_header($input, $remove_quotes=FALSE) 
    22812292    { 
    2282     $str = $this->decode_mime_string((string)$input); 
     2293    $str = $this->decode_mime_string((string)$input, !empty($this->charset) ? $this->charset : null ); 
    22832294    if ($str{0}=='"' && $remove_quotes) 
    22842295      $str = str_replace('"', '', $str); 
    22852296     
     
    23182329      } 
    23192330       
    23202331    // no encoding information, use fallback 
    2321     return rcube_charset_convert($input, !empty($fallback) ? $fallback : 'ISO-8859-1'); 
     2332    return rcube_charset_convert($input, !empty($fallback) ? $fallback : rcube_imap::$default_charset ); 
    23222333    } 
    23232334 
    23242335 
  • program/steps/mail/func.inc

    diff -ur roundcube.r955/program/steps/mail/func.inc roundcube/program/steps/mail/func.inc
    old new  
    229229     
    230230    $out .= sprintf("<td class=\"icon\">%s</td>\n", $message_icon ? sprintf($image_tag, $skin_path, $message_icon, '') : ''); 
    231231     
     232    $IMAP->setCharset($header->charset); 
     233     
    232234    // format each col 
    233235    foreach ($a_show_cols as $col) 
    234236      { 
     
    317319    if (empty($header)) 
    318320      continue; 
    319321 
     322    $IMAP->setCharset($header->charset); 
     323 
    320324    // format each col; similar as in rcmail_message_list() 
    321325    foreach ($a_show_cols as $col) 
    322326      { 
     
    815819   
    816820  $header_count = 0; 
    817821   
     822  $IMAP->setCharset($headers['charset']); 
     823 
    818824  // allow the following attributes to be added to the <table> tag 
    819825  $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'cellpadding', 'cellspacing', 'border', 'summary')); 
    820826  $out = '<table' . $attrib_str . ">\n";