作者 邓超

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	lib/DbQuery.php
@@ -132,10 +132,16 @@ class Home extends Base { @@ -132,10 +132,16 @@ class Home extends Base {
132 if(app()->requestHas('from')){ 132 if(app()->requestHas('from')){
133 // 如果是发件箱 133 // 如果是发件箱
134 if($folder == '发件箱'){ 134 if($folder == '发件箱'){
135 - $where['to'] = app()->request('from');  
136 - if(!$where['to']){ 135 + $tos = app()->request('from');
  136 + if(!$tos){
137 // 不让查询数据 137 // 不让查询数据
138 $where['id'] = 0; 138 $where['id'] = 0;
  139 + }else {
  140 + $tos = array_map(function ($v){
  141 + return "find_in_set('".addcslashes($v,"'")."',`to`)";
  142 + },is_array($tos) ? $tos : [$tos]);
  143 +
  144 + $where['_'][] = '('.implode(' or ',$tos).')';
139 } 145 }
140 }else{ 146 }else{
141 $where['from'] = app()->request('from'); 147 $where['from'] = app()->request('from');
@@ -28,6 +28,12 @@ trait DbQuery { @@ -28,6 +28,12 @@ trait DbQuery {
28 */ 28 */
29 protected int $cache = 0; 29 protected int $cache = 0;
30 30
  31 + /**
  32 + * 没有数据时 也缓存
  33 + * @var bool
  34 + */
  35 + protected bool $cacheNoData = true;
  36 +
31 37
32 public function getClient() 38 public function getClient()
33 { 39 {
@@ -51,8 +57,9 @@ trait DbQuery { @@ -51,8 +57,9 @@ trait DbQuery {
51 * @author:dc 57 * @author:dc
52 * @time 2024/8/14 14:04 58 * @time 2024/8/14 14:04
53 */ 59 */
54 - public function cache(int $ttl){ 60 + public function cache(int $ttl,bool $noData = true){
55 $this->cache = $ttl; 61 $this->cache = $ttl;
  62 + $this->cacheNoData = $noData;
56 return $this; 63 return $this;
57 } 64 }
58 65
@@ -254,9 +261,7 @@ trait DbQuery { @@ -254,9 +261,7 @@ trait DbQuery {
254 * @time 2023/2/17 11:03 261 * @time 2023/2/17 11:03
255 */ 262 */
256 public function value(string|array $sql){ 263 public function value(string|array $sql){
257 -  
258 return $this->getCacheData($sql,null,\PDO::FETCH_COLUMN); 264 return $this->getCacheData($sql,null,\PDO::FETCH_COLUMN);
259 -  
260 $query = $this->query($sql); 265 $query = $this->query($sql);
261 if($query){ 266 if($query){
262 return $query->fetch(\PDO::FETCH_COLUMN); 267 return $query->fetch(\PDO::FETCH_COLUMN);
@@ -280,7 +285,13 @@ trait DbQuery { @@ -280,7 +285,13 @@ trait DbQuery {
280 $key = 'data:'.md5(is_string($sql) ? $sql : json_encode($sql)); 285 $key = 'data:'.md5(is_string($sql) ? $sql : json_encode($sql));
281 if(redis()->has($key)){ 286 if(redis()->has($key)){
282 $this->cache = 0; 287 $this->cache = 0;
283 - return redis()->get($key,$default); 288 + $data = redis()->get($key,$default);
  289 + if(!$this->cacheNoData){
  290 + if($data || $data === 0){
  291 + return $data;
  292 + }
  293 + }
  294 +
284 } 295 }
285 } 296 }
286 $query = $this->query($sql); 297 $query = $this->query($sql);
@@ -251,7 +251,7 @@ class Mail { @@ -251,7 +251,7 @@ class Mail {
251 $blacklist = redis()->get('blacklist:'.$email_id); 251 $blacklist = redis()->get('blacklist:'.$email_id);
252 $blackFolder = ''; 252 $blackFolder = '';
253 if($blacklist){ 253 if($blacklist){
254 - $blackFolder = $db->value(folderSql::originFolder($email_id,'垃圾箱')); 254 + $blackFolder = $db->cache(86400*30)->value(folderSql::originFolder($email_id,'垃圾箱'));
255 } 255 }
256 256
257 // 257 //
@@ -281,11 +281,11 @@ class Mail { @@ -281,11 +281,11 @@ class Mail {
281 281
282 282
283 $uids = array_column($uids,'UID'); 283 $uids = array_column($uids,'UID');
284 - $existsUids = $db->all(listsSql::getUids($email_id,$folder_id,$uids));  
285 - if($existsUids){  
286 - $existsUids = array_column($existsUids,'uid');  
287 - // 获取不存在数据库的uid  
288 - $uids = array_diff($uids,$existsUids); 284 + foreach ($uids as $k=>$uid){
  285 + if($db->cache(86400*30,false)->value(listsSql::first(dbWhere(['email_id'=>$email_id,'folder_id'=>$folder_id,'uid'=>$uid]),'count(*) as c'))){
  286 +
  287 + unset($uids[$k]);
  288 + }
289 } 289 }
290 290
291 291
@@ -313,7 +313,7 @@ class Mail { @@ -313,7 +313,7 @@ class Mail {
313 $unseen = $db->count(listsSql::listCount(dbWhere([ 313 $unseen = $db->count(listsSql::listCount(dbWhere([
314 'seen' => 0, 314 'seen' => 0,
315 'deleted' => 0, 315 'deleted' => 0,
316 - 'email_id' => $email_id, 316 + // 'email_id' => $email_id,
317 'folder_id' => $folder_id, 317 'folder_id' => $folder_id,
318 ]))); 318 ])));
319 $db->update( 319 $db->update(
@@ -37,14 +37,14 @@ class MailFun { @@ -37,14 +37,14 @@ class MailFun {
37 * @time 2023/3/27 13:55 37 * @time 2023/3/27 13:55
38 */ 38 */
39 public static function mb_coding(string $str,array $appcode=[]){ 39 public static function mb_coding(string $str,array $appcode=[]){
40 - $str = trim($str," \t\n\r"); 40 + $str = trim($str);
41 $str = (new Header())->decode($str); 41 $str = (new Header())->decode($str);
42 - try {  
43 - $encode = mb_detect_encoding($str, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));  
44 - if($encode && $encode != 'UTF-8'){  
45 - $str = mb_convert_encoding($str, 'UTF-8', $encode);  
46 - }  
47 - }catch (\Throwable $e){} 42 + // try {
  43 + // $encode = mb_detect_encoding($str, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));
  44 + // if($encode && $encode != 'UTF-8'){
  45 + // $str = mb_convert_encoding($str, 'UTF-8', $encode);
  46 + // }
  47 + // }catch (\Throwable $e){}
48 48
49 49
50 return $str; 50 return $str;