作者 邓超

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);
@@ -146,47 +146,47 @@ class Mail { @@ -146,47 +146,47 @@ class Mail {
146 $pid = $db->value(folderSql::has(['uuid'=>md5($email_id.$folder['pname'])])); 146 $pid = $db->value(folderSql::has(['uuid'=>md5($email_id.$folder['pname'])]));
147 $pid = $pid ? $pid : 0; 147 $pid = $pid ? $pid : 0;
148 // try { 148 // try {
149 - $folder_name = '';  
150 - // 已发送  
151 - if(in_array('Send',$folder['check'])){  
152 - $folder_name = folderAlias('Send');  
153 - }  
154 - // 草稿  
155 - elseif(in_array('Drafts',$folder['check'])){  
156 - $folder_name = folderAlias('Drafts');  
157 - }  
158 - // 垃圾  
159 - elseif(in_array('Junk',$folder['check'])){  
160 - $folder_name = folderAlias('Junk');  
161 - }  
162 - // 回收站  
163 - elseif(in_array('Trash',$folder['check'])){  
164 - $folder_name = folderAlias('Trash');  
165 - } 149 + $folder_name = '';
  150 + // 已发送
  151 + if(in_array('Send',$folder['check'])){
  152 + $folder_name = folderAlias('Send');
  153 + }
  154 + // 草稿
  155 + elseif(in_array('Drafts',$folder['check'])){
  156 + $folder_name = folderAlias('Drafts');
  157 + }
  158 + // 垃圾
  159 + elseif(in_array('Junk',$folder['check'])){
  160 + $folder_name = folderAlias('Junk');
  161 + }
  162 + // 回收站
  163 + elseif(in_array('Trash',$folder['check'])){
  164 + $folder_name = folderAlias('Trash');
  165 + }
166 166
167 - if(!$folder_name){  
168 - $fn = explode('/',$folder['parseFolder']);  
169 - $folder_name = folderAlias(end($fn));  
170 - }  
171 - if(!$db->count(folderSql::has(['uuid'=>$uuid]))){  
172 - $db->insert(folderSql::$table,[  
173 - 'email_id' => $email_id,  
174 - 'folder' => folderAlias($folder_name),  
175 - 'origin_folder' => $folder['folder'],  
176 - 'uuid' => $uuid,  
177 - 'pid' => $pid  
178 - ],false);  
179 - }else{  
180 - $db->update(folderSql::$table,[  
181 - 'email_id' => $email_id,  
182 - 'folder' => folderAlias($folder_name),  
183 - 'origin_folder' => $folder['folder'],  
184 - 'uuid' => $uuid,  
185 - 'pid' => $pid  
186 - ],dbWhere(['email_id' => $email_id,'uuid' => $uuid]),false);  
187 - } 167 + if(!$folder_name){
  168 + $fn = explode('/',$folder['parseFolder']);
  169 + $folder_name = folderAlias(end($fn));
  170 + }
  171 + if(!$db->count(folderSql::has(['uuid'=>$uuid]))){
  172 + $db->insert(folderSql::$table,[
  173 + 'email_id' => $email_id,
  174 + 'folder' => folderAlias($folder_name),
  175 + 'origin_folder' => $folder['folder'],
  176 + 'uuid' => $uuid,
  177 + 'pid' => $pid
  178 + ],false);
  179 + }else{
  180 + $db->update(folderSql::$table,[
  181 + 'email_id' => $email_id,
  182 + 'folder' => folderAlias($folder_name),
  183 + 'origin_folder' => $folder['folder'],
  184 + 'uuid' => $uuid,
  185 + 'pid' => $pid
  186 + ],dbWhere(['email_id' => $email_id,'uuid' => $uuid]),false);
  187 + }
188 // }catch (\Throwable $e){ 188 // }catch (\Throwable $e){
189 - // 这里就不处理失败了 189 + // 这里就不处理失败了
190 // } 190 // }
191 191
192 unset($folders[$fk]); 192 unset($folders[$fk]);
@@ -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,13 +281,13 @@ class Mail { @@ -281,13 +281,13 @@ 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);  
289 - } 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'))){
290 286
  287 + unset($uids[$k]);
  288 + }
  289 + }
  290 +
291 291
292 $msgno += $nu; 292 $msgno += $nu;
293 293
@@ -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(
@@ -445,7 +445,7 @@ class Mail { @@ -445,7 +445,7 @@ class Mail {
445 if(php_sapi_name()=='cli'){ 445 if(php_sapi_name()=='cli'){
446 go(function ($id,$header,$data){ 446 go(function ($id,$header,$data){
447 new syncMail($id,$header,$data); 447 new syncMail($id,$header,$data);
448 - }, 448 + },
449 ...[$id,$header,$data] 449 ...[$id,$header,$data]
450 ); 450 );
451 } 451 }
@@ -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;