7
7
8
8
class Emails extends MsGraph
9
9
{
10
+ private ?bool $ delta = null ;
11
+
10
12
private string $ top = '' ;
11
13
12
14
private string $ skip = '' ;
13
15
16
+ private string $ search = '' ;
17
+
14
18
private string $ subject = '' ;
15
19
16
20
private string $ body = '' ;
@@ -97,13 +101,25 @@ public function skip(string $skip): static
97
101
return $ this ;
98
102
}
99
103
104
+ public function delta (?bool $ delta = true ): static
105
+ {
106
+ $ this ->delta = $ delta ;
107
+
108
+ return $ this ;
109
+ }
110
+
100
111
/**
101
112
* @throws Exception
102
113
*/
103
114
public function get (string $ folderId = '' , array $ params = []): MsGraph
104
115
{
105
116
$ top = request ('top ' , $ this ->top );
106
117
$ skip = request ('skip ' , $ this ->skip );
118
+ $ search = request ('search ' , $ this ->search );
119
+
120
+ if (filled ($ search ) && $ this ->delta ) {
121
+ throw new Exception ('Search is not supported in delta queries. ' );
122
+ }
107
123
108
124
if ($ top === null ) {
109
125
$ top = 100 ;
@@ -125,15 +141,16 @@ public function get(string $folderId = '', array $params = []): MsGraph
125
141
126
142
$ folder = $ folderId == '' ? 'Inbox ' : $ folderId ;
127
143
128
- //get inbox from folders list
144
+ // get inbox from folders list
129
145
$ folder = MsGraph::get ("me/mailFolders? \$filter=startswith(displayName,' $ folder') " );
130
146
131
147
if (isset ($ folder ['value ' ][0 ])) {
132
- //folder id
148
+ // folder id
133
149
$ folderId = $ folder ['value ' ][0 ]['id ' ];
150
+ $ messages = $ this ->delta ? 'messages/delta ' : 'messages ' ;
134
151
135
- //get messages from folderId
136
- return MsGraph::get ("me/mailFolders/ $ folderId/messages? " .$ params );
152
+ // get messages from folderId
153
+ return MsGraph::get ("me/mailFolders/ $ folderId/ $ messages? " .$ params );
137
154
} else {
138
155
throw new Exception ('email folder not found ' );
139
156
}
@@ -153,21 +170,21 @@ public function findInlineAttachments(array $email): array
153
170
{
154
171
$ attachments = self ::findAttachments ($ email ['id ' ]);
155
172
156
- //replace every case of <img='cid:' with the base64 image
173
+ // replace every case of <img='cid:' with the base64 image
157
174
$ email ['body ' ]['content ' ] = preg_replace_callback (
158
175
'~cid.*?"~ ' ,
159
176
function (array $ m ) use ($ attachments ) {
160
- //remove the last quote
177
+ // remove the last quote
161
178
$ parts = explode ('" ' , $ m [0 ]);
162
179
163
- //remove cid:
180
+ // remove cid:
164
181
$ contentId = str_replace ('cid: ' , '' , $ parts [0 ]);
165
182
166
- //loop over the attachments
183
+ // loop over the attachments
167
184
foreach ($ attachments ['value ' ] as $ file ) {
168
- //if there is a match
185
+ // if there is a match
169
186
if ($ file ['contentId ' ] == $ contentId ) {
170
- //return a base64 image with a quote
187
+ // return a base64 image with a quote
171
188
return 'data: ' .$ file ['contentType ' ].';base64, ' .$ file ['contentBytes ' ].'" ' ;
172
189
}
173
190
}
0 commit comments