1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dacastro4\LaravelGmail\Traits; |
4
|
|
|
|
5
|
|
|
use Dacastro4\LaravelGmail\Services\Message; |
6
|
|
|
|
7
|
|
|
trait Filterable |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Filter to get only unread emalis |
11
|
|
|
* |
12
|
|
|
* @return self|Message |
13
|
|
|
*/ |
14
|
|
|
public function unread() |
15
|
|
|
{ |
16
|
|
|
$this->add('is:unread'); |
17
|
|
|
|
18
|
|
|
return $this; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public abstract function add($query, $column = 'q', $encode = true); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Filter to get only unread emalis |
25
|
|
|
* |
26
|
|
|
* @param $query |
27
|
|
|
* |
28
|
|
|
* @return self|Message |
29
|
|
|
*/ |
30
|
|
|
public function subject($query) |
31
|
|
|
{ |
32
|
|
|
$this->add("[{$query}]"); |
33
|
|
|
|
34
|
|
|
return $this; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Filter to get only emails from a specific email address |
39
|
|
|
* |
40
|
|
|
* @param $email |
41
|
|
|
* |
42
|
|
|
* @return self|Message |
43
|
|
|
*/ |
44
|
|
|
public function to($email) |
45
|
|
|
{ |
46
|
|
|
$this->add("to:{$email}"); |
47
|
|
|
|
48
|
|
|
return $this; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* add an array of from addresses |
53
|
|
|
* |
54
|
|
|
* @param $emails |
55
|
|
|
* |
56
|
|
|
* @return self|Message |
57
|
|
|
*/ |
58
|
|
|
public function fromThese(array $emails) |
59
|
|
|
{ |
60
|
|
|
$emailsCount = count($emails); |
61
|
|
|
for ($i = 0; $i < $emailsCount; $i++) { |
62
|
|
|
!$i ? $this->add("{from:$emails[$i]") : ($i == $emailsCount - 1 ? $this->add("from:$emails[$i]}") : $this->from($emails[$i])); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Filter to get only emails from a specific email address |
70
|
|
|
* |
71
|
|
|
* @param $email |
72
|
|
|
* |
73
|
|
|
* @return self|Message |
74
|
|
|
*/ |
75
|
|
|
public function from($email) |
76
|
|
|
{ |
77
|
|
|
$this->add("from:{$email}"); |
78
|
|
|
|
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Filter to get only emails after a specific date |
84
|
|
|
* |
85
|
|
|
* @param $date |
86
|
|
|
* |
87
|
|
|
* @return self|Message |
88
|
|
|
*/ |
89
|
|
|
public function after($date) |
90
|
|
|
{ |
91
|
|
|
$this->add("after:{$date}"); |
92
|
|
|
|
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Filter to get only emails before a specific date |
98
|
|
|
* |
99
|
|
|
* @param $date |
100
|
|
|
* |
101
|
|
|
* @return self|Message |
102
|
|
|
*/ |
103
|
|
|
public function before($date) |
104
|
|
|
{ |
105
|
|
|
$this->add("before:{$date}"); |
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Filter by a Gmail raw query |
112
|
|
|
* Label should be the last thing to put in the raw query |
113
|
|
|
* |
114
|
|
|
* @param $query |
115
|
|
|
* |
116
|
|
|
* @return self|Message |
117
|
|
|
*/ |
118
|
|
|
public function raw($query) |
119
|
|
|
{ |
120
|
|
|
$this->add($query, 'q', false); |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Filters emails by tag |
127
|
|
|
* Example: |
128
|
|
|
* * starred |
129
|
|
|
* * inbox |
130
|
|
|
* * spam |
131
|
|
|
* * chats |
132
|
|
|
* * sent |
133
|
|
|
* * draft |
134
|
|
|
* * trash |
135
|
|
|
* |
136
|
|
|
* @param $box |
137
|
|
|
* |
138
|
|
|
* @return self|Message |
139
|
|
|
*/ |
140
|
|
|
public function in($box = 'inbox') |
141
|
|
|
{ |
142
|
|
|
$this->add("in:{$box}"); |
143
|
|
|
|
144
|
|
|
return $this; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Determines if the email has attachments |
149
|
|
|
* |
150
|
|
|
* @return self|Message |
151
|
|
|
*/ |
152
|
|
|
public function hasAttachment() |
153
|
|
|
{ |
154
|
|
|
$this->add('has:attachment'); |
155
|
|
|
|
156
|
|
|
return $this; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|