auto_reply_mail.php
3.5 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
138
139
<?php
use Model\listsSql;
/**
* 自动回复的邮件
* @author:dc
* @time 2024/9/6 17:09
* Class HotMail
*/
class AutoMail {
public function __construct(){
$this->start();
}
/**
* @var Lib\Es\Es
*/
public $es;
/**
* @author:dc
* @time 2024/7/18 14:04
*/
private function start(){
echo "start ";
echo date('Y-m-d H:i:s');
echo "\n";
$at = 0;
$this->es = es();
$h = (int) date('H');
while (true){
$postid = redis()->lPop('resync_to_es_inbox_list');
// 如果有增删 每天7点就开始自动刷
if($postid == '0a'){
if($h>18){
$postid = 0;
}else{
redis()->rPush('resync_to_es_inbox_list','0a');
continue;
}
}
if (!is_numeric($postid)){
break;
}
if(redis()->add('resync_to_es_inbox:'.$postid,1,$postid?600:7200)){
if (!$postid){
$post_ids = fob_mysql()->all("select `post_id` from `e_mail_binds` group by `post_id`");
if($post_ids){
$post_ids = array_column($post_ids,'post_id','post_id');
}
}else{
$post_ids = [$postid];
}
foreach ($post_ids as $post_id){
$total = $this->essss(0,$post_id,0);
$autoTotal = $this->essss(0,$post_id,1);
echo "postid {$post_id} inbox {$total} auto {$autoTotal}\n";
$at += $total + $autoTotal;
}
}
}
echo "总数量 {$at} ";
echo "end ";
echo date('Y-m-d H:i:s');
echo "\n";
}
public function essss($id,$post_id,$is_auto){
$total = 0;
while ( true){
// 查询自动回的邮件
$this->es->setIndex('email_lists_branch_'.$post_id);
$must = [
["term"=>["folder_as_int" => 1]], // 收件箱
["term"=>["is_auto" => $is_auto]], // 非auto
["term"=>["is_hots" => 0]], // 非预热
["term"=>["deleted" => 0]], // 非删除
["term"=>["source" => 2]], // 非删除
["range"=>[
'uuid'=>[
"gt"=>$id
]
]]
];
if($is_auto){
$must[] = [
"match_phrase" =>[
"subject"=>"Re:"
]
];
}
$lists = $this->es->search([
"_source" => ["uuid"],
"query"=>[
"constant_score"=>[
"filter"=>[
"bool"=>[
"must"=> $must
]
]
]
]
],0,1000,['uuid'=>'asc'],1000);
if(empty($lists['hits']['hits'])){
return $total;
}
foreach ($lists['hits']['hits']??[] as $list){
$total++;
$id = $list['_source']['uuid'];
redis()->rPush('sync_to_es',$list['_source']['uuid'].'.1');
}
}
}
}
include_once "../vendor/autoload.php";
new AutoMail();