From c69a2b642ee7d415db8dd54af8ed1e1f3c27a45d Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Wed, 2 Feb 2022 16:27:31 -0500 Subject: [PATCH 1/3] ability to add tags/metadata to Emails/Notifications --- src/Illuminate/Mail/Mailable.php | 30 +++++++++++++++++++ .../Notifications/Messages/MailMessage.php | 30 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/Illuminate/Mail/Mailable.php b/src/Illuminate/Mail/Mailable.php index 3e8cf6b45577..eac8dae28428 100644 --- a/src/Illuminate/Mail/Mailable.php +++ b/src/Illuminate/Mail/Mailable.php @@ -20,6 +20,9 @@ use PHPUnit\Framework\Assert as PHPUnit; use ReflectionClass; use ReflectionProperty; +use Symfony\Component\Mailer\Header\MetadataHeader; +use Symfony\Component\Mailer\Header\TagHeader; +use Symfony\Component\Mime\Email; class Mailable implements MailableContract, Renderable { @@ -1021,6 +1024,33 @@ public function mailer($mailer) return $this; } + /** + * Add a tag to the email (for drivers that support). + * + * @param string $value + * @return $this + */ + public function tag($value) + { + return $this->withSymfonyMessage(function (Email $message) use ($value) { + $message->getHeaders()->add(new TagHeader($value)); + }); + } + + /** + * Add metadata to the email (for drivers that support). + * + * @param string $key + * @param string $value + * @return $this + */ + public function metadata($key, $value) + { + return $this->withSymfonyMessage(function (Email $message) use ($key, $value) { + $message->getHeaders()->add(new MetadataHeader($key, $value)); + }); + } + /** * Register a callback to be called with the Symfony message instance. * diff --git a/src/Illuminate/Notifications/Messages/MailMessage.php b/src/Illuminate/Notifications/Messages/MailMessage.php index 24c2515ca52c..96f640a1669a 100644 --- a/src/Illuminate/Notifications/Messages/MailMessage.php +++ b/src/Illuminate/Notifications/Messages/MailMessage.php @@ -7,6 +7,9 @@ use Illuminate\Contracts\Support\Renderable; use Illuminate\Mail\Markdown; use Illuminate\Support\Traits\Conditionable; +use Symfony\Component\Mailer\Header\MetadataHeader; +use Symfony\Component\Mailer\Header\TagHeader; +use Symfony\Component\Mime\Email; class MailMessage extends SimpleMessage implements Renderable { @@ -321,6 +324,33 @@ public function render() ->render($this->markdown, $this->data()); } + /** + * Add a tag to the email (for drivers that support). + * + * @param string $value + * @return $this + */ + public function tag($value) + { + return $this->withSymfonyMessage(function (Email $message) use ($value) { + $message->getHeaders()->add(new TagHeader($value)); + }); + } + + /** + * Add metadata to the email (for drivers that support). + * + * @param string $key + * @param string $value + * @return $this + */ + public function metadata($key, $value) + { + return $this->withSymfonyMessage(function (Email $message) use ($key, $value) { + $message->getHeaders()->add(new MetadataHeader($key, $value)); + }); + } + /** * Register a callback to be called with the Symfony message instance. * From e3c572a585f55b2ec5ee78f3db9b5bdd031df16a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 4 Feb 2022 10:27:14 -0600 Subject: [PATCH 2/3] formatting --- src/Illuminate/Mail/Mailable.php | 54 ++++++++++++++++---------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Illuminate/Mail/Mailable.php b/src/Illuminate/Mail/Mailable.php index eac8dae28428..27f5b0fe155b 100644 --- a/src/Illuminate/Mail/Mailable.php +++ b/src/Illuminate/Mail/Mailable.php @@ -873,6 +873,33 @@ public function attachData($data, $name, array $options = []) return $this; } + /** + * Add a tag header to the message when supported by the underlying transport. + * + * @param string $value + * @return $this + */ + public function tag($value) + { + return $this->withSymfonyMessage(function (Email $message) use ($value) { + $message->getHeaders()->add(new TagHeader($value)); + }); + } + + /** + * Add a metadata header to the message when supported by the underlying transport. + * + * @param string $key + * @param string $value + * @return $this + */ + public function metadata($key, $value) + { + return $this->withSymfonyMessage(function (Email $message) use ($key, $value) { + $message->getHeaders()->add(new MetadataHeader($key, $value)); + }); + } + /** * Assert that the given text is present in the HTML email body. * @@ -1024,33 +1051,6 @@ public function mailer($mailer) return $this; } - /** - * Add a tag to the email (for drivers that support). - * - * @param string $value - * @return $this - */ - public function tag($value) - { - return $this->withSymfonyMessage(function (Email $message) use ($value) { - $message->getHeaders()->add(new TagHeader($value)); - }); - } - - /** - * Add metadata to the email (for drivers that support). - * - * @param string $key - * @param string $value - * @return $this - */ - public function metadata($key, $value) - { - return $this->withSymfonyMessage(function (Email $message) use ($key, $value) { - $message->getHeaders()->add(new MetadataHeader($key, $value)); - }); - } - /** * Register a callback to be called with the Symfony message instance. * From d1f8f9460ddfdba0623429d4d035800f2d2df9e7 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 4 Feb 2022 10:27:53 -0600 Subject: [PATCH 3/3] formatting --- .../Notifications/Messages/MailMessage.php | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Illuminate/Notifications/Messages/MailMessage.php b/src/Illuminate/Notifications/Messages/MailMessage.php index 96f640a1669a..da4a6a678627 100644 --- a/src/Illuminate/Notifications/Messages/MailMessage.php +++ b/src/Illuminate/Notifications/Messages/MailMessage.php @@ -256,6 +256,33 @@ public function attachData($data, $name, array $options = []) return $this; } + /** + * Add a tag header to the message when supported by the underlying transport. + * + * @param string $value + * @return $this + */ + public function tag($value) + { + return $this->withSymfonyMessage(function (Email $message) use ($value) { + $message->getHeaders()->add(new TagHeader($value)); + }); + } + + /** + * Add a metadata header to the message when supported by the underlying transport. + * + * @param string $key + * @param string $value + * @return $this + */ + public function metadata($key, $value) + { + return $this->withSymfonyMessage(function (Email $message) use ($key, $value) { + $message->getHeaders()->add(new MetadataHeader($key, $value)); + }); + } + /** * Set the priority of this message. * @@ -324,33 +351,6 @@ public function render() ->render($this->markdown, $this->data()); } - /** - * Add a tag to the email (for drivers that support). - * - * @param string $value - * @return $this - */ - public function tag($value) - { - return $this->withSymfonyMessage(function (Email $message) use ($value) { - $message->getHeaders()->add(new TagHeader($value)); - }); - } - - /** - * Add metadata to the email (for drivers that support). - * - * @param string $key - * @param string $value - * @return $this - */ - public function metadata($key, $value) - { - return $this->withSymfonyMessage(function (Email $message) use ($key, $value) { - $message->getHeaders()->add(new MetadataHeader($key, $value)); - }); - } - /** * Register a callback to be called with the Symfony message instance. *