Skip to content

Commit aef69b1

Browse files
committed
Add email messages delta
1 parent e129c9d commit aef69b1

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

src/Resources/Emails.php

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77

88
class Emails extends MsGraph
99
{
10+
private ?bool $delta = null;
11+
1012
private string $top = '';
1113

1214
private string $skip = '';
1315

16+
private string $search = '';
17+
1418
private string $subject = '';
1519

1620
private string $body = '';
@@ -97,13 +101,25 @@ public function skip(string $skip): static
97101
return $this;
98102
}
99103

104+
public function delta(?bool $delta = true): static
105+
{
106+
$this->delta = $delta;
107+
108+
return $this;
109+
}
110+
100111
/**
101112
* @throws Exception
102113
*/
103114
public function get(string $folderId = '', array $params = []): MsGraph
104115
{
105116
$top = request('top', $this->top);
106117
$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+
}
107123

108124
if ($top === null) {
109125
$top = 100;
@@ -125,15 +141,16 @@ public function get(string $folderId = '', array $params = []): MsGraph
125141

126142
$folder = $folderId == '' ? 'Inbox' : $folderId;
127143

128-
//get inbox from folders list
144+
// get inbox from folders list
129145
$folder = MsGraph::get("me/mailFolders?\$filter=startswith(displayName,'$folder')");
130146

131147
if (isset($folder['value'][0])) {
132-
//folder id
148+
// folder id
133149
$folderId = $folder['value'][0]['id'];
150+
$messages = $this->delta ? 'messages/delta' : 'messages';
134151

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);
137154
} else {
138155
throw new Exception('email folder not found');
139156
}
@@ -153,21 +170,21 @@ public function findInlineAttachments(array $email): array
153170
{
154171
$attachments = self::findAttachments($email['id']);
155172

156-
//replace every case of <img='cid:' with the base64 image
173+
// replace every case of <img='cid:' with the base64 image
157174
$email['body']['content'] = preg_replace_callback(
158175
'~cid.*?"~',
159176
function (array $m) use ($attachments) {
160-
//remove the last quote
177+
// remove the last quote
161178
$parts = explode('"', $m[0]);
162179

163-
//remove cid:
180+
// remove cid:
164181
$contentId = str_replace('cid:', '', $parts[0]);
165182

166-
//loop over the attachments
183+
// loop over the attachments
167184
foreach ($attachments['value'] as $file) {
168-
//if there is a match
185+
// if there is a match
169186
if ($file['contentId'] == $contentId) {
170-
//return a base64 image with a quote
187+
// return a base64 image with a quote
171188
return 'data:'.$file['contentType'].';base64,'.$file['contentBytes'].'"';
172189
}
173190
}

0 commit comments

Comments
 (0)