作者 邓超

黑名单

<?php
namespace Controller;
/**
* 黑名单
* @author:dc
* @time 2023/4/23 14:48
* Class Blacklist
* @package Controller
*/
class Blacklist {
public function add(){
$type = app()->request('type');
$value = app()->request('value');
db()->insert(\Model\blacklist::$table,[
]);
}
}
\ No newline at end of file
... ...
... ... @@ -359,6 +359,16 @@ class Home extends Base {
$datas = db()->all(emailSql::getValues(['email'=>$emails],'`id`,`email`,`pwd_error`'));
foreach ($datas as $k=>$v){
if(!$v['pwd_error']){
$blacklist = app()->request('blacklist');
if(is_array($blacklist)){
$blacklist = [
'emails' => $blacklist['emails']??[],
'domain' => $blacklist['domain']??[],
];
// 黑名单,7天过期时间
redis()->set('blacklist:'.$v['id'],$blacklist,86400*7);
}
redis()->rPush('sync_email_lists', $v['id']);
}
$datas[$k]['have_new'] = redis()->getDel('have_new_mail_'.$v['id']);
... ...
... ... @@ -198,6 +198,13 @@ class Mail {
return true;
}
// 读取黑名单
$blacklist = redis()->get('blacklist:'.$email_id);
$blackFolder = '';
if($blacklist){
$blackFolder = $db->value(folderSql::originFolder($email_id,'垃圾箱'));
}
//
$nu = 100;
$msgno = 1;
... ... @@ -289,6 +296,27 @@ class Mail {
'is_file' => MailFun::isFile($result['BODYSTRUCTURE']??'') ? 1: 0 //是否附件
];
$data['date'] = $data['date'] ? : 0;
// 验证是否存在黑名单中
if($blacklist){
// 邮箱是否在黑名单中
$isBlacklist = false;
if (!empty($blacklist['emails']) && is_array($blacklist['emails']) && in_array($data['from'],$blacklist['emails'])){
$isBlacklist = true;
}
// 域是否存在
if (!empty($blacklist['domain']) && is_array($blacklist['domain']) && in_array(explode('@',$data['from'])[1],$blacklist['domain'])){
$isBlacklist = true;
}
if($isBlacklist && $blackFolder){
// 移入垃圾箱
$this->client->move($result['UID'],$blackFolder);
continue;
}
}
}catch (\Throwable $e){
logs(
'邮件解析失败:'.PHP_EOL.$e->getMessage().PHP_EOL.print_r($result,true),
... ...
<?php
namespace Model;
use Lib\DbPool;
/**
* 黑名单
* @author:dc
* @time 2023/4/23 14:43
* Class blacklist
* @package Model
*/
class blacklist {
public static $table = 'blacklist';
}
... ...
... ... @@ -48,6 +48,16 @@ class folderSql {
return "select {$filed} from `".self::$table."` where ".dbWhere($where)." limit 1";
}
/**
* 读取源文件夹
* @param int $email_id
* @param string $folder
* @return string
* @author:dc
* @time 2023/5/8 11:01
*/
public static function originFolder(int $email_id,string $folder){
return "select `origin_folder` from `".static::$table."` where `email_id` = {$email_id} and `folder` = '{$folder}' limit 1";
}
}
... ...