diff --git a/src/Symfony/Component/Mailer/Bridge/Infobip/CHANGELOG.md b/src/Symfony/Component/Mailer/Bridge/Infobip/CHANGELOG.md index 7174cd7fdeed..1320fd5f75bc 100644 --- a/src/Symfony/Component/Mailer/Bridge/Infobip/CHANGELOG.md +++ b/src/Symfony/Component/Mailer/Bridge/Infobip/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +6.3 +--- + + * Add reporting behavior thanks to new attributes support + 6.2 --- diff --git a/src/Symfony/Component/Mailer/Bridge/Infobip/Tests/Transport/InfobipApiTransportTest.php b/src/Symfony/Component/Mailer/Bridge/Infobip/Tests/Transport/InfobipApiTransportTest.php index 020d897559fd..86470e159190 100644 --- a/src/Symfony/Component/Mailer/Bridge/Infobip/Tests/Transport/InfobipApiTransportTest.php +++ b/src/Symfony/Component/Mailer/Bridge/Infobip/Tests/Transport/InfobipApiTransportTest.php @@ -241,6 +241,51 @@ public function testSendEmailWithAttachmentsShouldCalledInfobipWithTheRightParam ); } + public function testSendEmailWithHeadersShouldCalledInfobipWithTheRightParameters() + { + $email = $this->basicValidEmail(); + $email->getHeaders() + ->addTextHeader('X-Infobip-IntermediateReport', 'true') + ->addTextHeader('X-Infobip-NotifyUrl', 'https://foo.bar') + ->addTextHeader('X-Infobip-NotifyContentType', 'application/json') + ->addTextHeader('X-Infobip-MessageId', 'RANDOM-CUSTOM-ID'); + + $this->transport->send($email); + + $options = $this->response->getRequestOptions(); + $this->arrayHasKey('body'); + $this->assertStringMatchesFormat(<<<'TXT' + %a + --%s + Content-Type: text/plain; charset=utf-8 + Content-Transfer-Encoding: 8bit + Content-Disposition: form-data; name="intermediateReport" + + true + --%s + Content-Type: text/plain; charset=utf-8 + Content-Transfer-Encoding: 8bit + Content-Disposition: form-data; name="notifyUrl" + + https://foo.bar + --%s + Content-Type: text/plain; charset=utf-8 + Content-Transfer-Encoding: 8bit + Content-Disposition: form-data; name="notifyContentType" + + application/json + --%s + Content-Type: text/plain; charset=utf-8 + Content-Transfer-Encoding: 8bit + Content-Disposition: form-data; name="messageId" + + RANDOM-CUSTOM-ID + --%s-- + TXT, + $options['body'] + ); + } + public function testSendMinimalEmailWithSuccess() { $email = (new Email()) @@ -357,6 +402,31 @@ public function testSendEmailWithAttachmentsWithSuccess() ); } + public function testSendEmailWithHeadersWithSuccess() + { + $email = $this->basicValidEmail(); + $email->getHeaders() + ->addTextHeader('X-Infobip-IntermediateReport', 'true') + ->addTextHeader('X-Infobip-NotifyUrl', 'https://foo.bar') + ->addTextHeader('X-Infobip-NotifyContentType', 'application/json') + ->addTextHeader('X-Infobip-MessageId', 'RANDOM-CUSTOM-ID'); + + $sentMessage = $this->transport->send($email); + + $this->assertInstanceOf(SentMessage::class, $sentMessage); + $this->assertStringMatchesFormat( + <<<'TXT' + %a + X-Infobip-IntermediateReport: true + X-Infobip-NotifyUrl: https://foo.bar + X-Infobip-NotifyContentType: application/json + X-Infobip-MessageId: RANDOM-CUSTOM-ID + %a + TXT, + $sentMessage->toString() + ); + } + public function testSentMessageShouldCaptureInfobipMessageId() { $this->response = new MockResponse('{"messages": [{"messageId": "somexternalMessageId0"}]}'); diff --git a/src/Symfony/Component/Mailer/Bridge/Infobip/Transport/InfobipApiTransport.php b/src/Symfony/Component/Mailer/Bridge/Infobip/Transport/InfobipApiTransport.php index ad20f468417c..7902b9cdff25 100644 --- a/src/Symfony/Component/Mailer/Bridge/Infobip/Transport/InfobipApiTransport.php +++ b/src/Symfony/Component/Mailer/Bridge/Infobip/Transport/InfobipApiTransport.php @@ -33,6 +33,13 @@ final class InfobipApiTransport extends AbstractApiTransport { private const API_VERSION = '3'; + private const HEADER_TO_MESSAGE = [ + 'X-Infobip-IntermediateReport' => 'intermediateReport', + 'X-Infobip-NotifyUrl' => 'notifyUrl', + 'X-Infobip-NotifyContentType' => 'notifyContentType', + 'X-Infobip-MessageId' => 'messageId', + ]; + private string $key; public function __construct(string $key, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null) @@ -123,6 +130,12 @@ private function formDataPart(Email $email, Envelope $envelope): FormDataPart $this->attachmentsFormData($fields, $email); + foreach ($email->getHeaders()->all() as $header) { + if ($convertConf = self::HEADER_TO_MESSAGE[$header->getName()] ?? false) { + $fields[$convertConf] = $header->getBodyAsString(); + } + } + return new FormDataPart($fields); }
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: