syncMail.php
3.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
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
namespace Event;
use Model\folderSql;
use Model\listsSql;
use Swlib\Saber;
use Swlib\SaberGM;
/**
* 邮件同步成功的事件
* @author:dc
* @time 2024/8/22 15:47
* Class syncMail
* @package Event
*/
class syncMail {
/**
* @var \Lib\Db|\Lib\DbPool
*/
private $db;
public function __construct($id,$header,$data)
{
$this->db = db();
// 是否是预热邮件 aicc专用
if(!empty($header['Aicc-Hot-Mail']) || !empty($header['aicc-hot-mail'])){
return $this->hot($id);
}
// 是否在指定文件夹内
$f = folderAlias($this->db->value(folderSql::first($data['folder_id'],'folder')));
if($f=='发件箱'){
if(empty($data['to_name'])){
$data['to_name'] = [];
}
$data['to_name'] = is_array($data['to_name'])?$data['to_name']:json_decode($data['to_name']);
$w = ['email' => array_column($data['to_name'],'email')];
}else{
$w = ['email' =>$data['from']];
}
// 是否在 预热邮箱中
if($this->db->count('select count(*) from `hot_mail` where '.dbWhere($w))){
return $this->hot($id);
}
// 不是预热邮箱
if($f=='收件箱'){
// 邮件过滤 这些邮箱都是系统邮箱
if(!$this->checkEmail($data['from']) && !$this->checkSubject($data['subject'])){
// 通知黑格 2024-08-22 新上 这个是异步的不会阻塞当前进程
try {
SaberGM::post('https://fob.ai.cc/api/email_new_push',[
'sign' => md5(date('ymd').'fob.ai.cc.email'),
'id' => $id,
'subject' => $data['subject'],
'udate' => $data['udate'],
'from' => $data['from'],
'tos' => array_column(json_decode($data['to_name'],1),'email')
]);
}catch (\Throwable $e){
// 就算异常了也不在推送了
}
}
}
}
private function hot($id){
return $this->db->update(listsSql::$table,['is_hots'=>1],dbWhere(['id'=>$id]));
}
/**
* 验证邮箱
* @param $email
* @author:dc
* @time 2024/8/28 14:33
*/
public function checkEmail($email){
// mimecast@wsa.aero
$filterEmail = ['mimecast@wsa.aero'];
if(in_array($email,$filterEmail)){
return true;
}
if(preg_match("/^((no-?reply)|(postmaster)|(mailer-daemon)|(email-notifications)|(googleplay-noreply)|(postmaster-noreply)|(privacy-noreply))@/i",$email)){
return true;
}
if(preg_match("/((no-?reply)|(postmaster)|(mailer-daemon)|(email-notifications))/i",$email)){
return true;
}
return false;
}
/**
* 验证标题是否存在某些关键词
* @param string $subject
* @return bool
* @author:dc
* @time 2024/8/24 15:09
*/
public function checkSubject(string $subject){
$keys = [
'Automatic reply: ',
'Delivery Failure',
'Automatische Antwort:',
'Automatic_reply:',
'Undelivered Mail Returned',
'Mail delivery failed:',
'Delivery Status Notification',
'Undeliverable:',
];
foreach ($keys as $key){
if(stripos($subject,$key)!==false){
return true;
}
}
return false;
}
}