MailList.php
6.1 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<?php
namespace Controller\fob_ai;
use Controller\Base;
use Model\folderSql;
/**
* 黑格 fob 那边专用 业务
* 为定制逻辑
* @author:dc
* @time 2024/7/18 11:40
* Class MailList
* @package Controller\fob_ai
*/
class MailList extends Base {
/**
* 邮件列表
* @throws \Lib\Err
* @author:dc
* @time 2024/7/18 11:40
*/
public function lists(){
// 分页 页数
$page = app()->request('page',1,'intval');
$page = $page ? $page : 1;
$limit = app()->request('limit',20,'intval');
$limit = $limit ? $limit : 1;
// 指定id
$ids = app()->request('mail_id');
$ids = is_array($ids) ? $ids : [$ids];
foreach ($ids as $i=>$d){
if(!is_numeric($d)){
unset($ids[$i]);
}
}
// 附件
$attachment = app()->request('attachment',0,'bool_Val');
$deleted = 0;
$where = ['email_id'=>$this->getEmails('id')];
// 目录
$folder = app()->request('folder','收件箱');
// 只允许查询这里文件夹
if(in_array($folder,['收件箱','发件箱','垃圾箱','星标邮件','预热收件箱','预热发件箱']))
// 查询 文件夹
$folderList = db()->all(folderSql::all($where['email_id']));
$folder_id = [];
// 文件夹id
if($folderList){
foreach ($folderList as $item){
if(
// 数组文件夹
(is_array($folder) && in_array($item['folder'],$folder))
|| $item['folder'] == $folder
){
$folder_id[] = $item['id'];
}
}
}
if(!$folder_id){
app()->e('folder_not_fount');
}
//目录
$where['folder_id'] = $folder_id;
if($ids) $where['id'] = $ids;
if(paramHas('attachment')){
$where['is_file'] = $attachment ? 1 : 0; //附件
}
// 软删
$where['deleted'] = $deleted;
// 已读/未读
if(paramHas('seen')){
if(in_array($seen,[0,1])){
$where['seen'] = $seen;
}
}
$where['_'] = [];
// 搜索关键字
$keyword = app()->request('keyword','',['htmlspecialchars','addslashes']);
if($keyword){
$where['_'][] = '`subject` like "%'.$keyword.'%"';
}
// 那个发的
$address = app()->request('address');
if($address){
if(is_array($address)){
// 发贱人
if(Verify::sEmail($address['from']??'')){
$where['from'] = $address['from'];
}
// 收件人
if(Verify::sEmail($address['to']??'')){
$where['_'][] = '`to_name` like "%'.$address.'%"';
}
}else if(Verify::sEmail($address)){
// 收件人/发件人
$where['_'][] = '(`from` = "'.$address.'" or `to_name` like "%'.$address.'%")';
}
}
// from 搜索收件人
if(app()->requestHas('from')){
// 如果是发件箱
if($folder == '发件箱'){
$where['to'] = app()->request('from');
if(!$where['to']){
// 不让查询数据
$where['id'] = 0;
}
}else{
$where['from'] = app()->request('from');
if(!$where['from']){
// 不让查询数据
$where['id'] = 0;
}
}
}
// 回复
if (paramHas('answered')){
$where['answered'] = app()->request('answered',0,'bool_Val')?1:0;
}
// 这个主要是来筛选 是否是自己发送的
$fromto = app()->request('formorto');
if($fromto=='from'){
$where['from'] = $this->getEmails('email');
}elseif ($fromto=='to'){
$where['from.notin'] = $this->getEmails('email');
}
/**
* 不查询哪些发件人的邮件
*/
$form_not_in = app()->request('from_not_in');
if($form_not_in){
$form_not_in = is_array($form_not_in) ? $form_not_in : [$form_not_in];
$form_not_in = array_filter($form_not_in,function ($v){
if(is_string($v) && Verify::sEmail($v)){
return true;
}
return false;
});
if($form_not_in){
if(isset($where['from.notin'])){
$where['from.notin'] = array_merge($where['from.notin'],$form_not_in);
}else{
$where['from.notin'] = $form_not_in;
}
}
}
if(!empty($where['from.notin'])){
$where['from.notin'] = array_unique($where['from.notin']);
}
$lists = db()->all(
listsSql::lists(
dbWhere($where),
$page,
$limit
)
);
// map
$lists = array_map(function ($v){
$v['uuid'] = get_email_uuid($v['subject'],$v['udate'],$v['from'],$v['to'],$v['size']);
if(!empty($v['description'])){
$v['description'] = @html_entity_decode($v['description'], ENT_COMPAT, 'UTF-8');
}
$v['to_name'] = @json_decode($v['to_name'],true);
$v['to_name'] = $v['to_name']?:[];
if($v['to_name']){
if(!empty($v['to_name'][0]['email'])){
$v['to'] = $v['to_name'][0]['email'];
}
$v['to_name'] = $v['to_name'][0]['name']??'';
}
if(is_array($v['to_name'])){
$v['to_name'] = '';
}
return $v;
},$lists);
// 总数
$total = db()->count(
listsSql::listCount(dbWhere($where))
);
app()->_json(listsPage($lists,$total,$page,$limit));
}
}