作者 邓超

1

@@ -5,7 +5,7 @@ error_reporting(E_ERROR | E_NOTICE | E_WARNING); @@ -5,7 +5,7 @@ error_reporting(E_ERROR | E_NOTICE | E_WARNING);
5 ini_set('display_errors',0); 5 ini_set('display_errors',0);
6 6
7 // 开启4个进程 7 // 开启4个进程
8 -define('WORKER_NUM',10); 8 +define('WORKER_NUM',1);
9 // 开启最大1000个协程 9 // 开启最大1000个协程
10 define('COROUTINE_MAX_NUM',5000); 10 define('COROUTINE_MAX_NUM',5000);
11 // 是否继续运行 11 // 是否继续运行
@@ -42,19 +42,35 @@ class Home extends Base { @@ -42,19 +42,35 @@ class Home extends Base {
42 } 42 }
43 } 43 }
44 44
45 - // 邮件文件夹的id  
46 - $folder_id = (int) app()->request('folder_id');  
47 // 附件 45 // 附件
48 $attachment = app()->request('attachment'); 46 $attachment = app()->request('attachment');
49 // 已读/未读 47 // 已读/未读
50 $seen = app()->request('seen',-1,'intval'); 48 $seen = app()->request('seen',-1,'intval');
  49 + // 软删
  50 + $deleted = app()->request('deleted',0,'intval');
51 51
52 52
53 $where = ['email_id'=>$this->getEmails('id')]; 53 $where = ['email_id'=>$this->getEmails('id')];
  54 +
  55 + // 目录
  56 + $folder = app()->request('folder','INBOX');
  57 + $folderList = db()->all(folderSql::all($where['email_id']));
  58 + $folder_id = [];
  59 + // 文件夹id
  60 + if($folderList){
  61 + foreach ($folderList as $item){
  62 + if($item['folder'] == $folder){
  63 + $folder_id[] = $item['id'];
  64 + }
  65 + }
  66 + }
  67 +
54 //目录 68 //目录
55 if($folder_id) $where['folder_id'] = $folder_id; 69 if($folder_id) $where['folder_id'] = $folder_id;
56 if($ids) $where['id'] = $ids; 70 if($ids) $where['id'] = $ids;
57 if($attachment) $where['is_file'] = 1; //附件 71 if($attachment) $where['is_file'] = 1; //附件
  72 + // 软删
  73 + $where['deleted'] = $deleted;
