8
8
9
9
class Emails extends MsGraph
10
10
{
11
- public function folders (): Folders
12
- {
13
- return new Folders ;
14
- }
11
+ private ?bool $ delta = null ;
15
12
16
13
private string $ top = '' ;
17
14
18
15
private string $ skip = '' ;
19
16
17
+ private string $ search = '' ;
18
+
20
19
private string $ subject = '' ;
21
20
22
21
private string $ body = '' ;
@@ -91,6 +90,11 @@ public function attachments(array $attachments): static
91
90
return $ this ;
92
91
}
93
92
93
+ public function folders (): Folders
94
+ {
95
+ return new Folders ;
96
+ }
97
+
94
98
public function singleValueExtendedProperties (array $ singleValueExtendedProperties ): static
95
99
{
96
100
$ this ->singleValueExtendedProperties = $ singleValueExtendedProperties ;
@@ -112,6 +116,13 @@ public function skip(string $skip): static
112
116
return $ this ;
113
117
}
114
118
119
+ public function delta (?bool $ delta = true ): static
120
+ {
121
+ $ this ->delta = $ delta ;
122
+
123
+ return $ this ;
124
+ }
125
+
115
126
/**
116
127
* @throws Exception
117
128
*/
@@ -121,6 +132,11 @@ public function get(string $folderIdOrName = 'Inbox', array $params = []): array
121
132
122
133
$ top = request ('top ' , $ this ->top );
123
134
$ skip = request ('skip ' , $ this ->skip );
135
+ $ search = request ('search ' , $ this ->search );
136
+
137
+ if (filled ($ search ) && $ this ->delta ) {
138
+ throw new Exception ('Search is not supported in delta queries. ' );
139
+ }
124
140
125
141
if ($ top === '' ) {
126
142
$ top = 25 ;
@@ -138,16 +154,28 @@ public function get(string $folderIdOrName = 'Inbox', array $params = []): array
138
154
];
139
155
}
140
156
141
- if ($ this ->isId ($ folderIdOrName )) {
142
- $ folder = MsGraph::emails ()->folders ()->find ($ folderIdOrName );
143
- } else {
144
- $ folder = MsGraph::emails ()->folders ()->findByName ($ folderIdOrName );
145
- }
157
+ $ folder = $ folderId == '' ? 'Inbox ' : $ folderId ;
158
+
159
+ // get inbox from folders list
160
+ $ folder = MsGraph::get ("me/mailFolders? \$filter=startswith(displayName,' $ folder') " );
146
161
147
- if ($ folder !== []) {
148
- return MsGraph::get ("me/mailFolders/ " .$ folder ['id ' ]."/messages? " .http_build_query ($ params ));
149
- } else {
150
- throw new Exception ('Email folder not found ' );
162
+ if (isset ($ folder ['value ' ][0 ])) {
163
+ // folder id
164
+ $ folderId = $ folder ['value ' ][0 ]['id ' ];
165
+ $ messages = $ this ->delta ? 'messages/delta ' : 'messages ' ;
166
+
167
+ // get messages from folderId
168
+ if ($ this ->isId ($ folderIdOrName )) {
169
+ $ folder = MsGraph::emails ()->folders ()->find ($ folderIdOrName );
170
+ } else {
171
+ $ folder = MsGraph::emails ()->folders ()->findByName ($ folderIdOrName );
172
+ }
173
+
174
+ if ($ folder !== []) {
175
+ return MsGraph::get ('me/mailFolders/ ' .$ folder ['id ' ]."/ {$ messages }? " .http_build_query ($ params ));
176
+ } else {
177
+ throw new Exception ('Email folder not found ' );
178
+ }
151
179
}
152
180
}
153
181
0 commit comments