Tiago Gomes wrote:
> Can i omit non-unicode characters to avoid the error: Server Error! (OK).
> The sent-mail folder from another webmail are with non-unicode characters.
> How can omit these characters?
Supplement: this happens in IE8 when rcmail_js_message_list() returns data with
non-unicode characters.
I got function to remove those characters. It fixes the issue, but I'm not sure
if this is one and only solution.
function rc_utf8_clean($str)
{
// iconv is 10x faster
if (function_exists('iconv'))
return iconv('UTF8', 'UTF8//IGNORE', $str);
$regexp = '/^('.
// '[\x00-\x7F]'. // UTF8-1
'|[\xC2-\xDF][\x80-\xBF]'. // UTF8-2
'|\xE0[\xA0-\xBF][\x80-\xBF]'. // UTF8-3
'|[\xE1-\xEC][\x80-\xBF][\x80-\xBF]'. // UTF8-3
'|\xED[\x80-\x9F][\x80-\xBF]'. // UTF8-3
'|[\xEE-\xEF][\x80-\xBF][\x80-\xBF]'. // UTF8-3
'|\xF0[\x90-\xBF][\x80-\xBF][\x80-\xBF]'. // UTF8-4
'|[\xF1-\xF3][\x80-\xBF][\x80-\xBF][\x80-\xBF]'.// UTF8-4
'|\xF4[\x80-\x8F][\x80-\xBF][\x80-\xBF]'. // UTF8-4
')$/';
$seq = '';
$out = '';
for ($i = 0, $len = strlen($str)-1; $i < $len; $i++) {
$chr = $str[$i];
$ord = ord($chr);
// 1-byte character
if ($ord <= 0x7F) {
if ($seq)
$out .= preg_match($regexp, $seq) ? $seq : '';
$seq = '';
$out .= $chr;
// first (or second) byte of multibyte sequence
} else if ($ord >= 0xC0) {
if (strlen($seq)>1) {
$out .= preg_match($regexp, $seq) ? $seq : '';
$seq = '';
} else if ($seq && ord($seq) < 0xC0) {
$seq = '';
}
$seq .= $chr;
// next byte of multibyte sequence
} else if ($seq) {
$seq .= $chr;
}
}
if ($seq)
$out .= preg_match($regexp, $seq) ? $seq : '';
return $out;
}
--
Aleksander 'A.L.E.C' Machniak http://alec.pl gg:2275252
LAN Management System Developer http://lms.org.pl
Roundcube Webmail Project Developer http://roundcube.net
_______________________________________________
List info: http://lists.roundcube.net/dev/