作者 邓超

优化 back

@@ -24,7 +24,7 @@ foreach ($tables as $table){ @@ -24,7 +24,7 @@ foreach ($tables as $table){
24 24
25 file_put_contents($name,$c['Create Table']); 25 file_put_contents($name,$c['Create Table']);
26 26
27 - if(in_array($table,['lists_auto','lists','bodies','bodies_back','lists_hot'])){ 27 + if(in_array($table,['lists_auto','lists','lists_back','bodies','bodies_back','lists_hot'])){
28 continue; 28 continue;
29 } 29 }
30 30
1 -<?php  
2 -  
3 -include_once "../vendor/autoload.php";  
4 -  
5 -/**  
6 - * 把lists表的is_hots字段为1的记录插入到list_hot表中 并删除list表中的这些记录  
7 - */  
8 -  
9 -// 进程管理器  
10 -$pm = new \Swoole\Process\Manager();  
11 -  
12 -// 启动业务进程  
13 -$pm->addBatch(10,function (\Swoole\Process\Pool $pool, int $worker_id){  
14 - if($worker_id == 0){  
15 - // 一个月以前的数据  
16 - $one_month_ago = strtotime(date('Y-m-d', strtotime('-1 month')));  
17 -  
18 -// 查询lists lists_hot  
19 - $id = redis()->rPop('lists_to_lists_hot');  
20 - if(!$id) {  
21 - $id = 389884523;  
22 - }else{  
23 - $id = redis()->rPush('lists_to_lists_hot', $id);  
24 - }  
25 - $limit = 100;  
26 - while (true){  
27 -// echo "正在查询 id {$id}\n";  
28 - $data = db()->all("select `id` from lists where id > {$id} and `is_hots` = 1 and `udate` < {$one_month_ago} limit {$limit};");  
29 - if($data){  
30 - foreach ($data as $item) {  
31 - $id = $item['id'];  
32 - redis()->rPush('lists_to_lists_hot', $item['id']);  
33 - }  
34 - }else{  
35 - sleep(5);  
36 - }  
37 - }  
38 - }else{  
39 -  
40 - // 迁移数据  
41 - while (true){  
42 - $id = redis()->lPop('lists_to_lists_hot');  
43 - if($id){  
44 - $data = db()->first("select * from lists where `id` = {$id} limit 1;");  
45 - if($data){  
46 - try {  
47 - db()->throw()->insert('lists_back', $data);  
48 - } catch (\Exception $e) {  
49 - @file_put_contents('lists_to_lists_hot.data.error.log', json_encode($data)."\n", FILE_APPEND);  
50 - }  
51 - db()->delete('lists', ['id' => $id]);  
52 -  
53 - echo $id . " ok \n";  
54 - }  
55 - }else{  
56 - sleep(1);  
57 - }  
58 - }  
59 -  
60 -  
61 - }  
62 -});  
63 -  
64 -$pm->start();  
65 -  
66 -  
67 -  
68 -  
@@ -237,10 +237,7 @@ class SyncToEsCmd { @@ -237,10 +237,7 @@ class SyncToEsCmd {
237 */ 237 */
238 public function getDataByEs($id,$is_check_body) { 238 public function getDataByEs($id,$is_check_body) {
239 try { 239 try {
240 - $data = $this->db->throw()->first(\Model\listsSql::first('`id` = '.$id));  
241 - if(!$data){  
242 - $data = $this->db->throw()->first(\Model\listsSql::firstHot('`id` = '.$id));  
243 - } 240 + $data = \Model\listsSql::first($this->db,'`id` = '.$id,'*',true);
244 }catch (Throwable $e){ 241 }catch (Throwable $e){
245 $this->log([$id]); 242 $this->log([$id]);
246 // redis()->rPush('sync_to_es',$origin_id); 243 // redis()->rPush('sync_to_es',$origin_id);
@@ -260,7 +260,7 @@ class Folder extends Base { @@ -260,7 +260,7 @@ class Folder extends Base {
260 } 260 }
261 261
262 // 是否存在邮件 262 // 是否存在邮件
263 - if(db()->count(listsSql::first(dbWhere(['folder_id'=>$folder['id'],'email_id'=>$email['id']])))){ 263 + if(listsSql::count(db(),dbWhere(['folder_id'=>$folder['id'],'email_id'=>$email['id']]))){
264 app()->e('folder_delete_exist_mail'); 264 app()->e('folder_delete_exist_mail');
265 } 265 }
266 266
@@ -23,327 +23,46 @@ use function Swoole\Coroutine\Http\request; @@ -23,327 +23,46 @@ use function Swoole\Coroutine\Http\request;
23 * Class Home 23 * Class Home
24 * @package Controller 24 * @package Controller
25 */ 25 */
26 -class Home extends Base { 26 +class Home extends Base
  27 +{
27 28
28 29
29 /** 30 /**
30 - * 邮件列表  
31 - * @author:dc  
32 - * @time 2023/2/17 14:12  
33 - */  
34 - public function lists(){  
35 -  
36 - // 分页 页数  
37 - $page = app()->request('page',1,'intval');  
38 - $page = $page ? $page : 1;  
39 -  
40 - $limit = app()->request('limit',20,'intval');  
41 - $limit = $limit ? $limit : 1;  
42 -  
43 - // 指定id  
44 - $ids = app()->request('mail_id');  
45 - $ids = is_array($ids) ? $ids : [$ids];  
46 - foreach ($ids as $i=>$d){  
47 - if(!is_numeric($d)){  
48 - unset($ids[$i]);  
49 - }  
50 - }  
51 -  
52 - // 附件  
53 - $attachment = app()->request('attachment',0,'bool_Val');  
54 - // 已读/未读  
55 - $seen = app()->request('seen',-1,'intval');  
56 - // 软删  
57 - $deleted = app()->request('deleted',0,'intval');  
58 -  
59 -  
60 - $where = ['email_id'=>$this->getEmails('id')];  
61 -  
62 -  
63 - $folder_id = ['-'];  
64 - if (app()->requestArr('folder_id')){  
65 - $folder_id = app()->requestArr('folder_id');  
66 - }else{  
67 - // 目录  
68 - $folder = app()->request('folder','收件箱','folderAlias');  
69 - if($folder !== true || $folder!=='true'){  
70 - $folderList = db()->all(folderSql::all($where['email_id']));  
71 -  
72 - // 文件夹id  
73 - if($folderList){  
74 - foreach ($folderList as $item){  
75 - if(  
76 - // 数组文件夹  
77 - (is_array($folder) && in_array($item['folder'],$folder))  
78 - || $item['folder'] == $folder  
79 - ){  
80 - $folder_id[] = $item['id'];  
81 - }  
82 - }  
83 - }  
84 - }  
85 -  
86 - }  
87 -  
88 - if(!$folder_id){  
89 - app()->e('folder_not_fount');  
90 - }  
91 - $folder_id = array_filter($folder_id,'is_int');  
92 -  
93 - //目录  
94 - if($folder_id) $where['folder_id'] = array_values($folder_id);  
95 - if($ids) $where['id'] = $ids;  
96 -  
97 - if(paramHas('attachment')){  
98 - $where['is_file'] = $attachment ? 1 : 0; //附件  
99 - }  
100 -  
101 -  
102 - // 软删  
103 - $where['deleted'] = $deleted;  
104 - // 已读/未读  
105 - if(paramHas('seen')){  
106 - if(in_array($seen,[0,1])){  
107 - $where['seen'] = $seen;  
108 - }  
109 - }  
110 -  
111 - $where['_'] = [];  
112 - // 搜索关键字  
113 - $keyword = app()->request('keyword','',['htmlspecialchars','addslashes']);  
114 - if($keyword){  
115 - $where['_'][] = '`subject` like "%'.$keyword.'%"';  
116 - }  
117 -  
118 - // 那个发的  
119 - $address = app()->request('address');  
120 - if($address){  
121 - if(is_array($address)){  
122 - // 发贱人  
123 - if(Verify::sEmail($address['from']??'')){  
124 - $where['from'] = $address['from'];  
125 - }  
126 - // 收件人  
127 - if(Verify::sEmail($address['to']??'')){  
128 - $where['_'][] = '`to_name` like "%'.$address.'%"';  
129 - }  
130 -  
131 - }else if(Verify::sEmail($address)){  
132 - // 收件人/发件人  
133 - $where['_'][] = '(`from` = "'.$address.'" or `to_name` like "%'.$address.'%")';  
134 - }  
135 - }  
136 - // from 搜索收件人  
137 - if(app()->requestHas('from')){  
138 - // 如果是发件箱  
139 - if($folder == '发件箱'){  
140 - $tos = app()->request('from');  
141 - if(!$tos){  
142 - // 不让查询数据  
143 - $where['id'] = 0;  
144 - }else {  
145 - $tos = array_map(function ($v){  
146 - return "find_in_set('".addcslashes($v,"'")."',`to`)";  
147 - },is_array($tos) ? $tos : [$tos]);  
148 -  
149 - $where['_'][] = '('.implode(' or ',$tos).')';  
150 - }  
151 - }else{  
152 - $where['from'] = app()->request('from');  
153 - if(!$where['from']){  
154 - // 不让查询数据  
155 - $where['id'] = 0;  
156 - }  
157 - }  
158 -  
159 -  
160 - }  
161 -  
162 -  
163 - // 回复  
164 - if (paramHas('answered')){  
165 - $where['answered'] = app()->request('answered',0,'bool_Val')?1:0;  
166 - }  
167 -  
168 - // 这个主要是来筛选 是否是自己发送的  
169 - $fromto = app()->request('formorto');  
170 - if($fromto=='from'){  
171 - $where['from'] = $this->getEmails('email');  
172 - }elseif ($fromto=='to'){  
173 - $where['from.notin'] = $this->getEmails('email');  
174 - }  
175 -  
176 - /**  
177 - * 不查询哪些发件人的邮件  
178 - */  
179 - $form_not_in = app()->request('from_not_in');  
180 - if($form_not_in){  
181 - $form_not_in = is_array($form_not_in) ? $form_not_in : [$form_not_in];  
182 - $form_not_in = array_filter($form_not_in,function ($v){  
183 - if(is_string($v) && Verify::sEmail($v)){  
184 - return true;  
185 - }  
186 - return false;  
187 - });  
188 - if($form_not_in){  
189 - if(isset($where['from.notin'])){  
190 - $where['from.notin'] = array_merge($where['from.notin'],$form_not_in);  
191 - }else{  
192 - $where['from.notin'] = $form_not_in;  
193 - }  
194 -  
195 - }  
196 - }  
197 - if(!empty($where['from.notin'])){  
198 - $where['from.notin'] = array_unique($where['from.notin']);  
199 - }  
200 -  
201 -  
202 -  
203 - $lists = db()->all(  
204 - listsSql::lists(  
205 - dbWhere($where),  
206 - $page,  
207 - $limit  
208 - )  
209 - );  
210 - $lists = $lists ? $lists : [];  
211 -  
212 - // map  
213 - $lists = array_map(function ($v){  
214 - $v['uuid'] = get_email_uuid($v['subject'],$v['udate'],$v['from'],$v['to'],$v['size']);  
215 - if(!empty($v['description'])){  
216 - $v['description'] = @html_entity_decode($v['description'], ENT_COMPAT, 'UTF-8');  
217 - }  
218 - $v['to_name'] = @json_decode($v['to_name'],true);  
219 - $v['to_name'] = $v['to_name']?:[];  
220 - if($v['to_name']){  
221 - if(!empty($v['to_name'][0]['email'])){  
222 - $v['to'] = $v['to_name'][0]['email'];  
223 - }  
224 - $v['to_name'] = MailFun::mb_coding($v['to_name'][0]['name']??'');  
225 - }  
226 - if(is_array($v['to_name'])){  
227 - $v['to_name'] = '';  
228 - }  
229 - // 邮件箱  
230 - $v['folder_name'] = db()->cache(86400)->value(folderSql::first($v['folder_id'],'folder'));  
231 - return $v;  
232 - },$lists);  
233 -  
234 - // 总数  
235 - $total = db()->count(  
236 - listsSql::listCount(dbWhere($where))  
237 - );  
238 -  
239 - app()->_json(listsPage($lists,$total,$page,$limit));  
240 -  
241 - }  
242 -  
243 - /**  
244 - * 统计  
245 - * @throws \Lib\Err  
246 - * @author:dc  
247 - * @time 2024/10/14 16:20  
248 - */  
249 - public function count()  
250 - {  
251 -  
252 - $where = [];  
253 -  
254 -  
255 - $start_time = app()->request('start_time',0,'intval');  
256 - $end_time = app()->request('end_time',0,'intval');  
257 -// if($start_time || $end_time){  
258 -// $where['email_id'] = $this->getEmails('id');  
259 -// }  
260 - $where['_'] = [];  
261 - if($start_time){  
262 - $where['_'][] = '`udate` >= '.$start_time;  
263 - }  
264 - if($end_time){  
265 - $where['_'][] = '`udate` <= '.$end_time;  
266 - }  
267 -  
268 - $where['_'] && $where['_'] = implode(' and ',$where['_']);  
269 -  
270 - $where['folder_id'] = [];  
271 -  
272 - // 目录  
273 - $folderList = db()->all(folderSql::all($this->getEmails('id')));  
274 -  
275 - // 文件夹id  
276 - foreach ($folderList as $item) {  
277 - if ($item['folder'] == '收件箱') {  
278 - $where['folder_id'][] = $item['id'];  
279 - }  
280 - }  
281 -  
282 -  
283 - // 软删  
284 - $where['deleted'] = 0;  
285 -  
286 - // 总数  
287 - $inbox = db()->cache(3600)->count(listsSql::listCount(dbWhere($where)));  
288 -  
289 - if(app()->request('show')=='inbox'){  
290 - app()->_json(['inbox'=>$inbox]);  
291 - }  
292 -  
293 - // 未读  
294 - $where['seen'] = 0;  
295 - $unseen = db()->cache(3600)->count(listsSql::listCount(dbWhere($where)));  
296 -  
297 -  
298 - $where['folder_id'] = [];  
299 - foreach ($folderList as $item) {  
300 - if ($item['folder'] == '发件箱') {  
301 - $where['folder_id'][] = $item['id'];  
302 - }  
303 - }  
304 - unset($where['seen']);  
305 - //发件箱  
306 - $send = db()->cache(3600)->count(listsSql::listCount(dbWhere($where)));  
307 -  
308 - app()->_json(['inbox'=>$inbox,'unseen'=>$unseen,'send'=>$send]);  
309 - }  
310 -  
311 - /**  
312 * 检测邮箱状态 31 * 检测邮箱状态
313 * @author:dc 32 * @author:dc
314 * @time 2023/3/28 16:19 33 * @time 2023/3/28 16:19
315 */ 34 */
316 - public function check(){  
317 - 35 + public function check()
  36 + {
318 37
319 38
320 - $lists = db()->all(emailSql::getValues(['email'=>web_request_emails()],'`id`,`pwd_error`,`email`,`password`,`imap`'));  
321 - if(count($lists)>1){  
322 - return array_column($lists,'pwd_error','email'); 39 + $lists = db()->all(emailSql::getValues(['email' => web_request_emails()], '`id`,`pwd_error`,`email`,`password`,`imap`'));
  40 + if (count($lists) > 1) {
  41 + return array_column($lists, 'pwd_error', 'email');
323 } 42 }
324 43
325 - foreach ($lists as $k=>$list){ 44 + foreach ($lists as $k => $list) {
326 // if(!$list['pwd_error']){ 45 // if(!$list['pwd_error']){
327 - $list['host'] = $list['imap'];  
328 - $list['password'] = base64_decode($list['password']);  
329 - $imap = ImapPool::get(new ImapConfig($list));  
330 - $n = $imap->login()->isOk();  
331 - if($n){  
332 - if($lists[$k]['pwd_error']){  
333 - db()->update(emailSql::$table,['pwd_error'=>0],'`id` = '.$list['id']);  
334 - }  
335 - $lists[$k]['pwd_error'] = 0;  
336 - }else{  
337 - if(!$lists[$k]['pwd_error']){  
338 - db()->update(emailSql::$table,['pwd_error'=>1],'`id` = '.$list['id']);  
339 - }  
340 - $lists[$k]['pwd_error'] = 1; 46 + $list['host'] = $list['imap'];
  47 + $list['password'] = base64_decode($list['password']);
  48 + $imap = ImapPool::get(new ImapConfig($list));
  49 + $n = $imap->login()->isOk();
  50 + if ($n) {
  51 + if ($lists[$k]['pwd_error']) {
  52 + db()->update(emailSql::$table, ['pwd_error' => 0], '`id` = ' . $list['id']);
341 } 53 }
  54 + $lists[$k]['pwd_error'] = 0;
  55 + } else {
  56 + if (!$lists[$k]['pwd_error']) {
  57 + db()->update(emailSql::$table, ['pwd_error' => 1], '`id` = ' . $list['id']);
  58 + }
  59 + $lists[$k]['pwd_error'] = 1;
  60 + }
342 // } 61 // }
343 62
344 } 63 }
345 64
346 - return array_column($lists,'pwd_error','email'); 65 + return array_column($lists, 'pwd_error', 'email');
347 66
348 } 67 }
349 68
@@ -353,35 +72,36 @@ class Home extends Base { @@ -353,35 +72,36 @@ class Home extends Base {
353 * @author:dc 72 * @author:dc
354 * @time 2023/2/18 17:32 73 * @time 2023/2/18 17:32
355 */ 74 */
356 - public function send_mail(){ 75 + public function send_mail()
  76 + {
357 77
358 $email = $this->getEmail(); 78 $email = $this->getEmail();
359 79
360 - $yzemail = function(&$value,$field){  
361 - if($value){  
362 - if(!is_array($value)){  
363 - if(@json_decode($value,true)){  
364 - $value = json_decode($value,true);  
365 - }else{  
366 - $value = [['email'=>$value,'name'=>'']]; 80 + $yzemail = function (&$value, $field) {
  81 + if ($value) {
  82 + if (!is_array($value)) {
  83 + if (@json_decode($value, true)) {
  84 + $value = json_decode($value, true);
  85 + } else {
  86 + $value = [['email' => $value, 'name' => '']];
367 } 87 }
368 } 88 }
369 - foreach ($value as $item){  
370 - if(!Verify::sEmail($item['email'])){  
371 - app()->e([$field.'_verify_error',$item['email']]); 89 + foreach ($value as $item) {
  90 + if (!Verify::sEmail($item['email'])) {
  91 + app()->e([$field . '_verify_error', $item['email']]);
372 } 92 }
373 } 93 }
374 } 94 }
375 }; 95 };
376 96
377 $formData = Verify::checks([ 97 $formData = Verify::checks([
378 - 'nickname|'.__('nickname') => ['max'=>50],  
379 - 'subject|'.__('subject') => ['required','max'=>500],  
380 - 'body|'.__('body_email') => ['required'],  
381 - 'tos|'.__('to_email') => ['required',$yzemail],  
382 - 'cc|'.__('to_cc') => [$yzemail],  
383 - 'bcc|'.__('to_bcc') => [$yzemail],  
384 - 'priority|'.__('priority_email') => ['in'=>[1,3,5]], 98 + 'nickname|' . __('nickname') => ['max' => 50],
  99 + 'subject|' . __('subject') => ['required', 'max' => 500],
  100 + 'body|' . __('body_email') => ['required'],
  101 + 'tos|' . __('to_email') => ['required', $yzemail],
  102 + 'cc|' . __('to_cc') => [$yzemail],
  103 + 'bcc|' . __('to_bcc') => [$yzemail],
  104 + 'priority|' . __('priority_email') => ['in' => [1, 3, 5]],
385 // 'attachment|'.__('files_email') => [ 105 // 'attachment|'.__('files_email') => [
386 // 'file'=>[ 106 // 'file'=>[
387 // 'ext' => [], 107 // 'ext' => [],
@@ -389,166 +109,164 @@ class Home extends Base { @@ -389,166 +109,164 @@ class Home extends Base {
389 // 'mine' => [] 109 // 'mine' => []
390 // ] 110 // ]
391 // ], 111 // ],
392 - 'receipt|'.__('receipt_email') => []  
393 - ],[ 112 + 'receipt|' . __('receipt_email') => []
  113 + ], [
394 114
395 ]); 115 ]);
396 116
397 117
398 $sendData = []; 118 $sendData = [];
399 - $sendData['email'] = $email['email'];  
400 - $sendData['nickname'] = $formData['nickname']??'';  
401 - $sendData['tos'] = $formData['tos'];  
402 - if(count($sendData['tos'])>100){  
403 - app()->e(['tos_number_error',100]); 119 + $sendData['email'] = $email['email'];
  120 + $sendData['nickname'] = $formData['nickname'] ?? '';
  121 + $sendData['tos'] = $formData['tos'];
  122 + if (count($sendData['tos']) > 100) {
  123 + app()->e(['tos_number_error', 100]);
404 } 124 }
405 // 抄送 125 // 抄送
406 $sendData['cc'] = []; 126 $sendData['cc'] = [];
407 - if(($formData['isCc']??0) && !empty($formData['cc'])){  
408 - $sendData['cc'] = $formData['cc']; 127 + if (($formData['isCc'] ?? 0) && !empty($formData['cc'])) {
  128 + $sendData['cc'] = $formData['cc'];
409 } 129 }
410 - if(count($sendData['cc'])>10){  
411 - app()->e(['cc_number_error',10]); 130 + if (count($sendData['cc']) > 10) {
  131 + app()->e(['cc_number_error', 10]);
412 } 132 }
413 // 密送 133 // 密送
414 $sendData['bcc'] = []; 134 $sendData['bcc'] = [];
415 - if(($formData['isBcc']??0) && !empty($formData['bcc'])){  
416 - $sendData['bcc'] = $formData['bcc']; 135 + if (($formData['isBcc'] ?? 0) && !empty($formData['bcc'])) {
  136 + $sendData['bcc'] = $formData['bcc'];
417 } 137 }
418 138
419 // 添加自定义头信息 预热邮件 139 // 添加自定义头信息 预热邮件
420 - if(!empty($formData['aicc-hot'])){ 140 + if (!empty($formData['aicc-hot'])) {
421 $sendData['mail-header'] = [ 141 $sendData['mail-header'] = [
422 - 'Aicc-Hot-Mail' => 'hot' // 预热邮件 142 + 'Aicc-Hot-Mail' => 'hot' // 预热邮件
423 ]; 143 ];
424 } 144 }
425 145
426 - if(count($sendData['bcc'])>10){  
427 - app()->e(['bcc_number_error',10]); 146 + if (count($sendData['bcc']) > 10) {
  147 + app()->e(['bcc_number_error', 10]);
428 } 148 }
429 $sendData['reply_to'] = [];//回复到那个邮件 149 $sendData['reply_to'] = [];//回复到那个邮件
430 //Attachments 附件 上传的 150 //Attachments 附件 上传的
431 $sendData['attachment'] = []; 151 $sendData['attachment'] = [];
432 // 这个是直接上传文件 152 // 这个是直接上传文件
433 $attachment = app()->file('attachment'); 153 $attachment = app()->file('attachment');
434 - if($attachment){  
435 - foreach ($attachment as $file){  
436 - if($file->move()){ 154 + if ($attachment) {
  155 + foreach ($attachment as $file) {
  156 + if ($file->move()) {
437 $sendData['attachment'][] = [ 157 $sendData['attachment'][] = [
438 - 'name' => $file->name,  
439 - 'filename' => $file->name,  
440 - 'signName' => $file->saveName,  
441 - 'path' => $file->savePath.$file->saveName 158 + 'name' => $file->name,
  159 + 'filename' => $file->name,
  160 + 'signName' => $file->saveName,
  161 + 'path' => $file->savePath . $file->saveName
442 ]; 162 ];
443 - }else{  
444 - app()->e(['attachment_upload_error',$file->name]); 163 + } else {
  164 + app()->e(['attachment_upload_error', $file->name]);
445 } 165 }
446 } 166 }
447 } 167 }
448 // 这个是通过了上传接口上传的文件 168 // 这个是通过了上传接口上传的文件
449 $attachment = app()->request('attachmentapi'); 169 $attachment = app()->request('attachmentapi');
450 - if($attachment){  
451 - foreach ($attachment as $file){  
452 - $file = json_decode($file,true);  
453 - if(empty($file['data']['saveName'])|| !is_file(PUBLIC_PATH.$file['data']['saveName'])){  
454 - app()->e('附件('.$file['data']['name'].")异常"); 170 + if ($attachment) {
  171 + foreach ($attachment as $file) {
  172 + $file = json_decode($file, true);
  173 + if (empty($file['data']['saveName']) || !is_file(PUBLIC_PATH . $file['data']['saveName'])) {
  174 + app()->e('附件(' . $file['data']['name'] . ")异常");
455 } 175 }
456 $sendData['attachment'][] = [ 176 $sendData['attachment'][] = [
457 - 'name' => $file['data']['name'],  
458 - 'filename' => $file['data']['name'],  
459 - 'signName' => $file['data']['saveName'],  
460 - 'path' => PUBLIC_PATH.$file['data']['saveName'] 177 + 'name' => $file['data']['name'],
  178 + 'filename' => $file['data']['name'],
  179 + 'signName' => $file['data']['saveName'],
  180 + 'path' => PUBLIC_PATH . $file['data']['saveName']
461 ]; 181 ];
462 } 182 }
463 } 183 }
464 184
465 // 远程路径,云文件 185 // 远程路径,云文件
466 $attachmentUrl = app()->request('attachmentUrl'); 186 $attachmentUrl = app()->request('attachmentUrl');
467 - if(is_array($attachmentUrl)){  
468 - foreach ($attachmentUrl as $file){  
469 - $file = is_array($file) ? $file : json_decode($file,true);  
470 - if(!empty($file['url']) && !empty($file['name'])){  
471 - $file = new UploadFile($file['name'],$file['url']);  
472 - if($file->move()){ 187 + if (is_array($attachmentUrl)) {
  188 + foreach ($attachmentUrl as $file) {
  189 + $file = is_array($file) ? $file : json_decode($file, true);
  190 + if (!empty($file['url']) && !empty($file['name'])) {
  191 + $file = new UploadFile($file['name'], $file['url']);
  192 + if ($file->move()) {
473 $sendData['attachment'][] = [ 193 $sendData['attachment'][] = [
474 - 'name' => $file->name,  
475 - 'filename' => $file->name,  
476 - 'signName' => $file->saveName,  
477 - 'path' => $file->savePath.$file->saveName 194 + 'name' => $file->name,
  195 + 'filename' => $file->name,
  196 + 'signName' => $file->saveName,
  197 + 'path' => $file->savePath . $file->saveName
478 ]; 198 ];
479 - }else{  
480 - app()->e(['attachment_upload_error',$file->name]); 199 + } else {
  200 + app()->e(['attachment_upload_error', $file->name]);
481 } 201 }
482 } 202 }
483 203
484 } 204 }
485 } 205 }
486 $sendData['receipt'] = empty($formData['receipt']) ? '' : 1;// 回执,阅读后收回执的邮箱 206 $sendData['receipt'] = empty($formData['receipt']) ? '' : 1;// 回执,阅读后收回执的邮箱
487 - $sendData['priority'] = $formData['priority']??3;// 是否紧急邮件 207 + $sendData['priority'] = $formData['priority'] ?? 3;// 是否紧急邮件
488 $sendData['subject'] = $formData['subject'];// //Content 主题,标题 208 $sendData['subject'] = $formData['subject'];// //Content 主题,标题
489 // 删除script标记 209 // 删除script标记
490 - $sendData['body'] = strip_tags_content($formData['body'],'<script>',true); 210 + $sendData['body'] = strip_tags_content($formData['body'], '<script>', true);
491 // 下划线 211 // 下划线
492 - $sendData['body'] = str_replace('class="sensitive-word"',' ',$sendData['body']);  
493 - $sendData['body'] = str_replace('style="text-decoration-line: underline; text-decoration-style: wavy; text-decoration-color: red;"',' ',$sendData['body']); 212 + $sendData['body'] = str_replace('class="sensitive-word"', ' ', $sendData['body']);
  213 + $sendData['body'] = str_replace('style="text-decoration-line: underline; text-decoration-style: wavy; text-decoration-color: red;"', ' ', $sendData['body']);
494 214
495 // 不重要的信息 215 // 不重要的信息
496 - $sendData['jobName'] = $formData['jobName']??'';//任务标题  
497 - $sendData['massSuit'] = $formData['massSuit']??0;// 是否是群发单显 216 + $sendData['jobName'] = $formData['jobName'] ?? '';//任务标题
  217 + $sendData['massSuit'] = $formData['massSuit'] ?? 0;// 是否是群发单显
498 218
499 // 定时发送时间 219 // 定时发送时间
500 - $timer = app()->request('timerValue',0);  
501 - if(is_numeric($timer) && $timer){  
502 - $timer = time()+$timer;  
503 - }else if (is_string($timer)){ 220 + $timer = app()->request('timerValue', 0);
  221 + if (is_numeric($timer) && $timer) {
  222 + $timer = time() + $timer;
  223 + } else if (is_string($timer)) {
504 $timer = strtotime($timer); 224 $timer = strtotime($timer);
505 - }else{ 225 + } else {
506 $timer = 0; 226 $timer = 0;
507 } 227 }
508 // 是否存草稿 228 // 是否存草稿
509 - if(app()->request('saveType')=='draft'){ 229 + if (app()->request('saveType') == 'draft') {
510 // 保存 230 // 保存
511 - $draftid = listsSql::saveDraft($sendData,$email,app()->request('draft_id',0,'intval')); 231 + $draftid = listsSql::saveDraft($sendData, $email, app()->request('draft_id', 0, 'intval'));
512 // 保存失败 232 // 保存失败
513 - if($draftid){  
514 - app()->_json(['draft_id'=>$draftid]); 233 + if ($draftid) {
  234 + app()->_json(['draft_id' => $draftid]);
515 } 235 }
516 app()->e('save_draft_error'); 236 app()->e('save_draft_error');
517 237
518 - }  
519 - // 定时发送 或者是单条发送  
520 - else if((app()->request('timer') && $timer > time()) || $sendData['massSuit']){ 238 + } // 定时发送 或者是单条发送
  239 + else if ((app()->request('timer') && $timer > time()) || $sendData['massSuit']) {
521 240
522 - if($sendData['massSuit']){ 241 + if ($sendData['massSuit']) {
523 // 每次发送间隔的时间 242 // 每次发送间隔的时间
524 - $sendData['masssuit_interval_send'] = app()->request('masssuit_interval_send');  
525 - $sendData['masssuit_interval_send']['start'] = intval($sendData['masssuit_interval_send']['start']??0);  
526 - $sendData['masssuit_interval_send']['end'] = intval($sendData['masssuit_interval_send']['end']??1); 243 + $sendData['masssuit_interval_send'] = app()->request('masssuit_interval_send');
  244 + $sendData['masssuit_interval_send']['start'] = intval($sendData['masssuit_interval_send']['start'] ?? 0);
  245 + $sendData['masssuit_interval_send']['end'] = intval($sendData['masssuit_interval_send']['end'] ?? 1);
527 } 246 }
528 247
529 248
530 // 插入任务 249 // 插入任务
531 - $job_id = db()->insert(sendJobsSql::$table,[  
532 - 'email_id' => $email['id'],  
533 - 'maildata' => $sendData,  
534 - 'title' => $sendData['jobName'] ? : $sendData['subject'],  
535 - 'total' => count($sendData['tos']),  
536 - 'send_time' => $timer?:time() 250 + $job_id = db()->insert(sendJobsSql::$table, [
  251 + 'email_id' => $email['id'],
  252 + 'maildata' => $sendData,
  253 + 'title' => $sendData['jobName'] ?: $sendData['subject'],
  254 + 'total' => count($sendData['tos']),
  255 + 'send_time' => $timer ?: time()
537 ]); 256 ]);
538 - if($job_id){ 257 + if ($job_id) {
539 // 返回任务id 258 // 返回任务id
540 - app()->_json(['job_id'=>$job_id]); 259 + app()->_json(['job_id' => $job_id]);
541 } 260 }
542 261
543 app()->e('send_timer_job_error'); 262 app()->e('send_timer_job_error');
544 - }  
545 - else{ 263 + } else {
546 // 立即发送 264 // 立即发送
547 - $email['hot_email'] = db()->cache(86400,false)->count("select count(*) from `hot_mail` where ".dbWhere(['email'=>$email['email']])); 265 + $email['hot_email'] = db()->cache(86400, false)->count("select count(*) from `hot_mail` where " . dbWhere(['email' => $email['email']]));
548 $email['not_proxy'] = app()->request('not_proxy');//是否要代理 266 $email['not_proxy'] = app()->request('not_proxy');//是否要代理
549 - $result = MailFun::sendEmail($sendData,$email);  
550 - if($result[0]){  
551 - app()->_json(['messageId' => $result[1]]); 267 + $result = MailFun::sendEmail($sendData, $email);
  268 + if ($result[0]) {
  269 + app()->_json(['messageId' => $result[1]]);
552 } 270 }
553 // 错误 271 // 错误
554 app()->e($result[1]); 272 app()->e($result[1]);
@@ -562,54 +280,55 @@ class Home extends Base { @@ -562,54 +280,55 @@ class Home extends Base {
562 * @author:dc 280 * @author:dc
563 * @time 2023/3/10 10:38 281 * @time 2023/3/10 10:38
564 */ 282 */
565 - public function sync(){ 283 + public function sync()
  284 + {
566 285
567 $emails = web_request_emails(); 286 $emails = web_request_emails();
568 $sync_type = app()->request('sync_type'); 287 $sync_type = app()->request('sync_type');
569 - if(empty($emails)){ 288 + if (empty($emails)) {
570 app()->e('sync_request_param_error'); 289 app()->e('sync_request_param_error');
571 - }else{ 290 + } else {
572 // 查询id 291 // 查询id
573 - if(count($emails)===1){ 292 + if (count($emails) === 1) {
574 $emails = $emails[0]; 293 $emails = $emails[0];
575 } 294 }
576 - $datas = db()->cache(3600)->all(emailSql::getValues(['email'=>$emails],'`id`,`email`,`pwd_error`'));  
577 - foreach ($datas as $k=>$v){  
578 - if(!$v['pwd_error']){  
579 - if(app()->requestHas('blacklist')){ 295 + $datas = db()->cache(3600)->all(emailSql::getValues(['email' => $emails], '`id`,`email`,`pwd_error`'));
  296 + foreach ($datas as $k => $v) {
  297 + if (!$v['pwd_error']) {
  298 + if (app()->requestHas('blacklist')) {
580 $blacklist = app()->request('blacklist'); 299 $blacklist = app()->request('blacklist');
581 - if(is_array($blacklist)){ 300 + if (is_array($blacklist)) {
582 $blacklist = [ 301 $blacklist = [
583 - 'emails' => $blacklist['emails']??[],  
584 - 'domain' => $blacklist['domain']??[], 302 + 'emails' => $blacklist['emails'] ?? [],
  303 + 'domain' => $blacklist['domain'] ?? [],
585 ]; 304 ];
586 // 黑名单,7天过期时间 305 // 黑名单,7天过期时间
587 - redis()->set('blacklist:'.$v['id'],$blacklist,86400*7); 306 + redis()->set('blacklist:' . $v['id'], $blacklist, 86400 * 7);
588 } 307 }
589 // 删除 308 // 删除
590 - if(!$blacklist||(empty($blacklist['emails'])&&empty($blacklist['domain']))){  
591 - redis()->delete('blacklist:'.$v['id']); 309 + if (!$blacklist || (empty($blacklist['emails']) && empty($blacklist['domain']))) {
  310 + redis()->delete('blacklist:' . $v['id']);
592 } 311 }
593 312
594 } 313 }
595 $source = app()->request('source'); 314 $source = app()->request('source');
596 315
597 // 是否立即同步 316 // 是否立即同步
598 - if($sync_type == 'immediately'){  
599 - try{  
600 - if(redis()->add('sync_immediately:'.$v['id'],1,10)){ 317 + if ($sync_type == 'immediately') {
  318 + try {
  319 + if (redis()->add('sync_immediately:' . $v['id'], 1, 10)) {
601 (new SyncMail($v['id']))->isUidAfter()->sync(); 320 (new SyncMail($v['id']))->isUidAfter()->sync();
602 } 321 }
603 - }catch (\Throwable $e){ 322 + } catch (\Throwable $e) {
604 logs($e->getTraceAsString()); 323 logs($e->getTraceAsString());
605 } 324 }
606 325
607 - }else{  
608 - redis()->rPush('sync_email_lists'.($source==1?'_my':''), $v['id']); 326 + } else {
  327 + redis()->rPush('sync_email_lists' . ($source == 1 ? '_my' : ''), $v['id']);
609 } 328 }
610 329
611 } 330 }
612 - $datas[$k]['have_new'] = redis()->getDel('have_new_mail_'.$v['id']); 331 + $datas[$k]['have_new'] = redis()->getDel('have_new_mail_' . $v['id']);
613 332
614 // 计算 333 // 计算
615 // $folders = db()->all(folderSql::all($v['id'],'`id`')); 334 // $folders = db()->all(folderSql::all($v['id'],'`id`'));
@@ -638,7 +357,8 @@ class Home extends Base { @@ -638,7 +357,8 @@ class Home extends Base {
638 * @author:dc 357 * @author:dc
639 * @time 2023/3/17 16:15 358 * @time 2023/3/17 16:15
640 */ 359 */
641 - public function seen_2_unseen(){ 360 + public function seen_2_unseen()
  361 + {
642 $this->setFlags('seen'); 362 $this->setFlags('seen');
643 } 363 }
644 364
@@ -648,7 +368,8 @@ class Home extends Base { @@ -648,7 +368,8 @@ class Home extends Base {
648 * @author:dc 368 * @author:dc
649 * @time 2023/4/10 16:30 369 * @time 2023/4/10 16:30
650 */ 370 */
651 - public function answered_2_unanswered(){ 371 + public function answered_2_unanswered()
  372 + {
652 $this->setFlags('answered'); 373 $this->setFlags('answered');
653 } 374 }
654 375
@@ -658,33 +379,32 @@ class Home extends Base { @@ -658,33 +379,32 @@ class Home extends Base {
658 * @author:dc 379 * @author:dc
659 * @time 2024/6/21 16:35 380 * @time 2024/6/21 16:35
660 */ 381 */
661 - public function star_2_unstar(){  
662 - logs("操作星标邮件 ".print_r(app()->request(),1)); 382 + public function star_2_unstar()
  383 + {
  384 + logs("操作星标邮件 " . print_r(app()->request(), 1));
663 $this->setFlags('flagged'); 385 $this->setFlags('flagged');
664 } 386 }
665 387
666 388
667 -  
668 -  
669 -  
670 /** 389 /**
671 * 邮件移动 390 * 邮件移动
672 * @author:dc 391 * @author:dc
673 * @time 2023/3/21 11:41 392 * @time 2023/3/21 11:41
674 */ 393 */
675 - public function move(){  
676 - $this->moveCopy(function (Mail $mailInstance,$uid,$origin_folder,$to_origin_folder){ 394 + public function move()
  395 + {
  396 + $this->moveCopy(function (Mail $mailInstance, $uid, $origin_folder, $to_origin_folder) {
677 // try { 397 // try {
678 // return $mailInstance->move($uid,$origin_folder,$to_origin_folder); 398 // return $mailInstance->move($uid,$origin_folder,$to_origin_folder);
679 // }catch (\Throwable $e){ 399 // }catch (\Throwable $e){
680 // if(app()->request('move_err_copy',1)){ 400 // if(app()->request('move_err_copy',1)){
681 // 复制成功 401 // 复制成功
682 try { 402 try {
683 - if($mailInstance->copy($uid,$origin_folder,$to_origin_folder)){  
684 - return $mailInstance->deleted($uid,$origin_folder); 403 + if ($mailInstance->copy($uid, $origin_folder, $to_origin_folder)) {
  404 + return $mailInstance->deleted($uid, $origin_folder);
685 } 405 }
686 - }catch (\Throwable $e){  
687 - logs('移动失败:'.$e->getMessage()); 406 + } catch (\Throwable $e) {
  407 + logs('移动失败:' . $e->getMessage());
688 return false; 408 return false;
689 } 409 }
690 410
@@ -696,89 +416,88 @@ class Home extends Base { @@ -696,89 +416,88 @@ class Home extends Base {
696 } 416 }
697 417
698 418
699 - private function moveCopy(\Closure $call){ 419 + private function moveCopy(\Closure $call)
  420 + {
700 $emails = $this->getEmails(); 421 $emails = $this->getEmails();
701 422
702 $mail_ids = app()->requestArr('mail_ids'); 423 $mail_ids = app()->requestArr('mail_ids');
703 - if(!($mail_ids && is_array($mail_ids))){ 424 + if (!($mail_ids && is_array($mail_ids))) {
704 app()->e('param_request_error'); 425 app()->e('param_request_error');
705 } 426 }
706 - foreach ($mail_ids as $k=>$id){  
707 - if(!is_numeric($id)){ 427 + foreach ($mail_ids as $k => $id) {
  428 + if (!is_numeric($id)) {
708 unset($mail_ids[$k]); 429 unset($mail_ids[$k]);
709 } 430 }
710 } 431 }
711 // 移动到的文件夹 432 // 移动到的文件夹
712 $to_folder = folderAlias(app()->request('folder')); 433 $to_folder = folderAlias(app()->request('folder'));
713 - if(empty($to_folder)){ 434 + if (empty($to_folder)) {
714 app()->e('folder_move_error'); 435 app()->e('folder_move_error');
715 } 436 }
716 - if($to_folder == '草稿箱'){ 437 + if ($to_folder == '草稿箱') {
717 app()->e('folder_move_to_draft_error'); 438 app()->e('folder_move_to_draft_error');
718 } 439 }
719 - if($to_folder == '发件箱'){ 440 + if ($to_folder == '发件箱') {
720 app()->e('folder_move_to_send_error'); 441 app()->e('folder_move_to_send_error');
721 } 442 }
722 443
723 - $data = db()->all(listsSql::all(dbWhere(['id'=>$mail_ids,'email_id'=>array_column($emails,'id')]),'`id`,`uid`,`email_id`,`folder_id`'));  
724 - if($data){ 444 + $data = listsSql::all(db(), dbWhere(['id' => $mail_ids, 'email_id' => array_column($emails, 'id')]), '`id`,`uid`,`email_id`,`folder_id`');
  445 + if ($data) {
725 // 查询邮箱 446 // 查询邮箱
726 - $emails = array_column($emails,null,'id'); 447 + $emails = array_column($emails, null, 'id');
727 $uids = []; 448 $uids = [];
728 - foreach ($data as $datum){ 449 + foreach ($data as $datum) {
729 // 只有草稿箱才没有uid 450 // 只有草稿箱才没有uid
730 // if($datum['uid']<0){ 451 // if($datum['uid']<0){
731 452
732 // } 453 // }
733 454
734 // 删除 455 // 删除
735 - if ($to_folder == '回收站'){ 456 + if ($to_folder == '回收站') {
736 // 删除数据,真实删除 457 // 删除数据,真实删除
737 - db()->update(listsSql::$table,[  
738 - 'deleted' => 1  
739 - ],dbWhere([  
740 - 'id' => $datum['id']  
741 - ])); 458 + listsSql::update(db(), [
  459 + 'deleted' => 1
  460 + ], $datum['id']);
742 continue; 461 continue;
743 } 462 }
744 463
745 - if(empty($uids[$datum['email_id']][$datum['folder_id']])){ 464 + if (empty($uids[$datum['email_id']][$datum['folder_id']])) {
746 $uids[$datum['email_id']][$datum['folder_id']] = []; 465 $uids[$datum['email_id']][$datum['folder_id']] = [];
747 } 466 }
748 $uids[$datum['email_id']][$datum['folder_id']][] = [ 467 $uids[$datum['email_id']][$datum['folder_id']][] = [
749 - 'uid' => $datum['uid'],  
750 - 'id' => $datum['id'], 468 + 'uid' => $datum['uid'],
  469 + 'id' => $datum['id'],
751 ]; 470 ];
752 } 471 }
753 472
754 - foreach ($uids as $eid=>$arr){ 473 + foreach ($uids as $eid => $arr) {
755 // 查询需要移动的文件夹 474 // 查询需要移动的文件夹
756 - $to_origin_folder = db()->first(folderSql::first(['email_id'=>$eid,'folder'=>$to_folder]));  
757 - if($to_origin_folder){  
758 - foreach ($arr as $fid=>$uid){ 475 + $to_origin_folder = db()->first(folderSql::first(['email_id' => $eid, 'folder' => $to_folder]));
  476 + if ($to_origin_folder) {
  477 + foreach ($arr as $fid => $uid) {
759 // 查询目录 478 // 查询目录
760 $folder = db()->first(folderSql::first($fid)); 479 $folder = db()->first(folderSql::first($fid));
761 - if($folder){ 480 + if ($folder) {
762 // 开始远程 481 // 开始远程
763 - $mailInstance = new Mail($emails[$eid]['email'],base64_decode($emails[$eid]['password']),$emails[$eid]['imap']); 482 + $mailInstance = new Mail($emails[$eid]['email'], base64_decode($emails[$eid]['password']), $emails[$eid]['imap']);
764 483
765 - if($mailInstance->login()==1){  
766 - $localUids = array_column($uid,'uid'); 484 + if ($mailInstance->login() == 1) {
  485 + $localUids = array_column($uid, 'uid');
767 // 检查 远程是否有邮件 486 // 检查 远程是否有邮件
768 $mailInstance->client->selectFolder($folder['origin_folder']); 487 $mailInstance->client->selectFolder($folder['origin_folder']);
769 - $originUids = $mailInstance->client->fetch($localUids,'UID',true); 488 + $originUids = $mailInstance->client->fetch($localUids, 'UID', true);
770 489
771 - if($originUids){ 490 + if ($originUids) {
772 // 进行移动 远程有的邮件 491 // 进行移动 远程有的邮件
773 - $ret = $call($mailInstance,array_column($originUids,'UID'),$folder['origin_folder'],$to_origin_folder['origin_folder']);  
774 - }else{ 492 + $ret = $call($mailInstance, array_column($originUids, 'UID'), $folder['origin_folder'], $to_origin_folder['origin_folder']);
  493 + } else {
775 $ret = true; 494 $ret = true;
776 } 495 }
777 496
778 // TODO:: 这个过程无法保证原子性。没办法 497 // TODO:: 这个过程无法保证原子性。没办法
779 // 先复制 498 // 先复制
780 - if($ret){  
781 - $uret = db()->update(listsSql::$table,['deleted'=>1],dbWhere(['id'=>array_column($uid,'id')])); 499 + if ($ret) {
  500 + listsSql::update(db(), ['deleted' => 1], dbWhere(['id' => array_column($uid, 'id')]));
782 } 501 }
783 502
784 503
@@ -797,7 +516,7 @@ class Home extends Base { @@ -797,7 +516,7 @@ class Home extends Base {
797 516
798 517
799 app()->_json([ 518 app()->_json([
800 - 'mail_id' => $mail_ids 519 + 'mail_id' => $mail_ids
801 ]); 520 ]);
802 } 521 }
803 522
@@ -808,10 +527,11 @@ class Home extends Base { @@ -808,10 +527,11 @@ class Home extends Base {
808 * @author:dc 527 * @author:dc
809 * @time 2024/3/9 13:50 528 * @time 2024/3/9 13:50
810 */ 529 */
811 - public function copy(){  
812 - $this->moveCopy(function (Mail $mailInstance,$uid,$origin_folder,$to_origin_folder){ 530 + public function copy()
  531 + {
  532 + $this->moveCopy(function (Mail $mailInstance, $uid, $origin_folder, $to_origin_folder) {
813 533
814 - return $mailInstance->copy($uid,$origin_folder,$to_origin_folder); 534 + return $mailInstance->copy($uid, $origin_folder, $to_origin_folder);
815 535
816 }); 536 });
817 } 537 }
@@ -823,11 +543,12 @@ class Home extends Base { @@ -823,11 +543,12 @@ class Home extends Base {
823 * @author:dc 543 * @author:dc
824 * @time 2024/3/14 14:18 544 * @time 2024/3/14 14:18
825 */ 545 */
826 - public function expunge(){ 546 + public function expunge()
  547 + {
827 $email = $this->getEmail(); 548 $email = $this->getEmail();
828 - $mailInstance = new Mail($email['email'],base64_decode($email['password']),$email['imap']); 549 + $mailInstance = new Mail($email['email'], base64_decode($email['password']), $email['imap']);
829 550
830 - if($mailInstance->login()==1 && $mailInstance->expunge()){ 551 + if ($mailInstance->login() == 1 && $mailInstance->expunge()) {
831 app()->_json([]); 552 app()->_json([]);
832 } 553 }
833 554
@@ -835,8 +556,6 @@ class Home extends Base { @@ -835,8 +556,6 @@ class Home extends Base {
835 } 556 }
836 557
837 558
838 -  
839 -  
840 /** 559 /**
841 * 远程标签 560 * 远程标签
842 * @param $d 561 * @param $d
@@ -844,118 +563,113 @@ class Home extends Base { @@ -844,118 +563,113 @@ class Home extends Base {
844 * @author:dc 563 * @author:dc
845 * @time 2023/3/21 14:28 564 * @time 2023/3/21 14:28
846 */ 565 */
847 - private function setFlags($d){ 566 + private function setFlags($d)
  567 + {
848 $emails = $this->getEmails(); 568 $emails = $this->getEmails();
849 569
850 $mail_ids = app()->request('mail_ids'); 570 $mail_ids = app()->request('mail_ids');
851 571
852 // 全部标记 572 // 全部标记
853 - if(!$mail_ids){ 573 + if (!$mail_ids) {
854 app()->e('标记失败'); 574 app()->e('标记失败');
855 - $folder = app()->request('folder','收件箱','folderAlias'); 575 + $folder = app()->request('folder', '收件箱', 'folderAlias');
856 // 查询 当前的 文件夹 如果有选中文件夹 就 查询出 选中文件夹的id 576 // 查询 当前的 文件夹 如果有选中文件夹 就 查询出 选中文件夹的id
857 - $fids = db()->all(folderSql::all(array_column($emails,'id'),'`id`,`folder`'));  
858 - foreach ($fids as $fk=>$fid){  
859 - if($fid['folder'] != $folder){ 577 + $fids = db()->all(folderSql::all(array_column($emails, 'id'), '`id`,`folder`'));
  578 + foreach ($fids as $fk => $fid) {
  579 + if ($fid['folder'] != $folder) {
860 unset($fids[$fk]); 580 unset($fids[$fk]);
861 } 581 }
862 } 582 }
863 - if($fids){ 583 + if ($fids) {
864 // 查询要标记的 邮件id 584 // 查询要标记的 邮件id
865 - $sql = listsSql::all(dbWhere(['folder_id'=>array_column($fids,'id'),'seen'=>0]),'`id`');  
866 - $mail_ids = db()->all($sql);  
867 -// $mail_ids2 = db()->all(str_replace('from `lists` where','from `lists_hot` where',$sql));  
868 -// $mail_ids = array_merge($mail_ids,$mail_ids2);  
869 - $mail_ids = array_column($mail_ids,'id'); 585 + $mail_ids = listsSql::all(db(), dbWhere(['folder_id' => array_column($fids, 'id'), 'seen' => 0]), '`id`');
  586 + $mail_ids = array_column($mail_ids, 'id');
870 } 587 }
871 588
872 } 589 }
873 590
874 - if($mail_ids){  
875 - $mail_ids = is_array($mail_ids) ? $mail_ids : explode(',',$mail_ids); 591 + if ($mail_ids) {
  592 + $mail_ids = is_array($mail_ids) ? $mail_ids : explode(',', $mail_ids);
876 } 593 }
877 594
878 - if(!($mail_ids && is_array($mail_ids))){ 595 + if (!($mail_ids && is_array($mail_ids))) {
879 app()->e('param_request_error'); 596 app()->e('param_request_error');
880 } 597 }
881 - foreach ($mail_ids as $k=>$id){  
882 - if(!is_numeric($id)){ 598 + foreach ($mail_ids as $k => $id) {
  599 + if (!is_numeric($id)) {
883 unset($mail_ids[$k]); 600 unset($mail_ids[$k]);
884 } 601 }
885 } 602 }
886 // 已读或未读 603 // 已读或未读
887 - $fv = (int) app()->request($d); 604 + $fv = (int)app()->request($d);
888 $fv = $fv ? 1 : 0; 605 $fv = $fv ? 1 : 0;
889 606
890 // if(app()->request('source')==2){ 607 // if(app()->request('source')==2){
891 - $ids = es('email_lists_branch_'.app()->request('postid','','intval'))  
892 - ->search([  
893 - "_source" => ["uuid"],  
894 - 'query'=>[  
895 - 'bool'=>[  
896 - 'must'=>[  
897 - ['terms'=>['uuid'=>$mail_ids]]  
898 - ] 608 + $ids = es('email_lists_branch_' . app()->request('postid', '', 'intval'))
  609 + ->search([
  610 + "_source" => ["uuid"],
  611 + 'query' => [
  612 + 'bool' => [
  613 + 'must' => [
  614 + ['terms' => ['uuid' => $mail_ids]]
899 ] 615 ]
900 ] 616 ]
901 - ],0,1000);  
902 - $mail_ids = [];  
903 - foreach ($ids['hits']['hits']??[] as $item){  
904 - $mail_ids[] = $item['_source']['uuid'];  
905 - } 617 + ]
  618 + ], 0, 1000);
  619 + $mail_ids = [];
  620 + foreach ($ids['hits']['hits'] ?? [] as $item) {
  621 + $mail_ids[] = $item['_source']['uuid'];
  622 + }
906 623
907 - $sql = listsSql::all(dbWhere(['id'=>$mail_ids]),'`id`,`uid`,`email_id`,`folder_id`');  
908 -// }  
909 -// else{  
910 -// $sql = listsSql::all(dbWhere(['id'=>$mail_ids,'email_id'=>array_column($emails,'id')]),'`id`,`uid`,`email_id`,`folder_id`'); 624 + $data = listsSql::all(db(), dbWhere(['id' => $mail_ids]), '`id`,`uid`,`email_id`,`folder_id`');
911 // } 625 // }
912 626
913 - $data = db()->all($sql);  
914 -// $data2 = db()->all(str_replace('from `lists` where','from `lists_hot` where',$sql));  
915 -// $data = array_merge($data,$data2);  
916 - if($data){ 627 + if ($data) {
917 // 查询邮箱 628 // 查询邮箱
918 - $emails = array_column(db()->all(emailSql::all(dbWhere(['id'=>array_column($data,'email_id')]))),null,'id'); 629 + $emails = array_column(db()->all(emailSql::all(dbWhere(['id' => array_column($data, 'email_id')]))), null, 'id');
919 630
920 631
921 $uids = []; 632 $uids = [];
922 - foreach ($data as $datum){  
923 - if(empty($uids[$datum['email_id']])){ 633 + foreach ($data as $datum) {
  634 + if (empty($uids[$datum['email_id']])) {
924 $uids[$datum['email_id']][$datum['folder_id']] = []; 635 $uids[$datum['email_id']][$datum['folder_id']] = [];
925 } 636 }
926 $uids[$datum['email_id']][$datum['folder_id']][] = [ 637 $uids[$datum['email_id']][$datum['folder_id']][] = [
927 - 'uid' => $datum['uid'],  
928 - 'id' => $datum['id'], 638 + 'uid' => $datum['uid'],
  639 + 'id' => $datum['id'],
929 ]; 640 ];
930 } 641 }
931 642
932 - foreach ($uids as $eid=>$arr){  
933 - foreach ($arr as $fid=>$uid){ 643 + foreach ($uids as $eid => $arr) {
  644 + foreach ($arr as $fid => $uid) {
934 // 查询目录 645 // 查询目录
935 $folder = db()->first(folderSql::first($fid)); 646 $folder = db()->first(folderSql::first($fid));
936 - if($folder){ 647 + if ($folder) {
937 // 开始远程 648 // 开始远程
938 - if(empty($emails[$eid])){ 649 + if (empty($emails[$eid])) {
939 $emails[$eid] = db()->first(emailSql::first($eid)); 650 $emails[$eid] = db()->first(emailSql::first($eid));
940 } 651 }
941 652
942 - $mailInstance = new Mail($emails[$eid]['email'],base64_decode($emails[$eid]['password']),$emails[$eid]['imap']); 653 + $mailInstance = new Mail($emails[$eid]['email'], base64_decode($emails[$eid]['password']), $emails[$eid]['imap']);
943 654
944 - if($mailInstance->login()==1){  
945 - switch ($d){ 655 + if ($mailInstance->login() == 1) {
  656 + switch ($d) {
946 // 已读 未读 657 // 已读 未读
947 - case 'seen':{  
948 - $mailInstance->seen(array_column($uid,'uid'),$folder['origin_folder'],$fv); 658 + case 'seen':
  659 + {
  660 + $mailInstance->seen(array_column($uid, 'uid'), $folder['origin_folder'], $fv);
949 break; 661 break;
950 } 662 }
951 // 未回复/已回复 663 // 未回复/已回复
952 - case 'answered':{  
953 - $mailInstance->answered(array_column($uid,'uid'),$folder['origin_folder'],$fv); 664 + case 'answered':
  665 + {
  666 + $mailInstance->answered(array_column($uid, 'uid'), $folder['origin_folder'], $fv);
954 break; 667 break;
955 } 668 }
956 // 星标 669 // 星标
957 - case 'flagged':{  
958 - $mailInstance->flagged(array_column($uid,'uid'),$folder['origin_folder'],$fv); 670 + case 'flagged':
  671 + {
  672 + $mailInstance->flagged(array_column($uid, 'uid'), $folder['origin_folder'], $fv);
959 break; 673 break;
960 } 674 }
961 // 回收站,已删 未删,软删 675 // 回收站,已删 未删,软删
@@ -968,10 +682,8 @@ class Home extends Base { @@ -968,10 +682,8 @@ class Home extends Base {
968 $mailInstance = null; 682 $mailInstance = null;
969 } 683 }
970 // 更新数据 684 // 更新数据
971 - db()->update(listsSql::$table,[  
972 - $d => $fv  
973 - ],dbWhere([  
974 - 'id' => array_column($uid,'id') 685 + listsSql::update(db(), [$d => $fv], dbWhere([
  686 + 'id' => array_column($uid, 'id')
975 ])); 687 ]));
976 688
977 } 689 }
@@ -983,7 +695,7 @@ class Home extends Base { @@ -983,7 +695,7 @@ class Home extends Base {
983 695
984 696
985 app()->_json([ 697 app()->_json([
986 - 'mail_id' => $mail_ids 698 + 'mail_id' => $mail_ids
987 ]); 699 ]);
988 700
989 } 701 }
@@ -993,82 +705,78 @@ class Home extends Base { @@ -993,82 +705,78 @@ class Home extends Base {
993 * @author:dc 705 * @author:dc
994 * @time 2023/4/1 9:24 706 * @time 2023/4/1 9:24
995 */ 707 */
996 - public function info(){  
997 - $reload = app()->request('reload',0,'intval'); 708 + public function info()
  709 + {
  710 + $reload = app()->request('reload', 0, 'intval');
998 $sync_num = 0; 711 $sync_num = 0;
999 HOME_INFO_BODY: 712 HOME_INFO_BODY:
1000 - $id = app()->request('id',0,'intval'); 713 + $id = app()->request('id', 0, 'intval');
1001 714
1002 - $udate = app()->request('udate',0,'intval'); 715 + $udate = app()->request('udate', 0, 'intval');
1003 $subject = app()->request('subject'); 716 $subject = app()->request('subject');
1004 - if($udate&&$subject){  
1005 - $data = db()->first(listsSql::first(dbWhere(['id'=>$id,'udate'=>$udate])));  
1006 -// if($data && trim($data['subject']) != trim($subject)){  
1007 -// $data = [];  
1008 -// }  
1009 - if($data){ 717 + if ($udate && $subject) {
  718 + $data = listsSql::first(db(), dbWhere(['id' => $id, 'udate' => $udate]));
  719 + if ($data) {
1010 $email = db()->first(emailSql::first($data['email_id'])); 720 $email = db()->first(emailSql::first($data['email_id']));
1011 } 721 }
1012 - }else{ 722 + } else {
1013 // 没有,说明没有同步过来 723 // 没有,说明没有同步过来
1014 - $email = $this->getEmail('*',false);  
1015 - $data = db()->first(listsSql::first(dbWhere(['id'=>$id])));  
1016 - if(!$data){  
1017 - $data = db()->first(listsSql::firstHot(dbWhere(['id'=>$id])));  
1018 - }  
1019 - if($data){ 724 + $email = $this->getEmail('*', false);
  725 + $data = listsSql::first(db(), dbWhere(['id' => $id]));
  726 +
  727 + if ($data) {
1020 $email = db()->first(emailSql::first($data['email_id'])); 728 $email = db()->first(emailSql::first($data['email_id']));
1021 } 729 }
1022 730
1023 } 731 }
1024 732
1025 - if($data){  
1026 - $data['uuid'] = get_email_uuid($data['subject'],$data['udate'],$data['from'],$data['to'],$data['size']); 733 + if ($data) {
  734 + $data['uuid'] = get_email_uuid($data['subject'], $data['udate'], $data['from'], $data['to'], $data['size']);
1027 735
1028 - $data['description'] = @html_entity_decode($data['description']??'', ENT_COMPAT, 'UTF-8'); 736 + $data['description'] = @html_entity_decode($data['description'] ?? '', ENT_COMPAT, 'UTF-8');
1029 737
1030 - $data['to_name'] = $data['to_name'] ? json_decode($data['to_name'],true) : [];  
1031 - if(!$data['to_name']){  
1032 - $data['to_name'] = [["email"=>$email['email'],'name'=>'']]; 738 + $data['to_name'] = $data['to_name'] ? json_decode($data['to_name'], true) : [];
  739 + if (!$data['to_name']) {
  740 + $data['to_name'] = [["email" => $email['email'], 'name' => '']];
1033 } 741 }
1034 - $data['cc'] = $data['cc'] ? json_decode($data['cc'],true) : [];  
1035 - $data['bcc'] = $data['bcc'] ? json_decode($data['bcc'],true) : []; 742 + $data['cc'] = $data['cc'] ? json_decode($data['cc'], true) : [];
  743 + $data['bcc'] = $data['bcc'] ? json_decode($data['bcc'], true) : [];
1036 744
1037 - $data['to_name'] = array_map(function ($t){  
1038 - if(!empty($t['name'])){ 745 + $data['to_name'] = array_map(function ($t) {
  746 + if (!empty($t['name'])) {
1039 $t['name'] = MailFun::mb_coding($t['name']); 747 $t['name'] = MailFun::mb_coding($t['name']);
1040 } 748 }
1041 return $t; 749 return $t;
1042 - },$data['to_name']); 750 + }, $data['to_name']);
1043 751
1044 - $postid = app()->request('postid','','intval');  
1045 - $esData = ($postid ? es('email_lists_branch_'.$postid) : es())->get(['id'=>$data['email_id'].'_'.$data['folder_id'].'_'.$data['uid']]);  
1046 - $data['postid'] = $esData['_source']['postid']??0; 752 + $postid = app()->request('postid', '', 'intval');
  753 + $esData = ($postid ? es('email_lists_branch_' . $postid) : es())->get(['id' => $data['email_id'] . '_' . $data['folder_id'] . '_' . $data['uid']]);
  754 + $data['postid'] = $esData['_source']['postid'] ?? 0;
1047 755
1048 // 是否再次 重新获取 756 // 是否再次 重新获取
1049 - $data['allowreply'] = db()->value(folderSql::first(['id'=>$data['folder_id']],'folder'))!='发件箱'?1:0; 757 + $data['allowreply'] = db()->value(folderSql::first(['id' => $data['folder_id']], 'folder')) != '发件箱' ? 1 : 0;
1050 758
1051 - $body = getMailBody($id);  
1052 - if($body && !$reload){  
1053 - $data['body'] = json_decode($body['text_html'],true); 759 + $body = getMailBody($id);
  760 + if ($body && !$reload) {
  761 + $data['body'] = json_decode($body['text_html'], true);
1054 $htmlbody = ''; 762 $htmlbody = '';
1055 - foreach ($data['body'] as $bd){ 763 + foreach ($data['body'] as $bd) {
1056 // if(!empty($bd['charset'])){ 764 // if(!empty($bd['charset'])){
1057 // $charset = $bd['charset']; 765 // $charset = $bd['charset'];
1058 // } 766 // }
1059 - if(($bd['type']??'') == 'text/html'){ 767 + if (($bd['type'] ?? '') == 'text/html') {
1060 $htmlbody = base64_decode($bd['body']); 768 $htmlbody = base64_decode($bd['body']);
1061 } 769 }
1062 } 770 }
1063 - foreach ($data['body'] as $bdk=>$bd){ 771 + foreach ($data['body'] as $bdk => $bd) {
1064 772
1065 - if(count($bd)==1){  
1066 - if(isset($bd['body'])){ 773 + if (count($bd) == 1) {
  774 + if (isset($bd['body'])) {
1067 $data['body'][$bdk]['type'] = 'text/html'; 775 $data['body'][$bdk]['type'] = 'text/html';
1068 } 776 }
1069 } 777 }
1070 778
1071 - if(!empty($bd['path'])){ 779 + if (!empty($bd['path'])) {
1072 780
1073 $data['body'][$bdk]['name'] = MailFun::isBase64($bd['name']) ? @base64_decode($bd['name']) : $bd['name']; 781 $data['body'][$bdk]['name'] = MailFun::isBase64($bd['name']) ? @base64_decode($bd['name']) : $bd['name'];
1074 $data['body'][$bdk]['filename'] = MailFun::isBase64($bd['filename']) ? @base64_decode($bd['filename']) : $bd['filename']; 782 $data['body'][$bdk]['filename'] = MailFun::isBase64($bd['filename']) ? @base64_decode($bd['filename']) : $bd['filename'];
@@ -1080,15 +788,15 @@ class Home extends Base { @@ -1080,15 +788,15 @@ class Home extends Base {
1080 788
1081 $data['body'][$bdk]['size'] = 0; 789 $data['body'][$bdk]['size'] = 0;
1082 $data['body'][$bdk]['url'] = ''; 790 $data['body'][$bdk]['url'] = '';
1083 - if(is_file($bd['path'])){ 791 + if (is_file($bd['path'])) {
1084 // 文件大小 792 // 文件大小
1085 $data['body'][$bdk]['size'] = filesize($bd['path']); 793 $data['body'][$bdk]['size'] = filesize($bd['path']);
1086 // 文件访问地址 794 // 文件访问地址
1087 - $data['body'][$bdk]['url'] = APP_HOST.str_replace(PUBLIC_PATH,'',$bd['path']); 795 + $data['body'][$bdk]['url'] = APP_HOST . str_replace(PUBLIC_PATH, '', $bd['path']);
1088 } 796 }
1089 797
1090 // 验证编码是否有其他编码字符,这里编辑了未知编码 798 // 验证编码是否有其他编码字符,这里编辑了未知编码
1091 - if(!@json_encode($data['body'][$bdk])){ 799 + if (!@json_encode($data['body'][$bdk])) {
1092 // 抛弃原有的名字,显示已存储到服务器的名字 800 // 抛弃原有的名字,显示已存储到服务器的名字
1093 $data['body'][$bdk]['name'] = $data['body'][$bdk]['signName']; 801 $data['body'][$bdk]['name'] = $data['body'][$bdk]['signName'];
1094 $data['body'][$bdk]['filename'] = $data['body'][$bdk]['signName']; 802 $data['body'][$bdk]['filename'] = $data['body'][$bdk]['signName'];
@@ -1097,35 +805,34 @@ class Home extends Base { @@ -1097,35 +805,34 @@ class Home extends Base {
1097 unset($data['body'][$bdk]['path']); 805 unset($data['body'][$bdk]['path']);
1098 806
1099 // 内容区是有有cid 807 // 内容区是有有cid
1100 - if ($htmlbody && !empty($bd['content-id'])){  
1101 - if(!strpos($htmlbody,"\"cid:{$bd['content-id']}\"")){ 808 + if ($htmlbody && !empty($bd['content-id'])) {
  809 + if (!strpos($htmlbody, "\"cid:{$bd['content-id']}\"")) {
1102 unset($data['body'][$bdk]['content-id']); 810 unset($data['body'][$bdk]['content-id']);
1103 } 811 }
1104 - }  
1105 - // 没有html内容,content-id是不可能有的  
1106 - else if(!$htmlbody){ 812 + } // 没有html内容,content-id是不可能有的
  813 + else if (!$htmlbody) {
1107 unset($data['body'][$bdk]['content-id']); 814 unset($data['body'][$bdk]['content-id']);
1108 } 815 }
1109 } 816 }
1110 } 817 }
1111 return [ 818 return [
1112 - 'data' => $data 819 + 'data' => $data
1113 ]; 820 ];
1114 }// 草稿 821 }// 草稿
1115 - else if(!$data['uid'] && $data['draft']){ 822 + else if (!$data['uid'] && $data['draft']) {
1116 $data['body'] = []; 823 $data['body'] = [];
1117 return [ 824 return [
1118 - 'data' => $data 825 + 'data' => $data
1119 ]; 826 ];
1120 } 827 }
1121 828
1122 // 循环几次 829 // 循环几次
1123 - if($data['uid'] >= 0 && $sync_num < 1){  
1124 - $folder = db()->value(folderSql::first(['id'=>$data['folder_id']],'origin_folder'));  
1125 - try{  
1126 - (new SyncMail(db()->first(emailSql::first($data['email_id']))))->mail($folder,[$data['uid']],true);  
1127 - }catch (\Throwable $e){  
1128 - logs('read body:'.$e->getMessage().$e->getTraceAsString()); 830 + if ($data['uid'] >= 0 && $sync_num < 1) {
  831 + $folder = db()->value(folderSql::first(['id' => $data['folder_id']], 'origin_folder'));
  832 + try {
  833 + (new SyncMail(db()->first(emailSql::first($data['email_id']))))->mail($folder, [$data['uid']], true);
  834 + } catch (\Throwable $e) {
  835 + logs('read body:' . $e->getMessage() . $e->getTraceAsString());
1129 app()->e('邮箱登录验证异常'); 836 app()->e('邮箱登录验证异常');
1130 } 837 }
1131 838
@@ -1133,10 +840,10 @@ class Home extends Base { @@ -1133,10 +840,10 @@ class Home extends Base {
1133 $reload = 0; 840 $reload = 0;
1134 goto HOME_INFO_BODY; 841 goto HOME_INFO_BODY;
1135 } 842 }
1136 - logs('超过读取body次数 '.$data['id']); 843 + logs('超过读取body次数 ' . $data['id']);
1137 844
1138 - }else{  
1139 - logs('读取body 没有查询到数据 '.$id.'-'.($email['email']??'')); 845 + } else {
  846 + logs('读取body 没有查询到数据 ' . $id . '-' . ($email['email'] ?? ''));
1140 } 847 }
1141 848
1142 app()->e('mail_body_error'); 849 app()->e('mail_body_error');
@@ -1149,8 +856,9 @@ class Home extends Base { @@ -1149,8 +856,9 @@ class Home extends Base {
1149 * @author:dc 856 * @author:dc
1150 * @time 2024/8/7 14:12 857 * @time 2024/8/7 14:12
1151 */ 858 */
1152 - public function desubscribe(){  
1153 - $key = app()->request('key',''); 859 + public function desubscribe()
  860 + {
  861 + $key = app()->request('key', '');
1154 app()->_json(MailFun::deSubscribeUrl($key)); 862 app()->_json(MailFun::deSubscribeUrl($key));
1155 } 863 }
1156 864
@@ -1161,21 +869,23 @@ class Home extends Base { @@ -1161,21 +869,23 @@ class Home extends Base {
1161 * @author:dc 869 * @author:dc
1162 * @time 2025/7/17 9:50 870 * @time 2025/7/17 9:50
1163 */ 871 */
1164 - public function bodyinfo(){ 872 + public function bodyinfo()
  873 + {
1165 $id = app()->request('list_id'); 874 $id = app()->request('list_id');
1166 875
1167 $body = getMailBody($id); 876 $body = getMailBody($id);
1168 - if(!$body){  
1169 - $data = db()->first(listsSql::first(dbWhere(['id'=>$id]),'folder_id,email_id,uid'));  
1170 - $folder = db()->value(folderSql::first(['id'=>$data['folder_id']],'origin_folder'));  
1171 - try{  
1172 - (new SyncMail($data['email_id']))->mail($folder,[$data['uid']],true);  
1173 - }catch (\Throwable $e){} 877 + if (!$body) {
  878 + $data = listsSql::first(db(), dbWhere(['id' => $id]), 'folder_id,email_id,uid');
  879 + $folder = db()->value(folderSql::first(['id' => $data['folder_id']], 'origin_folder'));
  880 + try {
  881 + (new SyncMail($data['email_id']))->mail($folder, [$data['uid']], true);
  882 + } catch (\Throwable $e) {
  883 + }
1174 } 884 }
1175 885
1176 $body = getMailBody($id); 886 $body = getMailBody($id);
1177 887
1178 - app()->_json(@json_decode($body['text_html']??"[]",true)); 888 + app()->_json(@json_decode($body['text_html'] ?? "[]", true));
1179 889
1180 } 890 }
1181 891
@@ -1185,22 +895,23 @@ class Home extends Base { @@ -1185,22 +895,23 @@ class Home extends Base {
1185 * @author:dc 895 * @author:dc
1186 * @time 2025/9/18 16:50 896 * @time 2025/9/18 16:50
1187 */ 897 */
1188 - public function resync_to_es(){  
1189 - $postid = (int) app()->request('postid');  
1190 - if(app()->request('postid')=='0a'){  
1191 - redis()->rPush('resync_to_es_inbox_list','0a'); 898 + public function resync_to_es()
  899 + {
  900 + $postid = (int)app()->request('postid');
  901 + if (app()->request('postid') == '0a') {
  902 + redis()->rPush('resync_to_es_inbox_list', '0a');
1192 return; 903 return;
1193 } 904 }
1194 905
1195 - if(redis()->has('resync_to_es_inbox:'.$postid)){ 906 + if (redis()->has('resync_to_es_inbox:' . $postid)) {
1196 app()->e('失败,请等待10分钟后在重试'); 907 app()->e('失败,请等待10分钟后在重试');
1197 } 908 }
1198 - $h = (int) date('H');  
1199 - if(!$postid && $h>=6&& $h<=18){ 909 + $h = (int)date('H');
  910 + if (!$postid && $h >= 6 && $h <= 18) {
1200 app()->e('刷所有项目只能在早6点前或晚18点后'); 911 app()->e('刷所有项目只能在早6点前或晚18点后');
1201 } 912 }
1202 913
1203 - redis()->rPush('resync_to_es_inbox_list',$postid); 914 + redis()->rPush('resync_to_es_inbox_list', $postid);
1204 915
1205 app()->e('请求成功,请等待5-15分钟'); 916 app()->e('请求成功,请等待5-15分钟');
1206 917
@@ -1214,29 +925,21 @@ class Home extends Base { @@ -1214,29 +925,21 @@ class Home extends Base {
1214 * @author:dc 925 * @author:dc
1215 * @time 2025/11/27 14:16 926 * @time 2025/11/27 14:16
1216 */ 927 */
1217 - public function my_resync_to_es(){ 928 + public function my_resync_to_es()
  929 + {
1218 $id = 0; 930 $id = 0;
1219 $total = 0; 931 $total = 0;
1220 $email_id = intval(app()->request('email_id')); 932 $email_id = intval(app()->request('email_id'));
1221 - while (1){  
1222 -// echo $id."\n";  
1223 - $mailLists = db()->all("select `id` from `lists` where `email_id` = {$email_id} and `id` > {$id} order by `id` asc limit 1000");  
1224 - if(empty($mailLists)){  
1225 - break;  
1226 - }  
1227 - foreach ($mailLists as $mailList){  
1228 - $total++;  
1229 - $id = $mailList['id'];  
1230 - redis()->rPush('sync_to_es',$id.'.1');  
1231 - } 933 + $mailLists = listsSql::all(db(), dbWhere(['email_id' => $email_id]), 'id');
  934 + foreach ($mailLists as $mailList) {
  935 + $total++;
  936 + $id = $mailList['id'];
  937 + redis()->rPush('sync_to_es', $id . '.1');
1232 } 938 }
1233 -  
1234 return $total; 939 return $total;
1235 } 940 }
1236 941
1237 942
1238 -  
1239 -  
1240 } 943 }
1241 944
1242 945
@@ -284,13 +284,6 @@ class MailListV2Es extends Base { @@ -284,13 +284,6 @@ class MailListV2Es extends Base {
284 // 邮件箱 284 // 邮件箱
285 $v['folder_name'] = db()->cache(86400)->value(folderSql::first($v['folder_id'],'folder')); 285 $v['folder_name'] = db()->cache(86400)->value(folderSql::first($v['folder_id'],'folder'));
286 286
287 - // 暂时这样吧  
288 - $info = db()->first(\Model\listsSql::first('id = '.$v['id'],'`flagged`,`seen`,`deleted`'));  
289 - if($info){  
290 - $v['flagged'] = $info['flagged'];  
291 - $v['seen'] = $info['seen'];  
292 - $v['deleted'] = $info['deleted'];  
293 - }  
294 287
295 288
296 return $v; 289 return $v;
@@ -280,15 +280,6 @@ class MailListV2Es2 extends Base { @@ -280,15 +280,6 @@ class MailListV2Es2 extends Base {
280 // 邮件箱 280 // 邮件箱
281 $v['folder_name'] = db()->cache(86400)->value(folderSql::first($v['folder_id'],'folder')); 281 $v['folder_name'] = db()->cache(86400)->value(folderSql::first($v['folder_id'],'folder'));
282 282
283 - // 暂时这样吧  
284 - $info = db()->first(\Model\listsSql::first('id = '.$v['id'],'`flagged`,`seen`,`deleted`'));  
285 - if($info){  
286 - $v['flagged'] = $info['flagged'];  
287 - $v['seen'] = $info['seen'];  
288 - $v['deleted'] = $info['deleted'];  
289 - }  
290 -  
291 - // 手动触发同步es  
292 // 手动触发同步es 283 // 手动触发同步es
293 if(empty($v['is_auto']) && $v['folder_name']=='收件箱' && isAiAutoMail($v['from'],$v['subject'])) redis()->rPush('sync_to_es',$v['id'].'.1'); 284 if(empty($v['is_auto']) && $v['folder_name']=='收件箱' && isAiAutoMail($v['from'],$v['subject'])) redis()->rPush('sync_to_es',$v['id'].'.1');
294 285
@@ -45,7 +45,7 @@ class SyncMailToEs { @@ -45,7 +45,7 @@ class SyncMailToEs {
45 public $es; 45 public $es;
46 46
47 public function handler(){ 47 public function handler(){
48 - if(in_array($this->table,['lists','lists_hot'])){//,'lists_auto' 48 + if(in_array($this->table,['lists','lists_hot','lists_back'])){//,'lists_auto'
49 49
50 if($this->type=='create'){ 50 if($this->type=='create'){
51 $this->create(); 51 $this->create();
@@ -70,17 +70,12 @@ class SyncMailToEs { @@ -70,17 +70,12 @@ class SyncMailToEs {
70 } 70 }
71 else if($this->table == 'lists'){ 71 else if($this->table == 'lists'){
72 redis()->rPush('sync_to_es',$this->data['id']); 72 redis()->rPush('sync_to_es',$this->data['id']);
73 -// $id = $this->data['email_id'].'_'.$this->data['folder_id'].'_'.$this->data['uid'];  
74 -// if(empty($this->data['is_auto'])){  
75 -// $this->data['is_auto'] = 0;  
76 -// }  
77 -// $this->es->save($id,$this->getData($this->data)); 73 + }
  74 + else if($this->table == 'lists_back'){
  75 + redis()->rPush('sync_to_es',$this->data['id']);
78 } 76 }
79 else if($this->table == 'lists_auto'){ 77 else if($this->table == 'lists_auto'){
80 redis()->rPush('sync_to_es',$this->data['list_id']); 78 redis()->rPush('sync_to_es',$this->data['list_id']);
81 -// $data = db()->first(listsSql::first('`id` = '.$this->data['list_id']));  
82 -// $id = $data['email_id'].'_'.$data['folder_id'].'_'.$data['uid'];  
83 -// $this->es->save($id,$this->getData($data));  
84 } 79 }
85 80
86 } 81 }
@@ -94,9 +89,9 @@ class SyncMailToEs { @@ -94,9 +89,9 @@ class SyncMailToEs {
94 // if($this->table == 'lists_hot'){ 89 // if($this->table == 'lists_hot'){
95 // 90 //
96 // } 91 // }
97 - if($this->table == 'lists'){ 92 + if(in_array($this->table,['lists','lists_back'])){
98 // 更新es 93 // 更新es
99 - $lists = db()->all(listsSql::all($this->where,'`id`')); 94 + $lists = listsSql::all(db(),$this->where,'`id`');
100 foreach ($lists as $list){ 95 foreach ($lists as $list){
101 redis()->rPush('sync_to_es',$list['id'].'.1'); 96 redis()->rPush('sync_to_es',$list['id'].'.1');
102 // $id = $list['email_id'].'_'.$list['folder_id'].'_'.$list['uid']; 97 // $id = $list['email_id'].'_'.$list['folder_id'].'_'.$list['uid'];
@@ -83,7 +83,7 @@ class fob_ai_mail_auto_reply { @@ -83,7 +83,7 @@ class fob_ai_mail_auto_reply {
83 continue; 83 continue;
84 } 84 }
85 // 查询数据 85 // 查询数据
86 - $data = $this->db->throw()->first(\Model\listsSql::first('`id` = '.$did,'`id`,`folder_id`,`email_id`,`subject`,`is_hots`,`from`,`udate`,`to`,`uid`')); 86 + $data = \Model\listsSql::first($this->db,'`id` = '.$did,'`id`,`folder_id`,`email_id`,`subject`,`is_hots`,`from`,`udate`,`to`,`uid`',true);
87 if($data && !$data['is_hots']){ 87 if($data && !$data['is_hots']){
88 88
89 // 不是屏蔽的 89 // 不是屏蔽的
@@ -86,7 +86,7 @@ class fob_hot_ai_mail_auto_reply @@ -86,7 +86,7 @@ class fob_hot_ai_mail_auto_reply
86 // } 86 // }
87 87
88 // 查询数据 88 // 查询数据
89 - $data = $this->db->first(\Model\listsSql::first('`id` = ' . $did, '`id`,`to`,`folder_id`,`email_id`,`subject`,`is_hots`,`from`,`udate`,`uid`')); 89 + $data = \Model\listsSql::first($this->db,'`id` = ' . $did, '`id`,`to`,`folder_id`,`email_id`,`subject`,`is_hots`,`from`,`udate`,`uid`');
90 if ($data && $data['is_hots']) { 90 if ($data && $data['is_hots']) {
91 // 在检查下是否是 收件箱 91 // 在检查下是否是 收件箱
92 if ($this->db->cache(3600)->value(\Model\folderSql::has(['id' => $data['folder_id'], 'origin_folder' => 'INBOX']))) { 92 if ($this->db->cache(3600)->value(\Model\folderSql::has(['id' => $data['folder_id'], 'origin_folder' => 'INBOX']))) {
@@ -110,453 +110,6 @@ class Mail { @@ -110,453 +110,6 @@ class Mail {
110 } 110 }
111 111
112 112
113 - /**  
114 - * 同步文件夹  
115 - * @param int $email_id  
116 - * @param DbPool|null $db  
117 - * @return mixed  
118 - * @author:dc  
119 - * @time 2023/2/5 10:58  
120 - */  
121 - public function syncFolder($email_id,$db=null){  
122 - $db = $db ? $db : db();  
123 - // 读取所有文件夹,未解密  
124 - $folders = $this->client->getFolder();  
125 -  
126 - foreach ($folders as $k=>$item){  
127 - $pname = explode('/',$item['folder']);  
128 - if(count($pname)>1){  
129 - array_pop($pname);  
130 - $pname = implode('/',$pname);  
131 - }else{  
132 - $pname = '';  
133 - }  
134 -  
135 - $folders[$k]['pname'] = $pname;  
136 - }  
137 -  
138 - $p = 0;  
139 - $uuids = [];  
140 - while ($folders){  
141 - foreach ($folders as $fk=>$folder){  
142 - $uuid = md5($email_id.$folder['folder']);  
143 - $uuids[$uuid] = $uuid;  
144 - // 查找/出现的次数  
145 - if (substr_count($folder['folder'],'/') == $p){  
146 -// 查找pid  
147 - $pid = $db->value(folderSql::has(['uuid'=>md5($email_id.$folder['pname'])]));  
148 - $pid = $pid ? $pid : 0;  
149 -// try {  
150 - $folder_name = '';  
151 - // 已发送  
152 - if(in_array('Send',$folder['check'])){  
153 - $folder_name = folderAlias('Send');  
154 - }  
155 - // 草稿  
156 - elseif(in_array('Drafts',$folder['check'])){  
157 - $folder_name = folderAlias('Drafts');  
158 - }  
159 - // 垃圾  
160 - elseif(in_array('Junk',$folder['check'])){  
161 - $folder_name = folderAlias('Junk');  
162 - }  
163 - // 回收站  
164 - elseif(in_array('Trash',$folder['check'])){  
165 - $folder_name = folderAlias('Trash');  
166 - }  
167 -  
168 - if(!$folder_name){  
169 - $fn = explode('/',$folder['parseFolder']);  
170 - $folder_name = folderAlias(end($fn));  
171 - }  
172 - if(!$db->count(folderSql::has(['uuid'=>$uuid]))){  
173 - $db->insert(folderSql::$table,[  
174 - 'email_id' => $email_id,  
175 - 'folder' => folderAlias($folder_name),  
176 - 'origin_folder' => $folder['folder'],  
177 - 'uuid' => $uuid,  
178 - 'pid' => $pid  
179 - ],false);  
180 - }else{  
181 - $db->update(folderSql::$table,[  
182 - 'email_id' => $email_id,  
183 - 'folder' => folderAlias($folder_name),  
184 - 'origin_folder' => $folder['folder'],  
185 - 'uuid' => $uuid,  
186 - 'pid' => $pid  
187 - ],dbWhere(['email_id' => $email_id,'uuid' => $uuid]),false);  
188 - }  
189 -// }catch (\Throwable $e){  
190 - // 这里就不处理失败了  
191 -// }  
192 -  
193 - unset($folders[$fk]);  
194 -  
195 - }  
196 - }  
197 - $p++;  
198 - }  
199 -  
200 - if($uuids){  
201 - // 删除以前的  
202 - $db->delete(folderSql::$table,['uuid.notin'=>$uuids,'email_id'=>$email_id]);  
203 - }  
204 -  
205 - }  
206 -  
207 -  
208 - /**  
209 - * 同步邮件  
210 - * @param $email_id  
211 - * @param $folder_id  
212 - * @param string $folder  
213 - * @param null|DbPool $db  
214 - * @return bool|array  
215 - * @throws \Exception  
216 - * @author:dc  
217 - * @time 2023/2/18 9:54  
218 - */  
219 - public function syncMail($email_id,$folder_id,$folder='INBOX') {  
220 - if(empty($folder)){  
221 - return 0;  
222 - }  
223 -// _echo('正在同步文件夹:'.$folder);  
224 - $db = db();  
225 - // 选择文件夹  
226 - try {  
227 - $status = $this->client->selectFolder($folder);  
228 - }catch (\Throwable $e){  
229 - return 0;  
230 - }  
231 -  
232 -  
233 - // 是否有邮件  
234 - if (!is_array($status) || !isset($status['EXISTS']) || !$status['EXISTS']){  
235 - return true;  
236 - }  
237 -  
238 - // 更新数量  
239 - $upFolderData = ['exsts'=>$status['EXISTS'],'last_sync_time' => time()];  
240 - // 谷歌 不返未读数量 谢特  
241 - if(isset($status['UNSEEN'])){  
242 - $upFolderData['unseen'] = $status['UNSEEN'];  
243 - }  
244 - $db->update(  
245 - folderSql::$table,  
246 - $upFolderData,  
247 - dbWhere(['id'=>$folder_id]),  
248 - false  
249 - );  
250 -  
251 - // 读取黑名单  
252 - $blacklist = redis()->get('blacklist:'.$email_id);  
253 - $blackFolder = '';  
254 - if($blacklist){  
255 - $blackFolder = $db->cache(86400*30)->value(folderSql::originFolder($email_id,'垃圾箱'));  
256 - }  
257 -  
258 - //  
259 - $nu = 100;  
260 - $msgno = 1;  
261 - $success_uid = [];  
262 - while (true){  
263 -  
264 - // 结束操作了  
265 - if(redis()->get(SYNC_RUNNING_REDIS_KEY) == 'stop'){  
266 - break;  
267 - }  
268 -  
269 - // 是否结束了  
270 - if($status['EXISTS'] < $msgno){  
271 - break;  
272 - }  
273 - // 是否超过了最大数量  
274 - $maxmsgno = ($msgno-1)+$nu;  
275 - if($maxmsgno > $status['EXISTS']){  
276 - $maxmsgno = $status['EXISTS'];  
277 - }  
278 - $uids = $this->client->fetch(range($msgno,$maxmsgno),'UID');  
279 - if(!$uids){  
280 - break;  
281 - }  
282 -  
283 -  
284 - $uids = array_column($uids,'UID');  
285 - foreach ($uids as $k=>$uid){  
286 - if($db->cache(86400*30,false)->value(listsSql::first(dbWhere(['email_id'=>$email_id,'folder_id'=>$folder_id,'uid'=>$uid]),'count(*) as c'))){  
287 -  
288 - unset($uids[$k]);  
289 - }  
290 - }  
291 -  
292 -  
293 - $msgno += $nu;  
294 -  
295 - // 开始同步  
296 - if($uids){  
297 - $this->syncUidEmail(  
298 - $uids,  
299 - $email_id,  
300 - $folder,  
301 - $folder_id,  
302 - $blacklist,  
303 - $blackFolder,  
304 - $db  
305 - );  
306 - $success_uid = array_merge($success_uid,$uids);  
307 - }  
308 -  
309 - }  
310 -  
311 - // 更新数量  
312 - if(!isset($status['UNSEEN'])){  
313 - // 统计未读数量  
314 - $unseen = $db->count(listsSql::listCount(dbWhere([  
315 - 'seen' => 0,  
316 - 'deleted' => 0,  
317 - // 'email_id' => $email_id,  
318 - 'folder_id' => $folder_id,  
319 - ])));  
320 - $db->update(  
321 - folderSql::$table,  
322 - ['unseen' => $unseen],  
323 - dbWhere(['id'=>$folder_id]),  
324 - false  
325 - );  
326 - }  
327 -  
328 -  
329 - return $success_uid;  
330 -  
331 - }  
332 -  
333 - /**  
334 - * 同步邮件 只通过 uid获取  
335 - * @param array $uids  
336 - * @param $email_id  
337 - * @param $folder  
338 - * @param $folder_id  
339 - * @param $blacklist  
340 - * @param $blackFolder  
341 - * @param \Lib\DbPool $db  
342 - * @throws \Exception  
343 - * @author:dc  
344 - * @time 2023/8/2 15:35  
345 - */  
346 - public function syncUidEmail(array $uids,$email_id,$folder,$folder_id,$blacklist,$blackFolder,$db){  
347 - $results = $this->client->fetchHeader($uids,true);  
348 -  
349 - if($results && is_array($results)){  
350 - // 表示已存在新邮件  
351 - if($folder == 'INBOX') redis()->incr('have_new_mail_'.$email_id,120);  
352 -  
353 - // 批量插入  
354 - foreach ($results as $key=>$result){  
355 - $header = $result['HEADER.FIELDS'];  
356 -  
357 - foreach ($result['FLAGS'] as $k=>$FLAG){  
358 - $result['FLAGS'][$k] = strtolower(str_replace('\\','',$FLAG));  
359 - }  
360 - try {  
361 -  
362 - foreach ($header as $k=>$item){  
363 - $header[strtolower($k)] = $item;  
364 - }  
365 -  
366 - // 没有收件人  
367 - $header['to'] = MailFun::toOrFrom($header['to']??'');  
368 -  
369 -  
370 - $header['from'] = MailFun::toOrFrom($header['from']);  
371 - // 抄送 ,密送  
372 - $cc = [];  
373 - $bcc = [];  
374 - if($header['cc']??''){  
375 - $cc = MailFun::toOrFrom($header['cc']);  
376 - }  
377 - if($header['bcc']??''){  
378 - $bcc = MailFun::toOrFrom($header['bcc']);  
379 - }  
380 -  
381 -  
382 - $data = [  
383 - 'uid' => $result['UID'],  
384 - 'subject' => $header['subject']??($header['Subject']??($header['SUBJECT']??'')),  
385 - 'cc' => $cc,  
386 - 'bcc' => $bcc,  
387 - 'from' => $header['from'][0]['email']??'',  
388 - 'from_name' => $header['from'][0]['name']??'',  
389 - 'to' => $header['to']?implode(',',array_column($header['to'],'email')):'',  
390 - 'to_name' => json_encode($header['to']),  
391 - 'date' => strtotime(is_array($header['date']??'') ? $header['date'][0] : $header['date']??''),  
392 -// 'message_id' => $header['message-id']??'',  
393 - 'udate' => strtotime($result['INTERNALDATE']),  
394 - 'size' => $result['RFC822.SIZE']??0,  
395 - 'recent' => in_array('recent',$result['FLAGS']) ? 1 : 0,  
396 - 'seen' => in_array('seen',$result['FLAGS']) ? 1 : 0,  
397 - 'draft' => in_array('draft',$result['FLAGS']) ? 1 : 0,  
398 - 'flagged' => in_array('flagged',$result['FLAGS']) ? 1 : 0,  
399 - 'answered' => in_array('answered',$result['FLAGS']) ? 1 : 0,  
400 - 'folder_id' => $folder_id,  
401 - 'email_id' => $email_id,  
402 - 'is_file' => MailFun::isFile($result['BODYSTRUCTURE']??'') ? 1: 0 //是否附件  
403 - ];  
404 - $data['date'] = $data['date'] ? : 0;  
405 -  
406 - // 验证是否存在黑名单中  
407 - if($blacklist && $blackFolder!=$folder){  
408 - // 邮箱是否在黑名单中  
409 - $isBlacklist = false;  
410 - if (!empty($blacklist['emails']) && is_array($blacklist['emails']) && in_array($data['from'],$blacklist['emails'])){  
411 - $isBlacklist = true;  
412 - }  
413 - // 域是否存在  
414 - if (!empty($blacklist['domain']) && is_array($blacklist['domain']) && in_array(explode('@',$data['from'])[1],$blacklist['domain'])){  
415 - $isBlacklist = true;  
416 - }  
417 -  
418 - if($isBlacklist && $blackFolder){  
419 - // 移入垃圾箱  
420 - try {  
421 - $this->client->move([$result['UID']],$blackFolder);  
422 - }catch (\Throwable $e){  
423 - logs('移动邮件失败 '.$result['UID'].':'.$e->getMessage().$e->getTraceAsString());  
424 - }  
425 -  
426 - continue;  
427 - }  
428 - }  
429 -  
430 -  
431 - }catch (\Throwable $e){  
432 - logs(  
433 - '邮件解析失败:'.PHP_EOL.$e->getMessage().PHP_EOL.print_r($result,true),  
434 - LOG_PATH.'/imap/mail/'.$email_id.'/'.$result['UID'].'.log'  
435 - );  
436 - unset($results[$key]);  
437 - continue;  
438 - }  
439 -  
440 - // 插入数据库  
441 - // 主题太长了就截取掉  
442 - $data['subject'] = mb_substr($data['subject'],0,3500);  
443 - try {  
444 - $id = $db->throw()->insert(listsSql::$table,$data);  
445 - if($id){  
446 - Event::call(SyncMail::class,$id,$data);  
447 - }  
448 -  
449 - }catch (\Throwable $e){  
450 - // 插入失败,尝试更新  
451 - $db->update(listsSql::$table,$data,dbWhere([  
452 - 'email_id'=> $data['email_id'],  
453 - 'folder_id' => $data['folder_id'],  
454 - 'uid' => $data['uid']  
455 - ]));  
456 - }  
457 -  
458 -  
459 - $results[$key] = [];  
460 - }  
461 - }  
462 - }  
463 -  
464 -  
465 - /**  
466 - * 同步 邮件 内容 body  
467 - * @param $folder_name  
468 - * @param $uid  
469 - * @param $id  
470 - * @param null $db  
471 - * @return bool  
472 - * @throws \Exception  
473 - * @author:dc  
474 - * @time 2023/4/23 17:40  
475 - */  
476 - public function syncBody($folder_name, $uid , $id, $db=null):bool {  
477 - if(empty($folder_name)){  
478 - return 0;  
479 - }  
480 - $db = $db ? $db : db();  
481 - // 选择文件夹  
482 - $this->client->selectFolder($folder_name);  
483 -  
484 - $body = $this->client->fetchBody([$uid],MAIL_ATTACHMENT_PATH,true);  
485 -  
486 - $body = array_values($body);  
487 - $body = $body[0]['RFC822.TEXT']??'';  
488 -  
489 - if(!empty($body)){  
490 - $description = '';  
491 - foreach ($body as $key=>$item){  
492 -  
493 - if(!empty($item['body'])){  
494 - // 过滤二进制  
495 - $item['body'] = preg_replace('/<0x[a-f\d]+>/','',$item['body']);  
496 - $body[$key]['body'] = base64_encode($item['body']);  
497 - }  
498 -  
499 - if(!$description && in_array($item['type']??'',['text/html','text/plain'])){  
500 -  
501 - if(!empty($item['charset'])){  
502 - $value = mb_iconv($item['body']?:'','utf-8',$item['charset']?:null);  
503 - $value = $value ? $value : $item['body'];  
504 - }else{  
505 - $value = $item['body'];  
506 - }  
507 - $value = @html_entity_decode($value, ENT_COMPAT, 'UTF-8');  
508 - $value=preg_replace("/<(script.*?)>(.*?)<(\/script.*?)>/si","",$value); //过滤script标签  
509 - $value=preg_replace("/<(\/?script.*?)>/si","",$value); //过滤script标签  
510 - $value=preg_replace("/javascript/si","Javascript",$value); //过滤script标签  
511 - $value=preg_replace("/<(style.*?)>(.*?)<(\/style.*?)>/si","",$value); //过滤style标签  
512 - $value=preg_replace("/<(\/?style.*?)>/si","",$value); //过滤style标签  
513 -  
514 - $value = strip_tags($value);  
515 - $value = str_replace(["\n","\\n","&nbsp;"],'',$value);  
516 - $description = mb_substr(trim($value),0,190);  
517 -  
518 - }  
519 -  
520 -  
521 -  
522 - if(!empty($body[$key]['filename'])){  
523 - $body[$key]['filename'] = base64_encode($body[$key]['filename']);  
524 - }  
525 -  
526 - if(!empty($body[$key]['name'])){  
527 - $body[$key]['name'] = base64_encode($body[$key]['name']);  
528 - }  
529 -  
530 - }  
531 -  
532 - bodySql::insertOrUpdate([  
533 - 'lists_id' => $id,  
534 - 'text_html' => $body // todo::因为邮件会出现多编码问题,会导致数据库写不进去  
535 - ]);  
536 -  
537 -  
538 - // 更新描述  
539 - try {  
540 - $db->update(listsSql::$table,[  
541 - 'description' => @base64_encode($description) ? $description : '',  
542 - 'is_file' => MailFun::isBodyFile($body)  
543 - ],dbWhere([  
544 - 'id' => $id  
545 - ]));  
546 - }catch (\Throwable $e){  
547 - $db->update(listsSql::$table,[  
548 - 'is_file' => MailFun::isBodyFile($body)  
549 - ],dbWhere([  
550 - 'id' => $id  
551 - ]));  
552 - }  
553 -  
554 - }  
555 -  
556 - return true;  
557 -  
558 - }  
559 -  
560 113
561 /** 114 /**
562 * 设置为未读 115 * 设置为未读
@@ -18,51 +18,21 @@ class listsSql { @@ -18,51 +18,21 @@ class listsSql {
18 public static $table = 'lists'; 18 public static $table = 'lists';
19 19
20 20
21 - /**  
22 - * 查询列表  
23 - * @param string $where  
24 - * @param int $p  
25 - * @param int $size  
26 - * @return string  
27 - * @author:dc  
28 - * @time 2023/3/16 18:11  
29 - */  
30 - public static function lists(string $where, int $p, int $size){  
31 -  
32 - $filed = '`id`,`uid`,`subject`,`from`,`from_name`,`to`,`date`,`size`,`recent`,`flagged`,`answered`,`deleted`,`seen`,`draft`,`udate`,`folder_id`,`is_file`,`cc`,`bcc`,`description`,`email_id`,`to_name`';  
33 -  
34 - return "select {$filed} from `".static::$table."` where ".$where." order by `udate` desc limit {$size} offset ".(($p-1)*$size);  
35 -  
36 - }  
37 -  
38 - /**  
39 - * 统计列表  
40 - * @param string $where  
41 - * @return string  
42 - * @author:dc  
43 - * @time 2023/3/16 18:10  
44 - */  
45 - public static function listCount(string $where){  
46 -  
47 - return "select count(*) from `".static::$table."` where ".$where;  
48 - }  
49 -  
50 21
51 - /**  
52 - * 获取已有的uid  
53 - * @param int $email_id  
54 - * @param int $folder_id  
55 - * @param array $uids  
56 - * @return string  
57 - * @author:dc  
58 - * @time 2023/4/23 16:54  
59 - */  
60 - public static function getUids(int $email_id, int $folder_id, array $uids){  
61 - return "select `uid` from `".static::$table."` where ".dbWhere(['email_id'=>$email_id,'folder_id'=>$folder_id,'uid'=>$uids]); 22 + public static function update(\Lib\Db $db,$data,$where) {
  23 + if(is_array($where)){
  24 + $where = dbWhere($where);
  25 + }elseif (is_numeric($where)) {
  26 + $where = dbWhere(['id' => $where]);
  27 + }
  28 + $num = 0;
  29 + foreach ([self::$table,"lists_back",/* "lists_hot" */] as $table) {
  30 + $num += $db->update($table,$data,$where);
  31 + }
  32 + return $num;
62 } 33 }
63 34
64 35
65 -  
66 /** 36 /**
67 * 根据id查询 37 * 根据id查询
68 * @param string $where 38 * @param string $where
@@ -70,29 +40,63 @@ class listsSql { @@ -70,29 +40,63 @@ class listsSql {
70 * @author:dc 40 * @author:dc
71 * @time 2023/3/17 16:24 41 * @time 2023/3/17 16:24
72 */ 42 */
73 - public static function first(string $where,$filed='*'):string { 43 + public static function first($db,string $where,$filed='*', $throw=false) {
  44 +
  45 + foreach ([self::$table,"lists_back","lists_hot"] as $table) {
  46 + $sql = "select {$filed} from `".$table."` where ".$where.' limit 1';
  47 + if($throw){
  48 + $data = $db->throw($throw)->first($sql);
  49 + }else{
  50 + $data = $db->first($sql);
  51 + }
  52 + if($data) {
  53 + return $data;
  54 + }
  55 + }
74 56
75 - return "select {$filed} from `".self::$table."` where ".$where.' limit 1'; 57 + return [];
76 } 58 }
77 59
78 - public static function firstHot(string $where,$filed='*'):string {  
79 60
80 - return "select {$filed} from `lists_hot` where ".$where.' limit 1'; 61 + public static function count($db,string $where){
  62 + $num = 0;
  63 + foreach ([self::$table,"lists_back",/*"lists_hot"*/] as $table) {
  64 + $sql = "select count(*) as `mc` from `".$table."` where ".$where;
  65 + $data = $db->value($sql);
  66 + if($data && is_numeric($data)) {
  67 + $num += $data;
  68 + }
  69 + }
  70 + return $num;
81 } 71 }
82 72
  73 +
83 /** 74 /**
84 * 查询所有 75 * 查询所有
  76 + * @param $db
85 * @param $where 77 * @param $where
86 * @param string $filed 78 * @param string $filed
87 - * @return string 79 + * @return array
88 * @author:dc 80 * @author:dc
89 * @time 2024/1/22 11:15 81 * @time 2024/1/22 11:15
90 */ 82 */
91 - public static function all($where,$filed='*'){  
92 - return "select {$filed} from `".self::$table."` where ".$where; 83 + public static function all($db,$where,$filed='*'){
  84 + if(is_array($where)){
  85 + $where = dbWhere($where);
  86 + }
  87 + $data = [];
  88 + foreach ([self::$table,"lists_back"] as $table) {
  89 + $sql = "select {$filed} from `".$table."` where ".$where;
  90 + $all = $db->all($sql);
  91 + if($all) {
  92 + $data = array_merge($data, $all);
  93 + }
  94 + }
  95 + return $data;
93 } 96 }
94 97
95 98
  99 +
96 /** 100 /**
97 * 存草稿 101 * 存草稿
98 * @param array $data 102 * @param array $data
@@ -133,12 +137,13 @@ class listsSql { @@ -133,12 +137,13 @@ class listsSql {
133 if($draftid){ 137 if($draftid){
134 // 修改 138 // 修改
135 unset($draftData['uid']); 139 unset($draftData['uid']);
136 - if(!db()->update(listsSql::$table,$draftData,dbWhere( 140 + $t = listsSql::update(db(),$draftData,dbWhere(
137 [ 141 [
138 'id' => $draftid, 142 'id' => $draftid,
139 'email_id' => $draftData['email_id'] 143 'email_id' => $draftData['email_id']
140 ] 144 ]
141 - ))){ 145 + ));
  146 + if(!$t){
142 return 0; 147 return 0;
143 } 148 }
144 }else{ 149 }else{
@@ -407,7 +407,7 @@ class SyncMail { @@ -407,7 +407,7 @@ class SyncMail {
407 foreach ($uids as $k=>$uid){ 407 foreach ($uids as $k=>$uid){
408 408
409 $num = redis()->get('h_'.$folder_id.'_'.$uid,function () use ($folder_id,$uid){ 409 $num = redis()->get('h_'.$folder_id.'_'.$uid,function () use ($folder_id,$uid){
410 - $num = $this->db->value(listsSql::first(dbWhere(['email_id'=>$this->emailId(),'folder_id'=>$folder_id,'uid'=>$uid]),'count(*) as c')); 410 + $num = listsSql::count($this->db,dbWhere(['email_id'=>$this->emailId(),'folder_id'=>$folder_id,'uid'=>$uid]));
411 if($num){ 411 if($num){
412 redis()->set('h_'.$folder_id.'_'.$uid,1,86400); 412 redis()->set('h_'.$folder_id.'_'.$uid,1,86400);
413 } 413 }
@@ -455,10 +455,15 @@ class SyncMail { @@ -455,10 +455,15 @@ class SyncMail {
455 if($this->isStop) return $sync_number; 455 if($this->isStop) return $sync_number;
456 456
457 if($this->isUid){ 457 if($this->isUid){
458 - $maxUid = $this->db->value(listsSql::first(dbWhere([ 458 + $maxUid = listsSql::first($this->db,dbWhere([
459 'email_id'=>$this->emailId(), 459 'email_id'=>$this->emailId(),
460 'folder_id'=>$folder_id, 460 'folder_id'=>$folder_id,
461 - ]),'max(uid)')); 461 + ]),'max(`uid`) as `uid`');
  462 + if($maxUid && $maxUid['uid']){
  463 + $maxUid = $maxUid['uid'];
  464 + }else {
  465 + $maxUid = 0;
  466 + }
462 $maxUid = $maxUid?$maxUid:0; 467 $maxUid = $maxUid?$maxUid:0;
463 if($this->isUid==1&&!$maxUid){ 468 if($this->isUid==1&&!$maxUid){
464 return 0; 469 return 0;
@@ -567,11 +572,14 @@ class SyncMail { @@ -567,11 +572,14 @@ class SyncMail {
567 $data['subject'] = str_replace('_',' ',$data['subject']); 572 $data['subject'] = str_replace('_',' ',$data['subject']);
568 573
569 // 查询是否存在 574 // 查询是否存在
570 - $id = $this->db->value(listsSql::first(dbWhere([ 575 + $id = listsSql::first($this->db,dbWhere([
571 'email_id'=> $data['email_id'], 576 'email_id'=> $data['email_id'],
572 'folder_id' => $data['folder_id'], 577 'folder_id' => $data['folder_id'],
573 'uid' => $data['uid'] 578 'uid' => $data['uid']
574 - ]),'`id`')); 579 + ]),'`id`');
  580 + if($id){
  581 + $id = $id['id'];
  582 + }
575 583
576 if(!$id){ 584 if(!$id){
577 $this->eLog( 585 $this->eLog(
@@ -643,7 +651,7 @@ class SyncMail { @@ -643,7 +651,7 @@ class SyncMail {
643 $data['uid'], 651 $data['uid'],
644 $data['subject'], 652 $data['subject'],
645 )); 653 ));
646 - $this->db->update(listsSql::$table,$data,dbWhere(['id'=> $id])); 654 + listsSql::update($this->db,$data,dbWhere(['id'=> $id]));
647 } 655 }
648 656
649 if(php_sapi_name()=='cli' && $this->isBody === null){ 657 if(php_sapi_name()=='cli' && $this->isBody === null){
@@ -771,7 +779,7 @@ class SyncMail { @@ -771,7 +779,7 @@ class SyncMail {
771 } 779 }
772 780
773 // 更新描述 781 // 更新描述
774 - $this->db->update(listsSql::$table,[ 782 + listsSql::update($this->db,[
775 'description'=> 783 'description'=>
776 Fun::mb_convert_encoding(mb_substr($mailBody,0,150),'utf-8') 784 Fun::mb_convert_encoding(mb_substr($mailBody,0,150),'utf-8')
777 ],dbWhere(['id'=> $id])); 785 ],dbWhere(['id'=> $id]));