Skip to content

Commit f412178

Browse files
authored
Merge pull request #103 from dcblogdev/email-methods
added methods
2 parents eb674ad + 1764d83 commit f412178

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

docs/v3/msgraph/emails.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ To view an email call **->find($id)** followed by the id of the email.
136136
MsGraph::emails()->find($id);
137137
```
138138

139+
> From version v4.0.6, mark email as read when viewing it.
140+
141+
```php
142+
MsGraph::emails()->find($id, bool $markAsRead = false);
143+
```
144+
139145
Retrieve the emails using singleValueExtendedProperties.
140146

141147
```php
@@ -144,6 +150,32 @@ MsGraph::emails()->get([
144150
]);
145151
```
146152

153+
## Get Email Attachments
154+
155+
Get email attachments
156+
```php
157+
MsGraph::emails()->findAttachment($id);
158+
```
159+
160+
## Get Email Attachment
161+
162+
Get email attachment by its id
163+
```php
164+
MsGraph::emails()->findAttachment($id, $attachmentId);
165+
```
166+
167+
## Mark email as read
168+
169+
```php
170+
MsGraph::emails()->markAsRead($id);
171+
```
172+
173+
## Mark email as unread
174+
175+
```php
176+
MsGraph::emails()->markAsUnread($id);
177+
```
178+
147179
## Send Email
148180

149181
To send an email the format is different to normal calls. The format is to call multiple methods to set the email properties.

src/Resources/Emails/Emails.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,12 @@ public function get(string $folderIdOrName = 'Inbox', array $params = []): array
151151
}
152152
}
153153

154-
public function find(string $id): array
154+
public function find(string $id, bool $markAsRead = false): array
155155
{
156+
if ($markAsRead) {
157+
self::markAsRead($id);
158+
}
159+
156160
return MsGraph::get('me/messages/'.$id);
157161
}
158162

@@ -161,6 +165,11 @@ public function findAttachments(string $id): array
161165
return MsGraph::get('me/messages/'.$id.'/attachments');
162166
}
163167

168+
public function findAttachment(string $id, string $attachmentId): array
169+
{
170+
return MsGraph::get('me/messages/'.$id.'/attachments/'.$attachmentId);
171+
}
172+
164173
public function findInlineAttachments(array $email): array
165174
{
166175
$attachments = self::findAttachments($email['id']);
@@ -192,6 +201,16 @@ function (array $m) use ($attachments) {
192201
return $email;
193202
}
194203

204+
public function markAsRead(string $id): void
205+
{
206+
MsGraph::patch('me/messages/'.$id, ['isRead' => true]);
207+
}
208+
209+
public function markAsUnread(string $id): void
210+
{
211+
MsGraph::patch('me/messages/'.$id, ['isRead' => false]);
212+
}
213+
195214
/**
196215
* @throws Exception
197216
*/

0 commit comments

Comments
 (0)