Skip to content

Commit

Permalink
Halt execution of SendEmail handler if email is not valid
Browse files Browse the repository at this point in the history
  • Loading branch information
rootpd committed Nov 3, 2020
1 parent c0852ff commit 1bc3bd6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Hermes/SendEmailHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
namespace Crm\RempMailerModule\Hermes;

use Crm\RempMailerModule\Models\Api\Client;
use Nette\Utils\Validators;
use Tomaj\Hermes\Handler\HandlerInterface;
use Tomaj\Hermes\Handler\RetryTrait;
use Tomaj\Hermes\MessageInterface;
use Tracy\Debugger;
use Tracy\ILogger;

class SendEmailHandler implements HandlerInterface
{
Expand All @@ -22,6 +25,11 @@ public function handle(MessageInterface $message): bool
{
$payload = $message->getPayload();

if (!Validators::isEmail($payload['email'])) {
Debugger::log('Attempt to send email through REMP Mailer with invalid email address: ' . $payload['email'], ILogger::WARNING);
return false;
}

$this->apiClient->sendEmail(
$payload['email'],
$payload['mail_template_code'],
Expand Down

0 comments on commit 1bc3bd6

Please sign in to comment.