auto_reply_mail.php
2.6 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
<?php
use Model\listsSql;
/**
* 自动回复的邮件
* @author:dc
* @time 2024/9/6 17:09
* Class HotMail
*/
class AutoMail {
public function __construct(){
$this->start();
}
/**
* @author:dc
* @time 2024/7/18 14:04
*/
private function start(){
$old = redis()->get('prev_auto_mail_keyword',[]);
$filter = isAiAutoMail(true,true);
redis()->set('prev_auto_mail_keyword',$filter,86400);
$t = function ($vs){
return array_map(function ($v){
return $v[0].":".$v[1];
},$vs);
};
// 找到新增的
$q = array_diff($t($filter),$t($old));
if(!$q){
return 0;
}
$es = es('email_lists_copy');
$not_must = [];
foreach ($q as $f){
list($t,$str) = explode(':',$f,2);
if($t==2){
$not_must[] = ["match_phrase"=>["subject"=>$str]];
}elseif ($t==1){
$not_must[] = ["match_phrase"=>["from.email"=>$str]];
}
}
// 查询自动回的邮件
$lists = $es->search([
"_source" => ["uuid","subject","from"],
"query"=>[
"constant_score"=>[
"filter"=>[
"bool"=>[
"must"=>[
["term"=>["folder_as_int" => 1]], // 收件箱
["term"=>["is_auto" => 0]], // 非auto
["term"=>["is_hots" => 0]], // 非预热
["term"=>["deleted" => 0]], // 非删除
["term"=>["source" => 2]], // 非删除
// 自动关键字
[
"bool" => [
"should"=> $not_must,
"minimum_should_match" => 1
]
]
]
]
]
]
]
],0,1000,['udate'=>'desc'],1000);
foreach ($lists['hits']['hits']??[] as $list){
$list = $list['_source'];
$id = intval($list['uuid']??0);
if($id && isAiAutoMail($list['from']['email'],$list['subject'])){
_echo("id = ".$id);
redis()->rPush('sync_to_es',$id);
}
}
}
}
include_once "../vendor/autoload.php";
new AutoMail();