@@ -9,9 +9,9 @@ class Emails extends MsGraphAdmin
99{
1010 private string $ userId = '' ;
1111
12- private string $ top = '' ;
12+ private string $ top = '100 ' ;
1313
14- private string $ skip = '' ;
14+ private string $ skip = '0 ' ;
1515
1616 private string $ subject = '' ;
1717
@@ -129,9 +129,13 @@ public function get(array $params = []): array
129129 $ params = http_build_query ($ params );
130130 }
131131
132- //get messages from folderId
132+ // get messages from folderId
133133 $ emails = MsGraphAdmin::get ('users/ ' .$ this ->userId .'/messages? ' .$ params );
134134
135+ if (isset ($ emails ->error )) {
136+ throw new Exception ("Graph API Error, code: {$ emails ->error ->code }, Message: {$ emails ->error ->message }" );
137+ }
138+
135139 $ data = MsGraphAdmin::getPagination ($ emails , $ top , $ skip );
136140
137141 return [
@@ -163,21 +167,21 @@ public function findInlineAttachments(array $email): array
163167 {
164168 $ attachments = self ::findAttachments ($ email ['id ' ]);
165169
166- //replace every case of <img='cid:' with the base64 image
170+ // replace every case of <img='cid:' with the base64 image
167171 $ email ['body ' ]['content ' ] = preg_replace_callback (
168172 '~cid.*?"~ ' ,
169173 function (array $ m ) use ($ attachments ) {
170- //remove the last quote
174+ // remove the last quote
171175 $ parts = explode ('" ' , $ m [0 ]);
172176
173- //remove cid:
177+ // remove cid:
174178 $ contentId = str_replace ('cid: ' , '' , $ parts [0 ]);
175179
176- //loop over the attachments
180+ // loop over the attachments
177181 foreach ($ attachments ['value ' ] as $ file ) {
178- //if there is a match
182+ // if there is a match
179183 if ($ file ['contentId ' ] == $ contentId ) {
180- //return a base64 image with a quote
184+ // return a base64 image with a quote
181185 return 'data: ' .$ file ['contentType ' ].';base64, ' .$ file ['contentBytes ' ].'" ' ;
182186 }
183187 }
@@ -217,7 +221,7 @@ public function send(): void
217221 /**
218222 * @throws Exception
219223 */
220- public function reply ()
224+ public function reply (): MsGraphAdmin
221225 {
222226 if (strlen ($ this ->userId ) === 0 ) {
223227 throw new Exception ('userId is required. ' );
@@ -237,7 +241,7 @@ public function reply()
237241 /**
238242 * @throws Exception
239243 */
240- public function forward ()
244+ public function forward (): MsGraphAdmin
241245 {
242246 if (strlen ($ this ->userId ) === 0 ) {
243247 throw new Exception ('userId is required. ' );
@@ -257,7 +261,7 @@ public function forward()
257261 /**
258262 * @throws Exception
259263 */
260- public function delete (string $ id )
264+ public function delete (string $ id ): MsGraphAdmin
261265 {
262266 if ($ this ->userId == null ) {
263267 throw new Exception ('userId is required. ' );
@@ -297,12 +301,12 @@ protected function prepareEmail(): array
297301 }
298302 }
299303
300- $ attachmentarray = [];
304+ $ attachmentArray = [];
301305 if ($ attachments != null ) {
302306 foreach ($ attachments as $ file ) {
303307 $ path = pathinfo ($ file );
304308
305- $ attachmentarray [] = [
309+ $ attachmentArray [] = [
306310 '@odata.type ' => '#microsoft.graph.fileAttachment ' ,
307311 'name ' => $ path ['basename ' ],
308312 'contentType ' => mime_content_type ($ file ),
@@ -330,8 +334,8 @@ protected function prepareEmail(): array
330334 if ($ bccArray != null ) {
331335 $ envelope ['message ' ]['bccRecipients ' ] = $ bccArray ;
332336 }
333- if ($ attachmentarray != null ) {
334- $ envelope ['message ' ]['attachments ' ] = $ attachmentarray ;
337+ if ($ attachmentArray != null ) {
338+ $ envelope ['message ' ]['attachments ' ] = $ attachmentArray ;
335339 }
336340 if ($ comment != null ) {
337341 $ envelope ['comment ' ] = $ comment ;
0 commit comments