This commit is contained in:
2022-07-18 08:00:16 +03:00
parent 42dd4c60f2
commit 42a8133706
2387 changed files with 210708 additions and 29 deletions

View File

@@ -0,0 +1,67 @@
<?php
namespace Illuminate\Mail\Transport;
use Illuminate\Support\Collection;
use Symfony\Component\Mailer\Envelope;
use Symfony\Component\Mailer\SentMessage;
use Symfony\Component\Mailer\Transport\TransportInterface;
use Symfony\Component\Mime\RawMessage;
class ArrayTransport implements TransportInterface
{
/**
* The collection of Symfony Messages.
*
* @var \Illuminate\Support\Collection
*/
protected $messages;
/**
* Create a new array transport instance.
*
* @return void
*/
public function __construct()
{
$this->messages = new Collection;
}
/**
* {@inheritdoc}
*/
public function send(RawMessage $message, Envelope $envelope = null): ?SentMessage
{
return $this->messages[] = new SentMessage($message, $envelope ?? Envelope::create($message));
}
/**
* Retrieve the collection of messages.
*
* @return \Illuminate\Support\Collection
*/
public function messages()
{
return $this->messages;
}
/**
* Clear all of the messages from the local collection.
*
* @return \Illuminate\Support\Collection
*/
public function flush()
{
return $this->messages = new Collection;
}
/**
* Get the string representation of the transport.
*
* @return string
*/
public function __toString(): string
{
return 'array';
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Illuminate\Mail\Transport;
use Psr\Log\LoggerInterface;
use Symfony\Component\Mailer\Envelope;
use Symfony\Component\Mailer\SentMessage;
use Symfony\Component\Mailer\Transport\TransportInterface;
use Symfony\Component\Mime\RawMessage;
class LogTransport implements TransportInterface
{
/**
* The Logger instance.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* Create a new log transport instance.
*
* @param \Psr\Log\LoggerInterface $logger
* @return void
*/
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
/**
* {@inheritdoc}
*/
public function send(RawMessage $message, Envelope $envelope = null): ?SentMessage
{
$this->logger->debug($message->toString());
return new SentMessage($message, $envelope ?? Envelope::create($message));
}
/**
* Get the logger for the LogTransport instance.
*
* @return \Psr\Log\LoggerInterface
*/
public function logger()
{
return $this->logger;
}
/**
* Get the string representation of the transport.
*
* @return string
*/
public function __toString(): string
{
return 'log';
}
}

View File

@@ -0,0 +1,131 @@
<?php
namespace Illuminate\Mail\Transport;
use Aws\Exception\AwsException;
use Aws\Ses\SesClient;
use Exception;
use Symfony\Component\Mailer\Header\MetadataHeader;
use Symfony\Component\Mailer\SentMessage;
use Symfony\Component\Mailer\Transport\AbstractTransport;
use Symfony\Component\Mime\Message;
class SesTransport extends AbstractTransport
{
/**
* The Amazon SES instance.
*
* @var \Aws\Ses\SesClient
*/
protected $ses;
/**
* The Amazon SES transmission options.
*
* @var array
*/
protected $options = [];
/**
* Create a new SES transport instance.
*
* @param \Aws\Ses\SesClient $ses
* @param array $options
* @return void
*/
public function __construct(SesClient $ses, $options = [])
{
$this->ses = $ses;
$this->options = $options;
parent::__construct();
}
/**
* {@inheritDoc}
*/
protected function doSend(SentMessage $message): void
{
$options = $this->options;
if ($message->getOriginalMessage() instanceof Message) {
foreach ($message->getOriginalMessage()->getHeaders()->all() as $header) {
if ($header instanceof MetadataHeader) {
$options['Tags'][] = ['Name' => $header->getKey(), 'Value' => $header->getValue()];
}
}
}
try {
$result = $this->ses->sendRawEmail(
array_merge(
$options, [
'Source' => $message->getEnvelope()->getSender()->toString(),
'Destinations' => collect($message->getEnvelope()->getRecipients())
->map
->toString()
->values()
->all(),
'RawMessage' => [
'Data' => $message->toString(),
],
]
)
);
} catch (AwsException $e) {
$reason = $e->getAwsErrorMessage() ?? $e->getMessage();
throw new Exception(
sprintf('Request to AWS SES API failed. Reason: %s.', $reason),
is_int($e->getCode()) ? $e->getCode() : 0,
$e
);
}
$messageId = $result->get('MessageId');
$message->getOriginalMessage()->getHeaders()->addHeader('X-Message-ID', $messageId);
$message->getOriginalMessage()->getHeaders()->addHeader('X-SES-Message-ID', $messageId);
}
/**
* Get the string representation of the transport.
*
* @return string
*/
public function __toString(): string
{
return 'ses';
}
/**
* Get the Amazon SES client for the SesTransport instance.
*
* @return \Aws\Ses\SesClient
*/
public function ses()
{
return $this->ses;
}
/**
* 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;
}
}