Skip to content

Commit

Permalink
Merge pull request #31 from narendravaghela/issue-24
Browse files Browse the repository at this point in the history
Fixes #24
  • Loading branch information
challgren authored Dec 18, 2019
2 parents e49aba8 + 948fe3b commit 834d2fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
25 changes: 10 additions & 15 deletions src/Mailer/Transport/MailgunTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,7 @@ public function send(Email $email)
}

try {
$apiResponse = $this->_sendEmail();
$res = ['apiResponse' => $apiResponse];

if (Configure::read('debug')) {
$res['reqData'] = $this->_formData;
}

return $res;
return $this->_sendEmail();
} finally {
$this->_reset();
}
Expand Down Expand Up @@ -382,7 +375,15 @@ protected function _sendEmail()
'headers' => ['Content-Type' => $this->_formData->contentType()],
]);

return $response->getJson();
$result = [];
$result['apiResponse'] = $response->getJson();
$result['responseCode'] = $response->getStatusCode();

if (Configure::read('debug')) {
$result['reqData'] = $this->_formData;
}

return $result;
}

/**
Expand Down Expand Up @@ -421,19 +422,13 @@ protected function _processHeaders(Email $email)
$var = $this->_mailgunHeaders[$header];
if (is_string($value)) {
$value = json_decode($value);
if (json_last_error() === JSON_ERROR_NONE && is_string($value)) {
$value = explode(',', $value);
}
}
$this->_formData->add("{$this->_optionPrefix}$var", $value);
} else {
$var = $this->_mailgunHeaders[$header];
$this->_formData->add("{$this->_optionPrefix}$var", $value);
}
}
if (0 === strpos($header, $this->_customHeaderPrefix) && !empty($value)) {
$this->_formData->add($header, $value);
}
}
}
}
4 changes: 2 additions & 2 deletions tests/TestCase/Mailer/Transport/MailgunTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ public function testInvalidApiKey()
{
$this->_setBlankApiEmailConfig();
$res = $this->_sendEmail();
$apiResponse = $res['apiResponse'];

$this->assertNull($apiResponse);
$this->assertNull($res['apiResponse']);
$this->assertSame(401, $res['responseCode']);
}

public function testInvalidDomainKey()
Expand Down

0 comments on commit 834d2fc

Please sign in to comment.