SyncMail.php
3.4 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
namespace Event;
use Lib\Imap\Parse\MessageItem;
use Model\emailSql;
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(int $id, array $data)
{
$this->db = db();
if($data['is_hots']){
return true;
}
// 是否在指定文件夹内
$f = $this->db->value(folderSql::first($data['folder_id'],'folder'));
if(!$f){
return true;
}
$f = folderAlias($f);
// 不是预热邮箱
if($f=='收件箱'){
// $this->auto_mail($id,$data);
// 邮件过滤 这些邮箱都是系统邮箱
// if(!$this->checkEmail($data['from']) && !$this->checkSubject($data['subject'])){
//只提醒re
if(stripos(trim($data['subject']),'re:')===0){
// 通知黑格 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($data['to_name'],'email')
]);
}catch (\Throwable $e){
// 就算异常了也不在推送了
}
}
}
}
/**
* 自动回复邮箱
* @param $id
* @param $data
* @author:dc
* @time 2024/9/12 15:29
*/
private function auto_mail($id,$data){
$filter = redis()->get('ai_email_filter_lists',[]);
if(!$filter || !is_array($filter)){
$filter = '2 Automatic reply
2 Delivery
2 Automatische Antwort
2 Undeliverable
2 Failure
2 Undelivered
1 noreply
1 postmaster
1 email-notifications
1 mailer-daemon
1 no-reply
2 自动回复
2 Returned mail
2 Autosvar
2 Out Of Office Re
2 Change_of_email_address
2 delivered
2 automatique
2 Reply auto
2 automatic
2 Request received
2 Automatisch
2 Unzustellbar
2 Notification
2 Invitation
2 Automatyczna
2 代开
2 expired';
$filter = explode("\n",$filter);
$filter = array_map(function ($v){
list($t,$str) = [
intval(mb_substr($v,0,1)),
trim(mb_substr($v,1,99)),
];
return [$t,$str];
},$filter);
}
foreach ($filter as $f){
$t = $f[0]??''; // 类型
$str = $f[1]??''; // 值
if(!$str) continue;
$haystack = '';
if($t==2){
$haystack = $data['subject'];
}elseif ($t==1){
$haystack = $data['from'];
}
if(stripos($haystack,$str)!==false){
try {
$this->db->create('lists_auto',['list_id'=>$id],false);
}catch (\Throwable $e){}
break;
}
}
}
}