Changeset 2503 in subversion
- Timestamp:
- May 19, 2009 3:26:47 PM (4 years ago)
- Location:
- trunk/roundcubemail
- Files:
-
- 2 edited
-
CHANGELOG (modified) (1 diff)
-
program/include/main.inc (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/roundcubemail/CHANGELOG
r2491 r2503 2 2 =========================== 3 3 4 - Better support for malformed character names (#1485758) 4 5 - Added possibility to encrypt received header, option 'http_received_header_encrypt', 5 6 added some more logic in encrypt/decrypt functions for security -
trunk/roundcubemail/program/include/main.inc
r2424 r2503 183 183 static $convert_warning = false; 184 184 185 $from = strtoupper($from); 186 $to = $to==NULL ? strtoupper(RCMAIL_CHARSET) : strtoupper($to); 187 $error = false; $conv = null; 188 189 # RFC1642 190 if ($from == 'UNICODE-1-1-UTF-7') 191 $from = 'UTF-7'; 192 if ($to == 'UNICODE-1-1-UTF-7') 193 $to = 'UTF-7'; 185 $error = false; 186 $conv = null; 187 188 $to = empty($to) ? $to = strtoupper(RCMAIL_CHARSET) : rcube_parse_charset($to); 189 $from = rcube_parse_charset($from); 194 190 195 191 if ($from == $to || empty($str) || empty($from)) 196 192 return $str; 197 193 198 $aliases = array(199 'US-ASCII' => 'ISO-8859-1',200 'ANSI_X3.110-1983' => 'ISO-8859-1',201 'ANSI_X3.4-1968' => 'ISO-8859-1',202 'UNKNOWN-8BIT' => 'ISO-8859-15',203 'X-UNKNOWN' => 'ISO-8859-15',204 'X-USER-DEFINED' => 'ISO-8859-15',205 'ISO-8859-8-I' => 'ISO-8859-8',206 'KS_C_5601-1987' => 'EUC-KR',207 );208 209 194 // convert charset using iconv module 210 195 if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') { … … 228 213 $mbstring_list = array_map('strtoupper', $mbstring_list); 229 214 } 230 215 231 216 $mb_from = $aliases[$from] ? $aliases[$from] : $from; 232 217 $mb_to = $aliases[$to] ? $aliases[$to] : $to; … … 236 221 if (mb_check_encoding($str, $mb_from) && ($out = mb_convert_encoding($str, $mb_to, $mb_from))) 237 222 return $out; 223 else 224 // return here, encoding supported, but string is invalid 225 return $str; 238 226 } 239 227 } … … 281 269 'type' => 'php', 282 270 'file' => __FILE__, 283 'message' => "Could not convert string from $from to $to. Make sure iconv is installed or lib/utf8.class is available"271 'message' => "Could not convert string from $from to $to. Make sure iconv/mbstring is installed or lib/utf8.class is available." 284 272 ), true, false); 285 273 … … 289 277 // return UTF-8 string 290 278 return $str; 279 } 280 281 282 /** 283 * Parse and validate charset name string (see #1485758). 284 * Sometimes charset string is malformed, there are also charset aliases 285 * but we need strict names for charset conversion (specially utf8 class) 286 * 287 * @param string Input charset name 288 * @return The validated charset name 289 */ 290 function rcube_parse_charset($charset) 291 { 292 $charset = strtoupper($charset); 293 294 # RFC1642 295 $charset = str_replace('UNICODE-1-1-', '', $charset); 296 297 $aliases = array( 298 'USASCII' => 'ISO-8859-1', 299 'ANSIX31101983' => 'ISO-8859-1', 300 'ANSIX341968' => 'ISO-8859-1', 301 'UNKNOWN8BIT' => 'ISO-8859-15', 302 'XUNKNOWN' => 'ISO-8859-15', 303 'XUSERDEFINED' => 'ISO-8859-15', 304 'ISO88598I' => 'ISO-8859-8', 305 'KSC56011987' => 'EUC-KR', 306 'UNICODE' => 'UTF-8', 307 ); 308 309 $str = preg_replace('/[^a-z0-9]/i', '', $charset); 310 311 if (isset($aliases[$str])) 312 return $aliases[$str]; 313 314 if (preg_match('/UTF(7|8|16|32)(BE|LE)*/', $str, $m)) 315 return 'UTF-' . $m[1] . $m[2]; 316 317 if (preg_match('/ISO8859([0-9]{0,2})/', $str, $m)) 318 return 'ISO-8859-' . ($m[1] ? $m[1] : 1); 319 320 return $charset; 291 321 } 292 322
Note: See TracChangeset
for help on using the changeset viewer.
