88
99class Emails extends MsGraph
1010{
11- public function folders (): Folders
12- {
13- return new Folders ;
14- }
11+ private ?bool $ delta = null ;
1512
1613 private string $ top = '' ;
1714
1815 private string $ skip = '' ;
1916
17+ private string $ search = '' ;
18+
2019 private string $ subject = '' ;
2120
2221 private string $ body = '' ;
@@ -91,6 +90,11 @@ public function attachments(array $attachments): static
9190 return $ this ;
9291 }
9392
93+ public function folders (): Folders
94+ {
95+ return new Folders ;
96+ }
97+
9498 public function singleValueExtendedProperties (array $ singleValueExtendedProperties ): static
9599 {
96100 $ this ->singleValueExtendedProperties = $ singleValueExtendedProperties ;
@@ -112,6 +116,13 @@ public function skip(string $skip): static
112116 return $ this ;
113117 }
114118
119+ public function delta (?bool $ delta = true ): static
120+ {
121+ $ this ->delta = $ delta ;
122+
123+ return $ this ;
124+ }
125+
115126 /**
116127 * @throws Exception
117128 */
@@ -121,6 +132,11 @@ public function get(string $folderIdOrName = 'Inbox', array $params = []): array
121132
122133 $ top = request ('top ' , $ this ->top );
123134 $ 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+ }
124140
125141 if ($ top === '' ) {
126142 $ top = 25 ;
@@ -138,16 +154,28 @@ public function get(string $folderIdOrName = 'Inbox', array $params = []): array
138154 ];
139155 }
140156
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') " );
146161
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+ }
151179 }
152180 }
153181
0 commit comments