-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathFilterable.php
158 lines (135 loc) · 2.32 KB
/
Filterable.php
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
<?php
namespace Dacastro4\LaravelGmail\Traits;
use Dacastro4\LaravelGmail\Services\Message;
trait Filterable
{
/**
* Filter to get only unread emalis
*
* @return self|Message
*/
public function unread()
{
$this->add('is:unread');
return $this;
}
public abstract function add($query, $column = 'q', $encode = true);
/**
* Filter to get only unread emalis
*
* @param $query
*
* @return self|Message
*/
public function subject($query)
{
$this->add("[{$query}]");
return $this;
}
/**
* Filter to get only emails from a specific email address
*
* @param $email
*
* @return self|Message
*/
public function to($email)
{
$this->add("to:{$email}");
return $this;
}
/**
* add an array of from addresses
*
* @param $emails
*
* @return self|Message
*/
public function fromThese(array $emails)
{
$emailsCount = count($emails);
for ($i = 0; $i < $emailsCount; $i++) {
!$i ? $this->add("{from:$emails[$i]") : ($i == $emailsCount - 1 ? $this->add("from:$emails[$i]}") : $this->from($emails[$i]));
}
return $this;
}
/**
* Filter to get only emails from a specific email address
*
* @param $email
*
* @return self|Message
*/
public function from($email)
{
$this->add("from:{$email}");
return $this;
}
/**
* Filter to get only emails after a specific date
*
* @param $date
*
* @return self|Message
*/
public function after($date)
{
$this->add("after:{$date}");
return $this;
}
/**
* Filter to get only emails before a specific date
*
* @param $date
*
* @return self|Message
*/
public function before($date)
{
$this->add("before:{$date}");
return $this;
}
/**
* Filter by a Gmail raw query
* Label should be the last thing to put in the raw query
*
* @param $query
*
* @return self|Message
*/
public function raw($query)
{
$this->add($query, 'q', false);
return $this;
}
/**
* Filters emails by tag
* Example:
* * starred
* * inbox
* * spam
* * chats
* * sent
* * draft
* * trash
*
* @param $box
*
* @return self|Message
*/
public function in($box = 'inbox')
{
$this->add("in:{$box}");
return $this;
}
/**
* Determines if the email has attachments
*
* @return self|Message
*/
public function hasAttachment()
{
$this->add('has:attachment');
return $this;
}
}