diff --git a/CHANGELOG.md b/CHANGELOG.md index df8c368..dc5a339 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [1.8.1] - 2024-04-25 + +- Use real value for template headers (should not be encoded as it is not a real header) + ## [1.8.0] - 2024-04-19 - Support new functionality [Bulk Stream](https://help.mailtrap.io/article/113-sending-streams) diff --git a/src/Api/AbstractEmails.php b/src/Api/AbstractEmails.php index 02f5d60..06c2b22 100644 --- a/src/Api/AbstractEmails.php +++ b/src/Api/AbstractEmails.php @@ -58,10 +58,10 @@ protected function getPayload(Email $email): array switch(true) { case $header instanceof CustomVariableHeader: - $payload[CustomVariableHeader::VAR_NAME][$header->getName()] = $header->getBodyAsString(); + $payload[CustomVariableHeader::VAR_NAME][$header->getName()] = $header->getValue(); break; case $header instanceof TemplateVariableHeader: - $payload[TemplateVariableHeader::VAR_NAME][$header->getName()] = $header->getBodyAsString(); + $payload[TemplateVariableHeader::VAR_NAME][$header->getName()] = $header->getValue(); break; case $header instanceof CategoryHeader: if (!empty($payload[CategoryHeader::VAR_NAME])) { @@ -70,7 +70,7 @@ protected function getPayload(Email $email): array ); } - $payload[CategoryHeader::VAR_NAME] = $header->getBodyAsString(); + $payload[CategoryHeader::VAR_NAME] = $header->getValue(); break; case $header instanceof TemplateUuidHeader: if (!empty($payload[TemplateUuidHeader::VAR_NAME])) { @@ -79,7 +79,7 @@ protected function getPayload(Email $email): array ); } - $payload[TemplateUuidHeader::VAR_NAME] = $header->getBodyAsString(); + $payload[TemplateUuidHeader::VAR_NAME] = $header->getValue(); break; default: $payload['headers'][$header->getName()] = $header->getBodyAsString(); diff --git a/tests/Api/AbstractEmailsTest.php b/tests/Api/AbstractEmailsTest.php index a8aa5e8..507f3c2 100644 --- a/tests/Api/AbstractEmailsTest.php +++ b/tests/Api/AbstractEmailsTest.php @@ -51,7 +51,8 @@ public function testValidSend(): void ->html('
Some text
') ; $email->getHeaders() - ->addTextHeader('X-Message-Source', 'dev.mydomain.com'); + ->addTextHeader('X-Message-Source', 'dev.mydomain.com') + ->addTextHeader('Test-Unicode-Header', 'Subašić'); $this->email ->expects($this->once()) @@ -75,6 +76,7 @@ public function testValidSend(): void 'X-Message-Source' => 'dev.mydomain.com', 'Reply-To' => 'reply@example.com', 'X-Priority' => '2 (High)', + 'Test-Unicode-Header' => '=?utf-8?Q?Suba=C5=A1i=C4=87?=', // See RFC 2822, Sect 2.2 ] ]) ->willReturn(new Response(200, ['Content-Type' => 'application/json'], json_encode($expectedData))); @@ -147,6 +149,7 @@ public function testValidSendTemplate(): void $email->getHeaders() ->add(new TemplateUuidHeader('bfa432fd-0000-0000-0000-8493da283a69')) ->add(new TemplateVariableHeader('user_name', 'Jon Bush')) + ->add(new TemplateVariableHeader('unicode_user_name', 'Subašić')) ->add(new TemplateVariableHeader('next_step_link', 'https://mailtrap.io/')) ->add(new TemplateVariableHeader('get_started_link', 'https://mailtrap.io/')) ->add(new TemplateVariableHeader('onboarding_video_link', 'some_video_link')) @@ -167,6 +170,7 @@ public function testValidSendTemplate(): void 'template_uuid' => 'bfa432fd-0000-0000-0000-8493da283a69', 'template_variables' => [ 'user_name' => 'Jon Bush', + 'unicode_user_name' => 'Subašić', // should not be encoded as it is not a real header 'next_step_link' => 'https://mailtrap.io/', 'get_started_link' => 'https://mailtrap.io/', 'onboarding_video_link' => 'some_video_link',