58 // 已读/未读 74 // 已读/未读
59 if(in_array($seen,[0,1])){ 75 if(in_array($seen,[0,1])){
60 $where['seen'] = $seen; 76 $where['seen'] = $seen;
@@ -164,6 +180,24 @@ class Home extends Base { @@ -164,6 +180,24 @@ class Home extends Base {
164 * @time 2023/3/17 16:15 180 * @time 2023/3/17 16:15
165 */ 181 */
166 public function seen_2_unseen(){ 182 public function seen_2_unseen(){
  183 + $this->setFlags('seen');
  184 + }
  185 +
  186 +
  187 +
  188 + /**
  189 + * 邮件回收站,进行回收,恢复邮件
  190 + * @author:dc
  191 + * @time 2023/3/21 11:41
  192 + */
  193 + public function recycle(){
  194 + $this->setFlags('deleted');
  195 + }
  196 +
  197 +
  198 +
  199 +
  200 + private function setFlags($d){
167 $emails = $this->getEmails(); 201 $emails = $this->getEmails();
168 202
169 $mail_ids = app()->request('mail_ids'); 203 $mail_ids = app()->request('mail_ids');
@@ -173,8 +207,8 @@ class Home extends Base { @@ -173,8 +207,8 @@ class Home extends Base {
173 } 207 }
174 } 208 }
175 // 已读或未读 209 // 已读或未读
176 - $seen = (int) app()->request('seen');  
177 - $seen = $seen ? 1 : 0; 210 + $fv = (int) app()->request($d);
  211 + $fv = $fv ? 1 : 0;
178 212
179 $data = db()->all(listsSql::first(dbWhere(['id'=>$mail_ids,'email_id'=>array_column($emails,'id')]))); 213 $data = db()->all(listsSql::first(dbWhere(['id'=>$mail_ids,'email_id'=>array_column($emails,'id')])));
180 if($data){ 214 if($data){
@@ -200,12 +234,23 @@ class Home extends Base { @@ -200,12 +234,23 @@ class Home extends Base {
200 $mailInstance = new Mail($emails[$eid]['email'],base64_decode($emails[$eid]['password']),$emails[$eid]['imap']); 234 $mailInstance = new Mail($emails[$eid]['email'],base64_decode($emails[$eid]['password']),$emails[$eid]['imap']);
201 235
202 if($mailInstance->login()){ 236 if($mailInstance->login()){
203 - $mailInstance->seen(array_column($uid,'uid'),$folder['origin_folder'],$seen); 237 + switch ($d){
  238 + // 已读 未读
  239 + case 'seen':{
  240 + $mailInstance->seen(array_column($uid,'uid'),$folder['origin_folder'],$fv);
  241 + break;
  242 + }
  243 + // 回收站,已删 未删,软删
  244 + case 'deleted':{
  245 + $mailInstance->recycle(array_column($uid,'uid'),$folder['origin_folder'],$fv);
  246 + break;
  247 + }
  248 + }
204 249
205 $mailInstance = null; 250 $mailInstance = null;
206 // 更新数据 251 // 更新数据
207 db()->update(listsSql::$table,[ 252 db()->update(listsSql::$table,[
208 - 'seen' => $seen 253 + $d => $fv
209 ],dbWhere([ 254 ],dbWhere([
210 'id' => array_column($uid,'id') 255 'id' => array_column($uid,'id')
211 ])); 256 ]));
@@ -223,7 +268,6 @@ class Home extends Base { @@ -223,7 +268,6 @@ class Home extends Base {
223 'mail_id' => $mail_ids 268 'mail_id' => $mail_ids
224 ]); 269 ]);
225 270
226 -  
227 } 271 }
228 272
229 273
@@ -147,7 +147,7 @@ function dbWhere(array $where, string $ar = 'and'):string{ @@ -147,7 +147,7 @@ function dbWhere(array $where, string $ar = 'and'):string{
147 },$v); 147 },$v);
148 if(count($v)===1){ 148 if(count($v)===1){
149 // 只有一个值时就是 = 149 // 只有一个值时就是 =
150 - $sql[] = "`{$f}` = ".$v; 150 + $sql[] = "`{$f}` = ".$v[0];
151 }elseif (count($v) > 1){ 151 }elseif (count($v) > 1){
152 $sql[] = "`{$f}` in (".implode(',',$v).")"; 152 $sql[] = "`{$f}` in (".implode(',',$v).")";
153 } 153 }
@@ -80,7 +80,7 @@ class DbPool { @@ -80,7 +80,7 @@ class DbPool {
80 $timer2 = microtime(true); 80 $timer2 = microtime(true);
81 81
82 // todo:: 记录日志,生产请注释 82 // todo:: 记录日志,生产请注释
83 - $sql = '['.substr($timer2-$timer,0,8).'ms] '.$sql; 83 + $sql = '['.substr(($timer2-$timer)*1000,0,6).'ms] '.$sql;
84 logs( 84 logs(
85 $params ? [$sql,$params] : $sql, 85 $params ? [$sql,$params] : $sql,
86 LOG_PATH.'/'.date('Y-m-d').'.sql.log' 86 LOG_PATH.'/'.date('Y-m-d').'.sql.log'
@@ -318,5 +318,21 @@ class Mail { @@ -318,5 +318,21 @@ class Mail {
318 return $this->client->flags($uids,[Imap::FLAGS_SEEN],$seen ? '+' : '-',true); 318 return $this->client->flags($uids,[Imap::FLAGS_SEEN],$seen ? '+' : '-',true);
319 } 319 }
320 320
  321 + /**
  322 + * 回收站
  323 + * @param $uids
  324 + * @param $folder
  325 + * @param $recycle
  326 + * @author:dc
  327 + * @time 2023/3/21 13:41
  328 + */
  329 + public function recycle($uids,$folder,$recycle){
  330 + // 选择目录
  331 + $status = $this->client->selectFolder($folder);
  332 +
  333 + return $this->client->flags($uids,[Imap::FLAGS_DELETED],$recycle ? '+' : '-',true);
  334 +
  335 + }
  336 +
321 337
322 } 338 }
@@ -29,7 +29,7 @@ class listsSql { @@ -29,7 +29,7 @@ class listsSql {
29 */ 29 */
30 public static function lists(string $where, int $p, int $size){ 30 public static function lists(string $where, int $p, int $size){
31 31
32 - $filed = '`id`,`uid`,`msgno`,`subject`,`from`,`from_name`,`to`,`date`,`size`,`recent`,`flagged`,`answered`,`deleted`,`seen`,`draft`,`udate`,`folder_id`,`is_file`,`cc`,`bcc`,`description`'; 32 + $filed = '`id`,`uid`,`msgno`,`subject`,`from`,`from_name`,`to`,`date`,`size`,`recent`,`flagged`,`answered`,`deleted`,`seen`,`draft`,`udate`,`folder_id`,`is_file`,`cc`,`bcc`,`description`,`email_id`';
33 33
34 return "select {$filed} from `".static::$table."` where ".$where." order by `udate` desc limit {$size} offset ".(($p-1)*$size); 34 return "select {$filed} from `".static::$table."` where ".$where." order by `udate` desc limit {$size} offset ".(($p-1)*$size);
35 35
@@ -31,6 +31,8 @@ return [ @@ -31,6 +31,8 @@ return [
31 'sync' => [\Controller\Home::class, 'sync'], 31 'sync' => [\Controller\Home::class, 'sync'],
32 // 标记为已读 32 // 标记为已读
33 'seen_2_unseen' => [\Controller\Home::class, 'seen_2_unseen'], 33 'seen_2_unseen' => [\Controller\Home::class, 'seen_2_unseen'],
  34 + // 回收站,邮件删除,非真实删除
  35 + 'recycle' => [\Controller\Home::class, 'recycle'],
34 36
35 37
36 38