Changeset 3036 in subversion


Ignore:
Timestamp:
Oct 12, 2009 12:06:33 PM (4 years ago)
Author:
alec
Message:
  • Fix IE issue with non-UTF-8 characters in AJAX response (#1486159)
Location:
trunk/roundcubemail
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r3034 r3036  
    22=========================== 
    33 
     4- Fix IE issue with non-UTF-8 characters in AJAX response (#1486159) 
    45- Partially fixed "empty body" issue by showing raw body of malformed message (#1486166) 
    56- Fix importing/sending to email address with whitespace (#1486214) 
  • trunk/roundcubemail/program/include/rcube_shared.inc

    r2927 r3036  
    555555} 
    556556 
    557  
    558557/** 
    559558 * A method to guess encoding of a string. 
     
    586585} 
    587586 
     587/** 
     588 * Removes non-unicode characters from input 
     589 * 
     590 * @param mixed $input String or array. 
     591 * @return string 
     592 */ 
     593function rc_utf8_clean($input) 
     594{ 
     595  // handle input of type array 
     596  if (is_array($input)) { 
     597    foreach ($input as $idx => $val) 
     598      $input[$idx] = rc_utf8_clean($val); 
     599    return $input; 
     600  } 
     601   
     602  if (!is_string($input)) 
     603    return $input; 
     604   
     605  // iconv is 10x faster 
     606  if (function_exists('iconv')) 
     607    return iconv('UTF8', 'UTF8//IGNORE', $input); 
     608 
     609  $regexp = '/^('. 
     610//    '[\x00-\x7F]'.                                  // UTF8-1 
     611    '|[\xC2-\xDF][\x80-\xBF]'.                      // UTF8-2 
     612    '|\xE0[\xA0-\xBF][\x80-\xBF]'.                  // UTF8-3 
     613    '|[\xE1-\xEC][\x80-\xBF][\x80-\xBF]'.           // UTF8-3 
     614    '|\xED[\x80-\x9F][\x80-\xBF]'.                  // UTF8-3 
     615    '|[\xEE-\xEF][\x80-\xBF][\x80-\xBF]'.           // UTF8-3 
     616    '|\xF0[\x90-\xBF][\x80-\xBF][\x80-\xBF]'.       // UTF8-4 
     617    '|[\xF1-\xF3][\x80-\xBF][\x80-\xBF][\x80-\xBF]'.// UTF8-4 
     618    '|\xF4[\x80-\x8F][\x80-\xBF][\x80-\xBF]'.       // UTF8-4 
     619    ')$/'; 
     620   
     621  $seq = ''; 
     622  $out = ''; 
     623 
     624  for ($i = 0, $len = strlen($input)-1; $i < $len; $i++) { 
     625    $chr = $input[$i]; 
     626    $ord = ord($chr); 
     627    // 1-byte character 
     628    if ($ord <= 0x7F) { 
     629      if ($seq) 
     630        $out .= preg_match($regexp, $seq) ? $seq : ''; 
     631      $seq = ''; 
     632      $out .= $chr; 
     633    // first (or second) byte of multibyte sequence 
     634    } else if ($ord >= 0xC0) { 
     635      if (strlen($seq)>1) { 
     636        $out .= preg_match($regexp, $seq) ? $seq : ''; 
     637        $seq = ''; 
     638      } else if ($seq && ord($seq) < 0xC0) { 
     639        $seq = ''; 
     640      } 
     641      $seq .= $chr; 
     642    // next byte of multibyte sequence 
     643    } else if ($seq) { 
     644      $seq .= $chr; 
     645    } 
     646  } 
     647 
     648  if ($seq) 
     649    $out .= preg_match($regexp, $seq) ? $seq : ''; 
     650 
     651  return $out; 
     652} 
    588653 
    589654/** 
  • trunk/roundcubemail/program/steps/mail/func.inc

    r3035 r3036  
    458458    if ($header->flagged) 
    459459      $a_msg_flags['flagged'] = 1; 
    460  
     460       
     461    if ($browser->ie) 
     462      $a_msg_cols = rc_utf8_clean($a_msg_cols); 
     463     
    461464    $OUTPUT->command('add_message_row', 
    462465      $header->uid, 
  • trunk/roundcubemail/program/steps/mail/headers.inc

    r1766 r3036  
    2525  if ($source) 
    2626    { 
     27    $browser = new rcube_browser; 
     28     
     29    if ($browser->ie) 
     30      $source = rc_utf8_clean($source);    
     31 
    2732    $source = htmlspecialchars(trim($source)); 
    2833    $source = preg_replace('/\t/', '&nbsp;&nbsp;&nbsp;&nbsp;', $source); 
Note: See TracChangeset for help on using the changeset viewer.