fixed a gb2312 encoding issue

This commit is contained in:
SJ 2013-11-09 14:13:09 +01:00
parent 3ca7b9d2be
commit 2ca6e5a5c0
2 changed files with 23 additions and 6 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
define('BUILD', '2013-11-01 848'); define('BUILD', '2013-11-09 848');
$config = array(); $config = array();

View File

@ -2,6 +2,11 @@
class ModelSearchMessage extends Model { class ModelSearchMessage extends Model {
public $encoding_aliases = array(
'GB2312' => 'GBK',
'GB231280' => 'GBK'
);
public function verify_message($id = '', $data = '') { public function verify_message($id = '', $data = '') {
if($id == '') { return 0; } if($id == '') { return 0; }
@ -117,10 +122,18 @@ class ModelSearchMessage extends Model {
} }
else { else {
$handle = popen(DECRYPT_BINARY . " $id", "r"); $handle = popen(DECRYPT_BINARY . " $id", "r");
while(($buf = fread($handle, DECRYPT_BUFFER_LENGTH))){ while(($buf = fread($handle, DECRYPT_BUFFER_LENGTH))) {
$s .= $buf; $s .= $buf;
} }
pclose($handle); 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); $type = preg_replace("/[\"\'\ ]/", "", $type);
$x = explode("=", $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)){ 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 = ''; } if($s) { $chunk = $s; $s = ''; }
} }
@ -599,7 +615,8 @@ class ModelSearchMessage extends Model {
$what = preg_replace("/^\=\?/", "", $what); $what = preg_replace("/^\=\?/", "", $what);
$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)){ if(preg_match("/\?Q\?/i", $what)){
$x = preg_replace("/^([\w\-]+)\?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)){ if(!preg_match("/utf-8/i", $encoding)){
$s = iconv($encoding, 'utf-8', $s); $s = iconv($encoding, 'utf-8' . '//IGNORE', $s);
} }
} }