Skip to content

Commit 1703c71

Browse files
committed
changed emails returns error when mailbox folder not found
1 parent 48b7bb2 commit 1703c71

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/Resources/Emails.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ public function get($folderId = null, $params = [])
9393
$top = request('top', $this->top);
9494
$skip = request('skip', $this->skip);
9595

96+
if ($top === null) {
97+
$top = 100;
98+
}
99+
100+
if ($skip === null) {
101+
$skip = 0;
102+
}
103+
96104
if ($params == []) {
97105
$params = http_build_query([
98106
'$top' => $top,
@@ -108,20 +116,15 @@ public function get($folderId = null, $params = [])
108116
//get inbox from folders list
109117
$folder = MsGraph::get("me/mailFolders?\$filter=startswith(displayName,'$folder')");
110118

111-
//folder id
112-
$folderId = $folder['value'][0]['id'];
119+
if (isset($folder['value'][0])) {
120+
//folder id
121+
$folderId = $folder['value'][0]['id'];
113122

114-
//get messages from folderId
115-
$emails = MsGraph::get("me/mailFolders/$folderId/messages?".$params);
116-
117-
$data = MsGraph::getPagination($emails, $top, $skip);
118-
119-
return [
120-
'emails' => $emails,
121-
'total' => $data['total'],
122-
'top' => $data['top'],
123-
'skip' => $data['skip'],
124-
];
123+
//get messages from folderId
124+
return MsGraph::get("me/mailFolders/$folderId/messages?".$params);
125+
} else {
126+
return throw new Exception('email folder not found');
127+
}
125128
}
126129

127130
public function find($id)

0 commit comments

Comments
 (0)