syncMail.php
2.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
<?php
namespace Event;
use Model\folderSql;
use Swlib\Saber;
use Swlib\SaberGM;
/**
* 邮件同步成功的事件
* @author:dc
* @time 2024/8/22 15:47
* Class syncMail
* @package Event
*/
class syncMail {
public function __construct($id,$header,$data)
{
$db = db();
// 是否在指定文件夹内
$f = $db->value(folderSql::first($data['folder_id'],'folder'));
$f = folderAlias($f);
if($f=='收件箱'){
$f = 's';
}elseif($f=='发件箱'){
$f = 'f';
}elseif($f=='垃圾箱'){
$f = 'l';
}
if(in_array($f,['s','f','l'])){
// 是否是预热邮件 aicc专用
if(!empty($header['Aicc-Hot-Mail']) || !empty($header['aicc-hot-mail'])){
$is_hot = 1;
}
if(empty($is_hot)){
if($f == 's' && $db->count('select count(*) from `hot_mail` where `email` = "'.$data['from'].'"')){
$is_hot = 1;
}
}
if(!empty($is_hot)){
try {
// 记录日志
logs('识别到aicc预热邮件 '.$id.'-'.$data['email_id'].'-'.$data['from'],LOG_PATH.'/hot-mail.log');
$db->throw()->insert('fob_hot_mail',[
'lists_id' => $id,
'email_id' => $data['email_id'],
'hot_form' => $data['from'],
'folder' => $f
],false);
}catch (\Throwable $exception){
logs($exception->getMessage());
}
}else{
if($f == 's'){
// 邮件过滤
if(!preg_match("/^((no-?reply)|(postmaster)|(mailer-daemon))@/i",$data['from'])){
// 通知黑格 2024-08-22 新上 这个是异步的不会阻塞当前进程
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')
]);
}
}
}
}
}
}