From 618be85c9dceb21ca3a3bb02965366cc66c770dd Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Fri, 28 Jan 2022 12:20:33 +0100 Subject: [PATCH] Add SesTransport decorator --- src/Illuminate/Mail/MailManager.php | 5 +- .../Mail/Transport/ArrayTransport.php | 2 - .../Mail/Transport/LogTransport.php | 2 - .../Mail/Transport/SesTransport.php | 101 ++++++++++++++++++ 4 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 src/Illuminate/Mail/Transport/SesTransport.php diff --git a/src/Illuminate/Mail/MailManager.php b/src/Illuminate/Mail/MailManager.php index b7b0fc7908b4..fd780670d071 100644 --- a/src/Illuminate/Mail/MailManager.php +++ b/src/Illuminate/Mail/MailManager.php @@ -7,6 +7,7 @@ use Illuminate\Log\LogManager; use Illuminate\Mail\Transport\ArrayTransport; use Illuminate\Mail\Transport\LogTransport; +use Illuminate\Mail\Transport\SesTransport; use Illuminate\Support\Arr; use Illuminate\Support\Str; use InvalidArgumentException; @@ -240,14 +241,14 @@ protected function createSesTransport(array $config) $config['session_token'] = $config['token']; } - return $factory->create(new Dsn( + return new SesTransport($factory->create(new Dsn( 'ses+api', 'default', $config['key'] ?? null, $config['secret'] ?? null, $config['port'] ?? null, $config - )); + )), $config['options'] ?? []); } /** diff --git a/src/Illuminate/Mail/Transport/ArrayTransport.php b/src/Illuminate/Mail/Transport/ArrayTransport.php index 1403c1acd9a6..dc26ed69d90b 100644 --- a/src/Illuminate/Mail/Transport/ArrayTransport.php +++ b/src/Illuminate/Mail/Transport/ArrayTransport.php @@ -29,8 +29,6 @@ public function __construct() /** * {@inheritdoc} - * - * @return int */ public function send(RawMessage $message, Envelope $envelope = null): ?SentMessage { diff --git a/src/Illuminate/Mail/Transport/LogTransport.php b/src/Illuminate/Mail/Transport/LogTransport.php index 82be1708be02..d9ec8ac09d7e 100644 --- a/src/Illuminate/Mail/Transport/LogTransport.php +++ b/src/Illuminate/Mail/Transport/LogTransport.php @@ -30,8 +30,6 @@ public function __construct(LoggerInterface $logger) /** * {@inheritdoc} - * - * @return int */ public function send(RawMessage $message, Envelope $envelope = null): ?SentMessage { diff --git a/src/Illuminate/Mail/Transport/SesTransport.php b/src/Illuminate/Mail/Transport/SesTransport.php new file mode 100644 index 000000000000..4acb90a7c804 --- /dev/null +++ b/src/Illuminate/Mail/Transport/SesTransport.php @@ -0,0 +1,101 @@ +transport = $transport; + $this->options = $options; + } + + /** + * {@inheritdoc} + */ + public function send(RawMessage $message, ?Envelope $envelope = null): ?SentMessage + { + if ($message instanceof Email) { + if (isset($this->options['ConfigurationSetName'])) { + $message->getHeaders()->addTextHeader( + 'X-SES-CONFIGURATION-SET', $this->options['ConfigurationSetName'] + ); + } + + if (isset($this->options['FromEmailAddressIdentityArn'])) { + $message->getHeaders()->addTextHeader( + 'X-SES-SOURCE-ARN', $this->options['FromEmailAddressIdentityArn'] + ); + } + } + + return $this->transport->send($message, $envelope); + } + + /** + * Get the string representation of the transport. + * + * @return string + */ + public function __toString(): string + { + return $this->transport->__toString(); + } + + /** + * Get the transmission options being used by the transport. + * + * @return array + */ + public function getOptions() + { + return $this->options; + } + + /** + * Set the transmission options being used by the transport. + * + * @param array $options + * @return array + */ + public function setOptions(array $options) + { + return $this->options = $options; + } +}