Skip to content

Commit

Permalink
Merge pull request #24 from railsware/bug/fix-template-variables-enco…
Browse files Browse the repository at this point in the history
…ding

Bug > Fix template variables encoding
  • Loading branch information
gaalferov authored Apr 26, 2024
2 parents b00a943 + 46935e2 commit d79e011
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/Api/AbstractEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand All @@ -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])) {
Expand All @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion tests/Api/AbstractEmailsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public function testValidSend(): void
->html('<p>Some text</p>')
;
$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())
Expand All @@ -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)));
Expand Down Expand Up @@ -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'))
Expand All @@ -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',
Expand Down

0 comments on commit d79e011

Please sign in to comment.