From eb8fe60933a4e9efa18e0d52dcfbe285e798f0c2 Mon Sep 17 00:00:00 2001 From: meckyp Date: Wed, 31 Jul 2024 10:59:29 +0200 Subject: [PATCH 1/3] feat: Add support for retrieving emails with singleValueExtendedProperties --- docs/v3/msgraph/emails.md | 28 ++++++++++++++++++++++++---- src/Resources/Emails.php | 11 +++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/docs/v3/msgraph/emails.md b/docs/v3/msgraph/emails.md index 0c0837d..d30085b 100644 --- a/docs/v3/msgraph/emails.md +++ b/docs/v3/msgraph/emails.md @@ -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. @@ -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()**. @@ -205,7 +229,3 @@ To delete an email call **->delete($id)** followed by the id of the email. ```php MsGraph::emails()->delete($id); ``` - - - - diff --git a/src/Resources/Emails.php b/src/Resources/Emails.php index 860977d..dcee2f4 100644 --- a/src/Resources/Emails.php +++ b/src/Resources/Emails.php @@ -27,6 +27,8 @@ class Emails extends MsGraph private array $attachments = []; + private array $singleValueExtendedProperties = []; + public function id(string $id): static { $this->id = $id; @@ -246,6 +248,7 @@ protected function prepareEmail(): array $cc = $this->cc; $bcc = $this->bcc; $attachments = $this->attachments; + $singleValueExtendedProperties = $this->singleValueExtendedProperties; $toArray = []; foreach ($to as $email) { @@ -274,6 +277,14 @@ protected function prepareEmail(): array ]; } + $singleValueExtendedPropertiesarray = []; + foreach ($singleValueExtendedProperties as $value) { + $singleValueExtendedPropertiesarray[] = [ + 'id' => $value['id'], + 'value' => $value['value'], + ]; + } + $envelope = []; if ($subject !== '') { $envelope['message']['subject'] = $subject; From 4451605187fbbd971d7377f7b89d3c6e8777b9b4 Mon Sep 17 00:00:00 2001 From: meckyp Date: Thu, 1 Aug 2024 10:36:59 +0200 Subject: [PATCH 2/3] feat: Add singleValueExtendedProperties method to Emails class --- src/Resources/Emails.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Resources/Emails.php b/src/Resources/Emails.php index dcee2f4..19e9b75 100644 --- a/src/Resources/Emails.php +++ b/src/Resources/Emails.php @@ -85,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; From 29ccce8414dd2644fe9de554fa5c41a1b48bc803 Mon Sep 17 00:00:00 2001 From: meckyp Date: Thu, 1 Aug 2024 11:04:30 +0200 Subject: [PATCH 3/3] Update Emails.php --- src/Resources/Emails.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Resources/Emails.php b/src/Resources/Emails.php index 19e9b75..b854ed9 100644 --- a/src/Resources/Emails.php +++ b/src/Resources/Emails.php @@ -274,14 +274,22 @@ 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 = [];