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