|
@@ -12,7 +12,7 @@ use Model\emailSql; |
|
@@ -12,7 +12,7 @@ use Model\emailSql; |
12
|
use Model\folderSql;
|
12
|
use Model\folderSql;
|
13
|
use Model\listsSql;
|
13
|
use Model\listsSql;
|
14
|
use Model\sendJobsSql;
|
14
|
use Model\sendJobsSql;
|
15
|
-
|
15
|
+use function Co\run;
|
16
|
|
16
|
|
17
|
|
17
|
|
18
|
/**
|
18
|
/**
|
|
@@ -24,23 +24,9 @@ use Model\sendJobsSql; |
|
@@ -24,23 +24,9 @@ use Model\sendJobsSql; |
24
|
class Home extends Base {
|
24
|
class Home extends Base {
|
25
|
|
25
|
|
26
|
|
26
|
|
27
|
- /**
|
|
|
28
|
- * 邮件列表 针对aicc应用那边
|
|
|
29
|
- * @author:dc
|
|
|
30
|
- * @time 2023/2/17 14:12
|
|
|
31
|
- */
|
|
|
32
|
- public function lists(){
|
|
|
33
|
-
|
|
|
34
|
- $limit = app()->request('limit',20,['intval','abs']);
|
|
|
35
|
-
|
|
|
36
|
- $last_id = app()->request('last_id',0,['intval','abs']);
|
|
|
37
|
-
|
27
|
+ private function getFolderIds($email_id){
|
38
|
$folder_ids = app()->request('folder_ids',[],['intval','abs']);
|
28
|
$folder_ids = app()->request('folder_ids',[],['intval','abs']);
|
39
|
|
29
|
|
40
|
- $udate = app()->request('udate',0,'intval');
|
|
|
41
|
-
|
|
|
42
|
- $where = ['email_id' => $this->getEmail('id')];
|
|
|
43
|
-
|
|
|
44
|
foreach ($folder_ids as $k=>$folder_id){
|
30
|
foreach ($folder_ids as $k=>$folder_id){
|
45
|
if(!$folder_id){
|
31
|
if(!$folder_id){
|
46
|
unset($folder_ids[$k]);
|
32
|
unset($folder_ids[$k]);
|
|
@@ -55,12 +41,34 @@ class Home extends Base { |
|
@@ -55,12 +41,34 @@ class Home extends Base { |
55
|
sprintf(
|
41
|
sprintf(
|
56
|
"select `id` from `%s` where `email_id` = %d and `origin_folder` = 'INBOX'",
|
42
|
"select `id` from `%s` where `email_id` = %d and `origin_folder` = 'INBOX'",
|
57
|
folderSql::$table
|
43
|
folderSql::$table
|
58
|
- ,$where['email_id']
|
44
|
+ ,$email_id
|
59
|
)
|
45
|
)
|
60
|
);
|
46
|
);
|
|
|
47
|
+
|
|
|
48
|
+ $folder_ids = [$folder_ids];
|
|
|
49
|
+ }
|
|
|
50
|
+
|
|
|
51
|
+ return $folder_ids;
|
61
|
}
|
52
|
}
|
|
|
53
|
+
|
|
|
54
|
+
|
|
|
55
|
+ /**
|
|
|
56
|
+ * 邮件列表 针对aicc应用那边
|
|
|
57
|
+ * @author:dc
|
|
|
58
|
+ * @time 2023/2/17 14:12
|
|
|
59
|
+ */
|
|
|
60
|
+ public function lists(){
|
|
|
61
|
+
|
|
|
62
|
+ $limit = app()->request('limit',20,['intval','abs']);
|
|
|
63
|
+
|
|
|
64
|
+ $last_id = app()->request('last_id',0,['intval','abs']);
|
|
|
65
|
+
|
|
|
66
|
+ $udate = app()->request('udate',0,'intval');
|
|
|
67
|
+
|
|
|
68
|
+ $where = ['email_id' => $this->getEmail('id')];
|
|
|
69
|
+
|
62
|
//目录
|
70
|
//目录
|
63
|
- $where['folder_id'] = $folder_ids;
|
71
|
+ $where['folder_id'] = $this->getFolderIds($where['email_id']);
|
64
|
|
72
|
|
65
|
|
73
|
|
66
|
$sql = "`id` > ".$last_id;
|
74
|
$sql = "`id` > ".$last_id;
|
|
@@ -83,6 +91,79 @@ class Home extends Base { |
|
@@ -83,6 +91,79 @@ class Home extends Base { |
83
|
}
|
91
|
}
|
84
|
|
92
|
|
85
|
|
93
|
|
|
|
94
|
+ /**
|
|
|
95
|
+ * v2 版本
|
|
|
96
|
+ * 同步规定 时间 之后的邮件
|
|
|
97
|
+ * @return string
|
|
|
98
|
+ * @throws \Lib\Err
|
|
|
99
|
+ * @author:dc
|
|
|
100
|
+ * @time 2023/8/2 16:19
|
|
|
101
|
+ */
|
|
|
102
|
+ public function sync(){
|
|
|
103
|
+ $emails = web_request_emails();
|
|
|
104
|
+ $udate = app()->request('udate',0,'intval');
|
|
|
105
|
+ if(!$udate){
|
|
|
106
|
+ return '';
|
|
|
107
|
+ }
|
|
|
108
|
+
|
|
|
109
|
+ // 查询邮箱
|
|
|
110
|
+ $emails = db()->all(emailSql::all(dbWhere(['email'=>$emails])));
|
|
|
111
|
+ if(!$emails){
|
|
|
112
|
+ return '';
|
|
|
113
|
+ }
|
|
|
114
|
+
|
|
|
115
|
+ // 启用协程来处理
|
|
|
116
|
+ run(function () use ($emails,$udate){
|
|
|
117
|
+ foreach ($emails as $email){
|
|
|
118
|
+ // 读取文件夹
|
|
|
119
|
+ $fids = $this->getFolderIds($email['id']);
|
|
|
120
|
+ $folders = db()->all(folderSql::all($email['id']));
|
|
|
121
|
+ // 循环 文件夹
|
|
|
122
|
+ foreach ($folders as $folder){
|
|
|
123
|
+ // 是否在同步请求中
|
|
|
124
|
+ if(in_array($folder['id'],$fids)){
|
|
|
125
|
+ // 启动 协程
|
|
|
126
|
+ go(function () use ($email,$udate,$folder){
|
|
|
127
|
+ // 实例一个邮箱对象
|
|
|
128
|
+ $mail = new Mail($email['email'],base64_decode($email['password']),$email['imap']);
|
|
|
129
|
+ // 登录
|
|
|
130
|
+ $mail->login();
|
|
|
131
|
+ // 选择 文件夹
|
|
|
132
|
+ $mail->client->selectFolder($folder['origin_folder']);
|
|
|
133
|
+ // 最后的时间
|
|
|
134
|
+ $maxudate = db()->value(
|
|
|
135
|
+ sprintf(
|
|
|
136
|
+ "select max(`udate`) from `%s` where `email_id` = %d and `folder_id` = %d limit 1",
|
|
|
137
|
+ listsSql::$table,
|
|
|
138
|
+ $email['id'],
|
|
|
139
|
+ $folder['id']
|
|
|
140
|
+ )
|
|
|
141
|
+ );
|
|
|
142
|
+ $udate = $udate > $maxudate ? $udate : $maxudate;
|
|
|
143
|
+
|
|
|
144
|
+ // 通过时间来搜索uid
|
|
|
145
|
+ $uids = $mail->client->search(['ON'=>date('Y-m-d H:i:s',$udate)]);
|
|
|
146
|
+ // 进行同步
|
|
|
147
|
+ $mail->syncUidEmail(
|
|
|
148
|
+ $uids,
|
|
|
149
|
+ $email['id'],
|
|
|
150
|
+ $folder['origin_folder'],
|
|
|
151
|
+ $folder['id'],
|
|
|
152
|
+ [],
|
|
|
153
|
+ [],
|
|
|
154
|
+ db()
|
|
|
155
|
+ );
|
|
|
156
|
+
|
|
|
157
|
+ });
|
|
|
158
|
+ }
|
|
|
159
|
+ }
|
|
|
160
|
+
|
|
|
161
|
+ }
|
|
|
162
|
+
|
|
|
163
|
+ });
|
|
|
164
|
+
|
|
|
165
|
+ }
|
|
|
166
|
+
|
86
|
}
|
167
|
}
|
87
|
|
168
|
|
88
|
|
169
|
|