diff --git a/app/bundles/EmailBundle/Swiftmailer/Transport/MailjetTransport.php b/app/bundles/EmailBundle/Swiftmailer/Transport/MailjetTransport.php index 68c200a57b5..0b35718ef4e 100644 --- a/app/bundles/EmailBundle/Swiftmailer/Transport/MailjetTransport.php +++ b/app/bundles/EmailBundle/Swiftmailer/Transport/MailjetTransport.php @@ -103,9 +103,15 @@ public function processCallbackRequest(Request $request) continue; } - if ('bounce' === $event['event'] || 'blocked' === $event['event']) { - $reason = $event['error_related_to'].': '.$event['error']; + if (('bounce' === $event['event']) || ('blocked' === $event['event'])) { $type = DoNotContact::BOUNCED; + if ('blocked' === $event['event']) { + $reason = 'BLOCKED: '.$event['error_related_to'].': '.$event['error']; + } elseif (false === $event['hard_bounce']) { + $reason = 'SOFT: '.$event['error_related_to'].': '.$event['error'].': '.$event['comment']; + } else { + $reason = 'HARD: '.$event['error_related_to'].': '.$event['error']; + } } elseif ('spam' === $event['event']) { $reason = 'User reported email as spam, source: '.$event['source']; $type = DoNotContact::UNSUBSCRIBED; diff --git a/app/bundles/EmailBundle/Tests/Transport/MailjetTransportTest.php b/app/bundles/EmailBundle/Tests/Transport/MailjetTransportTest.php index a7d8773e1ea..8f4727956d7 100644 --- a/app/bundles/EmailBundle/Tests/Transport/MailjetTransportTest.php +++ b/app/bundles/EmailBundle/Tests/Transport/MailjetTransportTest.php @@ -34,17 +34,17 @@ public function testWebhookPayloadIsProcessed() ->method('addFailureByHashId') ->withConsecutive( [$this->equalTo('1'), 'User unsubscribed', DoNotContact::UNSUBSCRIBED], - [$this->equalTo('2'), 'blocked: blocked', DoNotContact::BOUNCED], + [$this->equalTo('2'), 'BLOCKED: blocked: blocked', DoNotContact::BOUNCED], [$this->equalTo('3'), 'User reported email as spam, source: spam button', DoNotContact::UNSUBSCRIBED], - [$this->equalTo('4'), 'bounced: bounced', DoNotContact::BOUNCED], - [$this->equalTo('5'), 'bounced: bounced', DoNotContact::BOUNCED] + [$this->equalTo('4'), 'SOFT: bounced: bounced: text of mailjet', DoNotContact::BOUNCED], + [$this->equalTo('5'), 'HARD: bounced: bounced', DoNotContact::BOUNCED] ); $this->transportCallback->expects($this->once()) ->method('addFailureByAddress') ->with( 'bounce2@test.com', - 'bounced: bounce without hash', + 'HARD: bounced: bounce without hash', DoNotContact::BOUNCED ); @@ -119,9 +119,10 @@ private function getRequestWithPayload() "CustomID": "4-bounce@test.com", "Payload": "", "blocked": "", - "hard_bounce": "", + "hard_bounce": false, "error_related_to": "bounced", - "error": "bounced" + "error": "bounced", + "comment": "text of mailjet" }, { "event": "bounce", @@ -134,7 +135,7 @@ private function getRequestWithPayload() "CustomID": "5-bounce3@test-test.com", "Payload": "", "blocked": "", - "hard_bounce": "", + "hard_bounce": true, "error_related_to": "bounced", "error": "bounced" },