Skip to content

Commit

Permalink
Merge pull request #82 from giesencoffeeroasters/master
Browse files Browse the repository at this point in the history
feat: Add support for retrieving emails with singleValueExtendedProperties
  • Loading branch information
dcblogdev authored Nov 14, 2024
2 parents ed93cb1 + 29ccce8 commit be0aea9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
28 changes: 24 additions & 4 deletions docs/v3/msgraph/emails.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ To view an email call **->find($id)** followed by the id of the email.
MsGraph::emails()->find($id);
```

Retrieve the emails using singleValueExtendedProperties.

```php
MsGraph::emails()->get([
'\$filter' => 'singleValueExtendedProperties/Any(ep: ep/id eq \'String {00020329-0000-0000-C000-000000000046} Name CustomProperty\' and ep/value eq \'CustomValue\')'
]);
```

## Send Email

To send an email the format is different to normal calls. The format is to call multiple methods to set the email properties.
Expand Down Expand Up @@ -172,6 +180,22 @@ MsGraph::emails()
->send()
```

singleValueExtendedProperties() can be used to add custom properties to the email.

```php
MsGraph::emails()
->to(['email@domains.com'])
->subject('the subject')
->body('the content')
->singleValueExtendedProperties([
[
"id" => "String {00020329-0000-0000-C000-000000000046} Name CustomProperty",
"value" => "CustomValue"
]
])
->send()
```

## Forward Email

To forward to an email call **->forward()** and use **->comment()** instead of **->body()**.
Expand Down Expand Up @@ -205,7 +229,3 @@ To delete an email call **->delete($id)** followed by the id of the email.
```php
MsGraph::emails()->delete($id);
```




34 changes: 30 additions & 4 deletions src/Resources/Emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Emails extends MsGraph

private array $attachments = [];

private array $singleValueExtendedProperties = [];

public function id(string $id): static
{
$this->id = $id;
Expand Down Expand Up @@ -83,6 +85,13 @@ public function attachments(array $attachments): static
return $this;
}

public function singleValueExtendedProperties(array $singleValueExtendedProperties): static
{
$this->singleValueExtendedProperties = $singleValueExtendedProperties;

return $this;
}

public function top(string $top): static
{
$this->top = $top;
Expand Down Expand Up @@ -246,6 +255,7 @@ protected function prepareEmail(): array
$cc = $this->cc;
$bcc = $this->bcc;
$attachments = $this->attachments;
$singleValueExtendedProperties = $this->singleValueExtendedProperties;

$toArray = [];
foreach ($to as $email) {
Expand All @@ -264,14 +274,30 @@ protected function prepareEmail(): array

$attachmentArray = [];
foreach ($attachments as $file) {
if (array_key_exists('name', $file) && array_key_exists('contentBytes', $file)) {
$attachmentArray[] = [
'@odata.type' => '#microsoft.graph.fileAttachment',
'name' => $file['name'],
'contentBytes' => $file['contentBytes'],
];
} else {
$path = pathinfo($file);

$attachmentArray[] = [
'@odata.type' => '#microsoft.graph.fileAttachment',
'name' => $path['basename'],
'contentType' => mime_content_type($file),
'contentBytes' => base64_encode(file_get_contents($file)),
'@odata.type' => '#microsoft.graph.fileAttachment',
'name' => $path['basename'],
'contentType' => mime_content_type($file),
'contentBytes' => base64_encode(file_get_contents($file)),
];
}
}

$singleValueExtendedPropertiesarray = [];
foreach ($singleValueExtendedProperties as $value) {
$singleValueExtendedPropertiesarray[] = [
'id' => $value['id'],
'value' => $value['value'],
];
}

$envelope = [];
Expand Down

0 comments on commit be0aea9

Please sign in to comment.