From 2ca6e5a5c07938e802857e48f78900aa42d14653 Mon Sep 17 00:00:00 2001 From: SJ Date: Sat, 9 Nov 2013 14:13:09 +0100 Subject: [PATCH] fixed a gb2312 encoding issue --- webui/config.php | 2 +- webui/model/search/message.php | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/webui/config.php b/webui/config.php index c08ab1c7..2afe0c0d 100644 --- a/webui/config.php +++ b/webui/config.php @@ -1,6 +1,6 @@ 'GBK', + 'GB231280' => 'GBK' + ); + public function verify_message($id = '', $data = '') { if($id == '') { return 0; } @@ -117,10 +122,18 @@ class ModelSearchMessage extends Model { } else { $handle = popen(DECRYPT_BINARY . " $id", "r"); - while(($buf = fread($handle, DECRYPT_BUFFER_LENGTH))){ + while(($buf = fread($handle, DECRYPT_BUFFER_LENGTH))) { $s .= $buf; } pclose($handle); + + if($s == '') { + $handle = popen(DECRYPT_BINARY . " $id nocrypt", "r"); + while(($buf = fread($handle, DECRYPT_BUFFER_LENGTH))) { + $s .= $buf; + } + pclose($handle); + } } @@ -346,7 +359,10 @@ class ModelSearchMessage extends Model { $type = preg_replace("/[\"\'\ ]/", "", $type); $x = explode("=", $type); - $charset = $x[1]; + $charset = rtrim(strtoupper($x[1])); + + if(isset($this->encoding_aliases[$charset])) { $charset = $this->encoding_aliases[$charset]; } + } } } @@ -476,7 +492,7 @@ class ModelSearchMessage extends Model { } if($charset && !preg_match("/utf-8/i", $charset)){ - $s = @iconv($charset, 'utf-8', $chunk); + $s = @iconv($charset, 'utf-8' . '//IGNORE', $chunk); if($s) { $chunk = $s; $s = ''; } } @@ -599,7 +615,8 @@ class ModelSearchMessage extends Model { $what = preg_replace("/^\=\?/", "", $what); $what = preg_replace("/\?\=$/", "", $what); - $encoding = substr($what, 0, strpos($what, '?')); + $encoding = strtoupper(substr($what, 0, strpos($what, '?'))); + if(isset($this->encoding_aliases[$encoding])) { $encoding = $this->encoding_aliases[$encoding]; } if(preg_match("/\?Q\?/i", $what)){ $x = preg_replace("/^([\w\-]+)\?Q\?/i", "", $what); @@ -616,7 +633,7 @@ class ModelSearchMessage extends Model { } if(!preg_match("/utf-8/i", $encoding)){ - $s = iconv($encoding, 'utf-8', $s); + $s = iconv($encoding, 'utf-8' . '//IGNORE', $s); } }