mail_black_del.php
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
use Model\listsSql;
/**
* 自动回复的邮件
* @author:dc
* @time 2024/9/6 17:09
* Class HotMail
*/
class AutoMail {
public function __construct(){
$this->db = db();
$this->start();
}
/**
* shopk那边的预热邮箱
* @var array
*/
private $black_emails = [];
/**
* @var \Lib\Db|\Lib\DbPool
*/
private $db;
private $fids = [];
/**
* @author:dc
* @time 2024/7/18 14:04
*/
private function start(){
$this->fids = $this->db->all("select `id` from `folders` where `folder` = '收件箱'");
$this->fids = array_column($this->fids,'id');
$this->black_emails = $this->db->all("select * from `ai_black_email`");
$this->black_emails = array_column($this->black_emails,'email');
$this->black_emails = array_map("strtolower",$this->black_emails);
if(redis()->add('black_mail_sync2',1,60)){
echo '正在计算数据';
$maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1");
$id = 0;
while (1){
$ids = [];
for ($i=0;$i<1000;$i++){
$ids[] = $i+$id;
}
$id = end($ids);
redis()->rPush('black_check_ids',implode(',',$ids));
if($id>$maxId){
break;
}
}
echo '计算完成';
}
while (1){
$ids = redis()->lPop('black_check_ids');
if($ids){
$ids = explode(',',$ids);
$this->run($ids);
}else{
echo '等待'.PHP_EOL;
co::sleep(2);
}
}
}
private $filter = [];
private function run($id){
$list = $this->db->all(\Model\listsSql::all(dbWhere(['id'=>$id,'deleted'=>0]),'`id`,`from`,`folder_id`,`email_id`'));
foreach ($list as $item){
// 必须是收件箱
if(in_array($item['folder_id'],$this->fids)){
// 是否在黑名单中
if(in_array(strtolower($item['from']),$this->black_emails)){
if (!isset($this->filter[$item['email_id']])){
// 找到邮箱
$e = $this->db->value(\Model\emailSql::first($item['email_id'],'`email`'));
// 是否是ai邮件
$this->filter[$item['email_id']] =
$this->db->count("select count(*) from `hot_mail` where ".dbWhere(['email'=> $e]));
}
// 是否是ai邮件
if($this->filter[$item['email_id']]){
echo '删除 '.$item['id'].'===>'.$this->db->update(listsSql::$table,['deleted'=>1],dbWhere(['id'=>$item['id']]))."\n";
}
}
}
}
}
}
$pm = new Swoole\Process\Manager();
$pm->addBatch(3,function (){
include_once "../vendor/autoload.php";
// while(1){
new AutoMail();
// 执行完了暂停5分钟在执行
sleep(40);
// }
},true);
$pm->start();