From 83d4de9f739ee3c46d35f815a482f868c5f782e9 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 6 Dec 2023 14:52:13 +0100 Subject: [PATCH 1/3] support maile template override --- src/Appwrite/Event/Mail.php | 27 ++++++++++++++++++++++++- src/Appwrite/Platform/Workers/Mails.php | 6 +++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Event/Mail.php b/src/Appwrite/Event/Mail.php index c2de8023b0..212cdabb5a 100644 --- a/src/Appwrite/Event/Mail.php +++ b/src/Appwrite/Event/Mail.php @@ -13,6 +13,7 @@ class Mail extends Event protected string $body = ''; protected array $smtp = []; protected array $variables = []; + protected string $bodyTemplate = ''; public function __construct(protected Connection $connection) { @@ -115,6 +116,29 @@ class Mail extends Event return $this->name; } + /** + * Sets bodyTemplate for the mail event. + * + * @param string $bodyTemplate + * @return self + */ + public function setbodyTemplate(string $bodyTemplate): self + { + $this->bodyTemplate = $bodyTemplate; + + return $this; + } + + /** + * Returns subject for the mail event. + * + * @return string + */ + public function getbodyTemplate(): string + { + return $this->bodyTemplate; + } + /** * Set SMTP Host * @@ -327,10 +351,11 @@ class Mail extends Event 'recipient' => $this->recipient, 'name' => $this->name, 'subject' => $this->subject, + 'bodyTemplate' => $this->bodyTemplate, 'body' => $this->body, 'smtp' => $this->smtp, 'variables' => $this->variables, 'events' => Event::generateEvents($this->getEvent(), $this->getParams()) ]); } -} +} \ No newline at end of file diff --git a/src/Appwrite/Platform/Workers/Mails.php b/src/Appwrite/Platform/Workers/Mails.php index 94a2a46087..a6f5b463a3 100644 --- a/src/Appwrite/Platform/Workers/Mails.php +++ b/src/Appwrite/Platform/Workers/Mails.php @@ -59,8 +59,8 @@ class Mails extends Action $variables = $payload['variables']; $name = $payload['name']; $body = $payload['body']; - - $bodyTemplate = Template::fromFile(__DIR__ . '/../../../../app/config/locale/templates/email-base.tpl'); + $bodyTemplate = $payload['bodyTemplate'] ?? __DIR__ . '/../../../../app/config/locale/templates/email-base.tpl'; + $bodyTemplate = Template::fromFile($bodyTemplate); $bodyTemplate->setParam('{{body}}', $body); foreach ($variables as $key => $value) { $bodyTemplate->setParam('{{' . $key . '}}', $value); @@ -131,4 +131,4 @@ class Mails extends Action return $mail; } -} +} \ No newline at end of file From 5c9199f332adf3664e6c4809d78efaf0e4eaf2a9 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 6 Dec 2023 16:16:31 +0100 Subject: [PATCH 2/3] fix empty body template --- src/Appwrite/Platform/Workers/Mails.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Mails.php b/src/Appwrite/Platform/Workers/Mails.php index a6f5b463a3..3bcc9e7699 100644 --- a/src/Appwrite/Platform/Workers/Mails.php +++ b/src/Appwrite/Platform/Workers/Mails.php @@ -59,7 +59,10 @@ class Mails extends Action $variables = $payload['variables']; $name = $payload['name']; $body = $payload['body']; - $bodyTemplate = $payload['bodyTemplate'] ?? __DIR__ . '/../../../../app/config/locale/templates/email-base.tpl'; + $bodyTemplate = $payload['bodyTemplate']; + if(empty($bodyTemplate)) { + $bodyTemplate = __DIR__ . '/../../../../app/config/locale/templates/email-base.tpl'; + } $bodyTemplate = Template::fromFile($bodyTemplate); $bodyTemplate->setParam('{{body}}', $body); foreach ($variables as $key => $value) { From ffdc6620224765baa1578f6def87d9503c48ec8b Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sat, 9 Dec 2023 06:41:24 +0000 Subject: [PATCH 3/3] fix formatting --- src/Appwrite/Event/Mail.php | 2 +- src/Appwrite/Platform/Workers/Mails.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Event/Mail.php b/src/Appwrite/Event/Mail.php index c283092e69..9973dae403 100644 --- a/src/Appwrite/Event/Mail.php +++ b/src/Appwrite/Event/Mail.php @@ -376,4 +376,4 @@ class Mail extends Event 'events' => Event::generateEvents($this->getEvent(), $this->getParams()) ]); } -} \ No newline at end of file +} diff --git a/src/Appwrite/Platform/Workers/Mails.php b/src/Appwrite/Platform/Workers/Mails.php index e8d96f098d..8c1e3c2ec8 100644 --- a/src/Appwrite/Platform/Workers/Mails.php +++ b/src/Appwrite/Platform/Workers/Mails.php @@ -61,9 +61,9 @@ class Mails extends Action $body = $payload['body']; $attachment = $payload['attachment'] ?? []; $bodyTemplate = $payload['bodyTemplate']; - if(empty($bodyTemplate)) { + if (empty($bodyTemplate)) { $bodyTemplate = __DIR__ . '/../../../../app/config/locale/templates/email-base.tpl'; - } + } $bodyTemplate = Template::fromFile($bodyTemplate); $bodyTemplate->setParam('{{body}}', $body); foreach ($variables as $key => $value) { @@ -143,4 +143,4 @@ class Mails extends Action return $mail; } -} \ No newline at end of file +}