正在显示
5 个修改的文件
包含
106 行增加
和
1 行删除
controller/Blacklist.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace Controller; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 黑名单 | ||
| 7 | + * @author:dc | ||
| 8 | + * @time 2023/4/23 14:48 | ||
| 9 | + * Class Blacklist | ||
| 10 | + * @package Controller | ||
| 11 | + */ | ||
| 12 | +class Blacklist { | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + public function add(){ | ||
| 16 | + | ||
| 17 | + $type = app()->request('type'); | ||
| 18 | + | ||
| 19 | + $value = app()->request('value'); | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + db()->insert(\Model\blacklist::$table,[ | ||
| 25 | + | ||
| 26 | + ]); | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + | ||
| 33 | + | ||
| 34 | +} | 
| @@ -359,6 +359,16 @@ class Home extends Base { | @@ -359,6 +359,16 @@ class Home extends Base { | ||
| 359 | $datas = db()->all(emailSql::getValues(['email'=>$emails],'`id`,`email`,`pwd_error`')); | 359 | $datas = db()->all(emailSql::getValues(['email'=>$emails],'`id`,`email`,`pwd_error`')); | 
| 360 | foreach ($datas as $k=>$v){ | 360 | foreach ($datas as $k=>$v){ | 
| 361 | if(!$v['pwd_error']){ | 361 | if(!$v['pwd_error']){ | 
| 362 | + $blacklist = app()->request('blacklist'); | ||
| 363 | + if(is_array($blacklist)){ | ||
| 364 | + $blacklist = [ | ||
| 365 | + 'emails' => $blacklist['emails']??[], | ||
| 366 | + 'domain' => $blacklist['domain']??[], | ||
| 367 | + ]; | ||
| 368 | + // 黑名单,7天过期时间 | ||
| 369 | + redis()->set('blacklist:'.$v['id'],$blacklist,86400*7); | ||
| 370 | + } | ||
| 371 | + | ||
| 362 | redis()->rPush('sync_email_lists', $v['id']); | 372 | redis()->rPush('sync_email_lists', $v['id']); | 
| 363 | } | 373 | } | 
| 364 | $datas[$k]['have_new'] = redis()->getDel('have_new_mail_'.$v['id']); | 374 | $datas[$k]['have_new'] = redis()->getDel('have_new_mail_'.$v['id']); | 
| @@ -198,6 +198,13 @@ class Mail { | @@ -198,6 +198,13 @@ class Mail { | ||
| 198 | return true; | 198 | return true; | 
| 199 | } | 199 | } | 
| 200 | 200 | ||
| 201 | + // 读取黑名单 | ||
| 202 | + $blacklist = redis()->get('blacklist:'.$email_id); | ||
| 203 | + $blackFolder = ''; | ||
| 204 | + if($blacklist){ | ||
| 205 | + $blackFolder = $db->value(folderSql::originFolder($email_id,'垃圾箱')); | ||
| 206 | + } | ||
| 207 | + | ||
| 201 | // | 208 | // | 
| 202 | $nu = 100; | 209 | $nu = 100; | 
| 203 | $msgno = 1; | 210 | $msgno = 1; | 
| @@ -289,6 +296,27 @@ class Mail { | @@ -289,6 +296,27 @@ class Mail { | ||
| 289 | 'is_file' => MailFun::isFile($result['BODYSTRUCTURE']??'') ? 1: 0 //是否附件 | 296 | 'is_file' => MailFun::isFile($result['BODYSTRUCTURE']??'') ? 1: 0 //是否附件 | 
| 290 | ]; | 297 | ]; | 
| 291 | $data['date'] = $data['date'] ? : 0; | 298 | $data['date'] = $data['date'] ? : 0; | 
| 299 | + | ||
| 300 | + // 验证是否存在黑名单中 | ||
| 301 | + if($blacklist){ | ||
| 302 | + // 邮箱是否在黑名单中 | ||
| 303 | + $isBlacklist = false; | ||
| 304 | + if (!empty($blacklist['emails']) && is_array($blacklist['emails']) && in_array($data['from'],$blacklist['emails'])){ | ||
| 305 | + $isBlacklist = true; | ||
| 306 | + } | ||
| 307 | + // 域是否存在 | ||
| 308 | + if (!empty($blacklist['domain']) && is_array($blacklist['domain']) && in_array(explode('@',$data['from'])[1],$blacklist['domain'])){ | ||
| 309 | + $isBlacklist = true; | ||
| 310 | + } | ||
| 311 | + | ||
| 312 | + if($isBlacklist && $blackFolder){ | ||
| 313 | + // 移入垃圾箱 | ||
| 314 | + $this->client->move($result['UID'],$blackFolder); | ||
| 315 | + continue; | ||
| 316 | + } | ||
| 317 | + } | ||
| 318 | + | ||
| 319 | + | ||
| 292 | }catch (\Throwable $e){ | 320 | }catch (\Throwable $e){ | 
| 293 | logs( | 321 | logs( | 
| 294 | '邮件解析失败:'.PHP_EOL.$e->getMessage().PHP_EOL.print_r($result,true), | 322 | '邮件解析失败:'.PHP_EOL.$e->getMessage().PHP_EOL.print_r($result,true), | 
model/blacklist.php
0 → 100644
| @@ -48,6 +48,16 @@ class folderSql { | @@ -48,6 +48,16 @@ class folderSql { | ||
| 48 | return "select {$filed} from `".self::$table."` where ".dbWhere($where)." limit 1"; | 48 | return "select {$filed} from `".self::$table."` where ".dbWhere($where)." limit 1"; | 
| 49 | } | 49 | } | 
| 50 | 50 | ||
| 51 | - | 51 | + /** | 
| 52 | + * 读取源文件夹 | ||
| 53 | + * @param int $email_id | ||
| 54 | + * @param string $folder | ||
| 55 | + * @return string | ||
| 56 | + * @author:dc | ||
| 57 | + * @time 2023/5/8 11:01 | ||
| 58 | + */ | ||
| 59 | + public static function originFolder(int $email_id,string $folder){ | ||
| 60 | + return "select `origin_folder` from `".static::$table."` where `email_id` = {$email_id} and `folder` = '{$folder}' limit 1"; | ||
| 61 | + } | ||
| 52 | 62 | ||
| 53 | } | 63 | } | 
- 
请 注册 或 登录 后发表评论