ImapSearch.php
5.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
<?php
namespace Lib\Imap;
/**
* 搜索邮箱
* TODO:: 有些邮箱服务器并不支持搜索 或者 某些字段搜索
* 日期类搜索是没问题的
* @author:dc
* @time 2024/9/14 15:48
* Class ImapSearch
* @package Lib\Imap
*/
class ImapSearch {
/**
* @var array
*/
protected array $where = [];
/**
* 搜索已标记为 已回复 的邮件
* @param bool $a 是否已标记为 已回复
* @return $this
* @author:dc
* @time 2024/9/14 16:22
*/
public function answered(bool $a = true):static {
$this->where[$a?'ANSWERED':'UNANSWERED'] = true;
return $this;
}
/**
* 搜索已标记为删除的
* Messages with the \Deleted flag set.
* @param bool $del 是否已删除的
* @return $this
* @author:dc
* @time 2024/9/14 16:21
*/
public function deleted(bool $del = true):static {
$this->where[$del?'DELETED':'UNDELETED'] = true;
return $this;
}
/**
* 搜索标记为草稿的
* Messages with the \Draft flag set.
* @param bool $draft 是否是草稿
* @return $this
* @author:dc
* @time 2024/9/14 16:20
*/
public function draft(bool $draft = true):static {
$this->where[$draft?'DRAFT':'UNDRAFT'] = true;
return $this;
}
/**
* 搜索标记为星标的邮件
* @param bool $flagged 是否带星标
* @return $this
* @author:dc
* @time 2024/9/14 16:19
*/
public function flagged(bool $flagged = true):static {
$this->where[$flagged?'FLAGGED':'UNFLAGGED'] = true;
return $this;
}
/**
* 搜索未读 还是已读
* @param bool $seen 是否标记为已读
* @return $this
* @author:dc
* @time 2024/9/14 16:23
*/
public function seen(bool $seen = true):static {
$this->where[$seen?'SEEN':'UNSEEN'] = true;
return $this;
}
/**
* 搜索密送 中有这个邮箱的
* @param string $bcc 邮箱
* @return $this
* @author:dc
* @time 2024/9/14 15:57
*/
public function bcc(string $bcc):static {
$this->where['BCC'] = $bcc;
return $this;
}
/**
* 搜索抄送 中有这个邮箱的
* Messages that contain the specified string in the envelope structure's CC field.
* @param string $cc 邮箱
* @return $this
* @author:dc
* @time 2024/9/14 16:06
*/
public function cc(string $cc):static {
$this->where['CC'] = $cc;
return $this;
}
/**
* 搜索 发件人
* @param string $from
* @return $this
* @author:dc
* @time 2024/9/14 16:10
*/
public function from(string $from):static {
$this->where['FROM'] = $from;
return $this;
}
/**
* 搜索收件人
* @param string $to
* @return $this
* @author:dc
* @time 2024/9/14 16:17
*/
public function to(string $to):static {
$this->where['TO'] = $to;
return $this;
}
/**
* 搜索内容
* Messages that contain the specified string in the body of the message.
* @param string $body
* @return $this
* @author:dc
* @time 2024/9/14 16:05
*/
public function body(string $body):static {
$this->where['BODY'] = $body;
return $this;
}
/**
* 搜索 日期 小于某个日期的
* Messages whose internal date (disregarding time and timezone) is earlier than the specified date.
* @param string $date 日期
* @author:dc
* @time 2024/9/14 16:03
*/
public function dateLt(string $date):static{
$this->where['BEFORE'] = date('d-M-Y',strtotime($date));
return $this;
}
/**
* 搜索指定日期的邮件
* Messages whose internal date (disregarding time and timezone) is within the specified date.
* @param string $date
* @author:dc
* @time 2024/9/14 16:12
*/
public function date(string $date):static{
$this->where['ON'] = date('d-M-Y',strtotime($date));
return $this;
}
/**
* 搜索指定日期后的邮件 如 2024-04-04 显示这个日期过后的
* Messages whose internal date (disregarding time and timezone) is within or later than the specified date.
* @param string $date
* @author:dc
* @time 2024/9/14 16:14
*/
public function dateGt(string $date):static{
$this->where['SINCE'] = date('d-M-Y',strtotime($date));
return $this;
}
/**
* 模糊搜索主题
* @param string $subject 主题
* @author:dc
* @time 2024/9/14 16:16
*/
public function subject(string $subject):static {
$this->where['SUBJECT'] = $subject;
return $this;
}
/**
* 返回搜索字符串
* @author:dc
* @time 2024/9/14 16:27
*/
public function toString():string {
$arr = [];
foreach ($this->where as $k=>$v){
if(is_bool($v)){
$arr[] = $k;
}else{
$arr[] = $k.' "'.addcslashes($v,'"').'"';
}
}
return implode(' ',$arr);
}
}