AmazonSESMapper.php
3 years ago
BlacklistErrorMapperTrait.php
3 years ago
ConnectionErrorMapperTrait.php
3 years ago
MailPoetMapper.php
1 year ago
PHPMailMapper.php
4 years ago
PHPMailerMapper.php
3 years ago
SMTPMapper.php
4 years ago
SendGridMapper.php
3 years ago
index.php
3 years ago
AmazonSESMapper.php
45 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Mailer\Methods\ErrorMappers; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Mailer\Mailer; |
| 9 | use MailPoet\Mailer\MailerError; |
| 10 | use MailPoet\Mailer\SubscriberError; |
| 11 | |
| 12 | class AmazonSESMapper { |
| 13 | use BlacklistErrorMapperTrait; |
| 14 | use ConnectionErrorMapperTrait; |
| 15 | |
| 16 | const METHOD = Mailer::METHOD_AMAZONSES; |
| 17 | |
| 18 | public function getErrorFromException(\Exception $e, $subscriber) { |
| 19 | $level = MailerError::LEVEL_HARD; |
| 20 | if (strpos($e->getMessage(), 'Invalid address') !== false && strpos($e->getMessage(), '(to):') !== false) { |
| 21 | $level = MailerError::LEVEL_SOFT; |
| 22 | } |
| 23 | $subscriberErrors = [new SubscriberError($subscriber, null)]; |
| 24 | return new MailerError(MailerError::OPERATION_SEND, $level, $e->getMessage(), null, $subscriberErrors); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @see https://docs.aws.amazon.com/ses/latest/DeveloperGuide/api-error-codes.html |
| 29 | * @return MailerError |
| 30 | */ |
| 31 | public function getErrorFromResponse($response, $subscriber) { |
| 32 | $message = ($response) ? |
| 33 | $response->Error->Message->__toString() : // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps |
| 34 | // translators: %s is the name of the method. |
| 35 | sprintf(__('%s has returned an unknown error.', 'mailpoet'), Mailer::METHOD_AMAZONSES); |
| 36 | |
| 37 | $level = MailerError::LEVEL_HARD; |
| 38 | if ($response && $response->Error->Code->__toString() === 'MessageRejected') { // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps |
| 39 | $level = MailerError::LEVEL_SOFT; |
| 40 | } |
| 41 | $subscriberErrors = [new SubscriberError($subscriber, null)]; |
| 42 | return new MailerError(MailerError::OPERATION_SEND, $level, $message, null, $subscriberErrors); |
| 43 | } |
| 44 | } |
| 45 |