Remove unnecessary test_email extra parameter for mailer->send
It was used only to prevent appending unprocessed subscribers into error message. Since the message is now composed by on demand by MailerError the parameter is not needed any more. [MAILPOET-1154]
This commit is contained in:
@ -21,10 +21,7 @@ class Mailer extends APIEndpoint {
|
||||
(isset($data['sender'])) ? $data['sender'] : false,
|
||||
(isset($data['reply_to'])) ? $data['reply_to'] : false
|
||||
);
|
||||
$extra_params = array(
|
||||
'test_email' => true
|
||||
);
|
||||
$result = $mailer->send($data['newsletter'], $data['subscriber'], $extra_params);
|
||||
$result = $mailer->send($data['newsletter'], $data['subscriber']);
|
||||
} catch(\Exception $e) {
|
||||
return $this->errorResponse(array(
|
||||
$e->getCode() => $e->getMessage()
|
||||
|
@ -79,7 +79,7 @@ class AmazonSES {
|
||||
}
|
||||
if(WPFunctions::wpRemoteRetrieveResponseCode($result) !== 200) {
|
||||
$response = simplexml_load_string(WPFunctions::wpRemoteRetrieveBody($result));
|
||||
$error = $this->error_mapper->getErrorFromResponse($response, $subscriber, $extra_params);
|
||||
$error = $this->error_mapper->getErrorFromResponse($response, $subscriber);
|
||||
return Mailer::formatMailerErrorResult($error);
|
||||
}
|
||||
return Mailer::formatMailerSendSuccessResult();
|
||||
|
@ -21,7 +21,7 @@ class AmazonSESMapper {
|
||||
* @see https://docs.aws.amazon.com/ses/latest/DeveloperGuide/api-error-codes.html
|
||||
* @return MailerError
|
||||
*/
|
||||
function getErrorFromResponse($response, $subscriber, $extra_params) {
|
||||
function getErrorFromResponse($response, $subscriber) {
|
||||
$message = ($response) ?
|
||||
$response->Error->Message->__toString() :
|
||||
sprintf(__('%s has returned an unknown error.', 'mailpoet'), Mailer::METHOD_AMAZONSES);
|
||||
@ -30,11 +30,7 @@ class AmazonSESMapper {
|
||||
if($response && $response->Error->Code->__toString() === 'MessageRejected') {
|
||||
$level = MailerError::LEVEL_SOFT;
|
||||
}
|
||||
|
||||
$subscriber_errors = [];
|
||||
if(empty($extra_params['test_email'])) {
|
||||
$subscriber_errors[] = new SubscriberError($subscriber, null);
|
||||
}
|
||||
$subscriber_errors = [new SubscriberError($subscriber, null)];
|
||||
return new MailerError(MailerError::OPERATION_SEND, $level, $message, null, $subscriber_errors);
|
||||
}
|
||||
}
|
||||
|
@ -8,24 +8,19 @@ use MailPoet\Mailer\SubscriberError;
|
||||
class PHPMailMapper {
|
||||
use ConnectionErrorMapperTrait;
|
||||
|
||||
function getErrorFromException(\Exception $e, $subscriber, $extra_params) {
|
||||
function getErrorFromException(\Exception $e, $subscriber) {
|
||||
$level = MailerError::LEVEL_HARD;
|
||||
if(strpos($e->getMessage(), 'Invalid address') === 0) {
|
||||
$level = MailerError::LEVEL_SOFT;
|
||||
}
|
||||
$subscriber_errors = [];
|
||||
if(empty($extra_params['test_email'])) {
|
||||
$subscriber_errors[] = new SubscriberError($subscriber, null);
|
||||
}
|
||||
|
||||
$subscriber_errors = [new SubscriberError($subscriber, null)];
|
||||
return new MailerError(MailerError::OPERATION_SEND, $level, $e->getMessage(), null, $subscriber_errors);
|
||||
}
|
||||
|
||||
function getErrorForSubscriber($subscriber, $extra_params) {
|
||||
function getErrorForSubscriber($subscriber) {
|
||||
$message = sprintf(__('%s has returned an unknown error.', 'mailpoet'), Mailer::METHOD_PHPMAIL);
|
||||
$subscriber_errors = [];
|
||||
if(empty($extra_params['test_email'])) {
|
||||
$subscriber_errors[] = new SubscriberError($subscriber, null);
|
||||
}
|
||||
$subscriber_errors = [new SubscriberError($subscriber, null)];
|
||||
return new MailerError(MailerError::OPERATION_SEND, MailerError::LEVEL_HARD, $message, null, $subscriber_errors);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ class SMTPMapper {
|
||||
* @see https://swiftmailer.symfony.com/docs/sending.html
|
||||
* @return MailerError
|
||||
*/
|
||||
function getErrorFromException(\Exception $e, $subscriber, $extra_params = []) {
|
||||
function getErrorFromException(\Exception $e, $subscriber) {
|
||||
// remove redundant information appended by Swift logger to exception messages
|
||||
$message = explode(PHP_EOL, $e->getMessage());
|
||||
|
||||
@ -20,16 +20,11 @@ class SMTPMapper {
|
||||
if($e instanceof \Swift_RfcComplianceException) {
|
||||
$level = MailerError::LEVEL_SOFT;
|
||||
}
|
||||
|
||||
$subscriber_errors = [];
|
||||
if(empty($extra_params['test_email'])) {
|
||||
$subscriber_errors[] = new SubscriberError($subscriber, null);
|
||||
}
|
||||
|
||||
$subscriber_errors = [new SubscriberError($subscriber, null)];
|
||||
return new MailerError(MailerError::OPERATION_SEND, $level, $message[0], null, $subscriber_errors);
|
||||
}
|
||||
|
||||
function getErrorFromLog($log, $subscriber, $extra_params = []) {
|
||||
function getErrorFromLog($log, $subscriber) {
|
||||
// extract error message from log
|
||||
preg_match('/!! (.*?)>>/ism', $log, $message);
|
||||
if(!empty($message[1])) {
|
||||
@ -39,11 +34,7 @@ class SMTPMapper {
|
||||
} else {
|
||||
$message = sprintf(__('%s has returned an unknown error.', 'mailpoet'), Mailer::METHOD_SMTP);
|
||||
}
|
||||
|
||||
$subscriber_errors = [];
|
||||
if(empty($extra_params['test_email'])) {
|
||||
$subscriber_errors[] = new SubscriberError($subscriber, null);
|
||||
}
|
||||
$subscriber_errors = [new SubscriberError($subscriber, null)];
|
||||
return new MailerError(MailerError::OPERATION_SEND, MailerError::LEVEL_HARD, $message, null, $subscriber_errors);
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ use MailPoet\Mailer\SubscriberError;
|
||||
class SendGridMapper {
|
||||
use ConnectionErrorMapperTrait;
|
||||
|
||||
function getErrorFromResponse($response, $subscriber, $extra_params) {
|
||||
function getErrorFromResponse($response, $subscriber) {
|
||||
$response = (!empty($response['errors'][0])) ?
|
||||
$response['errors'][0] :
|
||||
sprintf(__('%s has returned an unknown error.', 'mailpoet'), Mailer::METHOD_SENDGRID);
|
||||
@ -17,11 +17,7 @@ class SendGridMapper {
|
||||
if(strpos($response, 'Invalid email address') === 0) {
|
||||
$level = MailerError::LEVEL_SOFT;
|
||||
}
|
||||
|
||||
$subscriber_errors = [];
|
||||
if(empty($extra_params['test_email'])) {
|
||||
$subscriber_errors[] = new SubscriberError($subscriber, null);
|
||||
}
|
||||
$subscriber_errors = [new SubscriberError($subscriber, null)];
|
||||
return new MailerError(MailerError::OPERATION_SEND, $level, $response, null, $subscriber_errors);
|
||||
}
|
||||
}
|
||||
|
@ -33,12 +33,12 @@ class PHPMail {
|
||||
$mailer = $this->configureMailerWithMessage($newsletter, $subscriber, $extra_params);
|
||||
$result = $mailer->send();
|
||||
} catch(\Exception $e) {
|
||||
return Mailer::formatMailerErrorResult($this->error_mapper->getErrorFromException($e, $subscriber, $extra_params));
|
||||
return Mailer::formatMailerErrorResult($this->error_mapper->getErrorFromException($e, $subscriber));
|
||||
}
|
||||
if($result === true) {
|
||||
return Mailer::formatMailerSendSuccessResult();
|
||||
} else {
|
||||
$error = $this->error_mapper->getErrorForSubscriber($subscriber, $extra_params);
|
||||
$error = $this->error_mapper->getErrorForSubscriber($subscriber);
|
||||
return Mailer::formatMailerErrorResult($error);
|
||||
}
|
||||
}
|
||||
|
@ -49,13 +49,13 @@ class SMTP {
|
||||
$result = $this->mailer->send($message);
|
||||
} catch(\Exception $e) {
|
||||
return Mailer::formatMailerErrorResult(
|
||||
$this->error_mapper->getErrorFromException($e, $subscriber, $extra_params)
|
||||
$this->error_mapper->getErrorFromException($e, $subscriber)
|
||||
);
|
||||
}
|
||||
if($result === 1) {
|
||||
return Mailer::formatMailerSendSuccessResult();
|
||||
} else {
|
||||
$error = $this->error_mapper->getErrorFromLog($this->mailer_logger->dump(), $subscriber, $extra_params);
|
||||
$error = $this->error_mapper->getErrorFromLog($this->mailer_logger->dump(), $subscriber);
|
||||
return Mailer::formatMailerErrorResult($error);
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class SendGrid {
|
||||
}
|
||||
if(WPFunctions::wpRemoteRetrieveResponseCode($result) !== 200) {
|
||||
$response = json_decode($result['body'], true);
|
||||
$error = $this->error_mapper->getErrorFromResponse($response, $subscriber, $extra_params);
|
||||
$error = $this->error_mapper->getErrorFromResponse($response, $subscriber);
|
||||
return Mailer::formatMailerErrorResult($error);
|
||||
}
|
||||
return Mailer::formatMailerSendSuccessResult();
|
||||
|
@ -27,7 +27,7 @@ class AmazonSESMapperTest extends \MailPoetTest {
|
||||
|
||||
function testGetProperError() {
|
||||
$response = $this->buildXmlResponseFromArray($this->response_data, new SimpleXMLElement('<response/>'));
|
||||
$error = $this->mapper->getErrorFromResponse($response, 'john@rambo.com', []);
|
||||
$error = $this->mapper->getErrorFromResponse($response, 'john@rambo.com');
|
||||
expect($error->getLevel())->equals(MailerError::LEVEL_HARD);
|
||||
expect($error->getMessage())->equals('Some message');
|
||||
expect($error->getSubscriberErrors()[0]->getEmail())->equals('john@rambo.com');
|
||||
@ -36,7 +36,7 @@ class AmazonSESMapperTest extends \MailPoetTest {
|
||||
function testGetSoftErrorForRejectedMessage() {
|
||||
$this->response_data['Error']['Code'] = 'MessageRejected';
|
||||
$response = $this->buildXmlResponseFromArray($this->response_data, new SimpleXMLElement('<response/>'));
|
||||
$error = $this->mapper->getErrorFromResponse($response, 'john@rambo.com', []);
|
||||
$error = $this->mapper->getErrorFromResponse($response, 'john@rambo.com');
|
||||
expect($error->getLevel())->equals(MailerError::LEVEL_SOFT);
|
||||
}
|
||||
|
||||
|
@ -14,21 +14,21 @@ class PHPMailMapperTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testGetProperErrorForSubscriber() {
|
||||
$error = $this->mapper->getErrorForSubscriber('john@rambo.com', []);
|
||||
$error = $this->mapper->getErrorForSubscriber('john@rambo.com');
|
||||
expect($error->getLevel())->equals(MailerError::LEVEL_HARD);
|
||||
expect($error->getMessage())->equals('PHPMail has returned an unknown error.');
|
||||
expect($error->getSubscriberErrors()[0]->getEmail())->equals('john@rambo.com');
|
||||
}
|
||||
|
||||
function testGetProperErrorFromException() {
|
||||
$error = $this->mapper->getErrorFromException(new \Exception('Some message'), 'john@rambo.com', []);
|
||||
$error = $this->mapper->getErrorFromException(new \Exception('Some message'), 'john@rambo.com');
|
||||
expect($error->getLevel())->equals(MailerError::LEVEL_HARD);
|
||||
expect($error->getMessage())->equals('Some message');
|
||||
expect($error->getSubscriberErrors()[0]->getEmail())->equals('john@rambo.com');
|
||||
}
|
||||
|
||||
function testGetSoftErrorFromExceptionForInvalidEmail() {
|
||||
$error = $this->mapper->getErrorFromException(new \Exception('Invalid address. (Add ...'), 'john@rambo.com', []);
|
||||
$error = $this->mapper->getErrorFromException(new \Exception('Invalid address. (Add ...'), 'john@rambo.com');
|
||||
expect($error->getLevel())->equals(MailerError::LEVEL_SOFT);
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ class SMTPMapperTest extends \MailPoetTest {
|
||||
. '" (code: 550)' . PHP_EOL
|
||||
. '>> RSET' . PHP_EOL
|
||||
. '<< 250 Reset OK' . PHP_EOL;
|
||||
$error = $this->mapper->getErrorFromLog($log, 'test@example.com', []);
|
||||
$error = $this->mapper->getErrorFromLog($log, 'test@example.com');
|
||||
expect($error->getMessage())
|
||||
->equals('Expected response code 250/251/252 but got code "550", with message "550 No such recipient here" (code: 550)');
|
||||
expect($error->getSubscriberErrors()[0]->getEmail('moi@mrcasual.com'));
|
||||
|
@ -22,7 +22,7 @@ class SendGridMapperTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testGetProperError() {
|
||||
$error = $this->mapper->getErrorFromResponse($this->response, 'john@rambo.com', []);
|
||||
$error = $this->mapper->getErrorFromResponse($this->response, 'john@rambo.com');
|
||||
expect($error->getLevel())->equals(MailerError::LEVEL_HARD);
|
||||
expect($error->getMessage())->equals('Some message');
|
||||
expect($error->getSubscriberErrors()[0]->getEmail())->equals('john@rambo.com');
|
||||
@ -30,7 +30,7 @@ class SendGridMapperTest extends \MailPoetTest {
|
||||
|
||||
function testGetSoftErrorForInvalidEmail() {
|
||||
$this->response['errors'][0] = 'Invalid email address ,,@';
|
||||
$error = $this->mapper->getErrorFromResponse($this->response, ',,@', []);
|
||||
$error = $this->mapper->getErrorFromResponse($this->response, ',,@');
|
||||
expect($error->getLevel())->equals(MailerError::LEVEL_SOFT);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user