Skip to content

Commit d1213e0

Browse files
committed
fix: address PR review comments
- Add email validation in Recipient constructor to reject empty strings - Fix Mailgun address format to use RFC 5322 compliant "Name <email>" with a space before the angle bracket, consistent with Resend adapter
1 parent 842c112 commit d1213e0

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/Utopia/Messaging/Adapter/Email/Mailgun.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected function process(EmailMessage $message): array
5656
$body = [
5757
'to' => \implode(',', \array_map(
5858
fn ($to) => !empty($to->getName())
59-
? "{$to->getName()}<{$to->getEmail()}>"
59+
? "{$to->getName()} <{$to->getEmail()}>"
6060
: $to->getEmail(),
6161
$message->getTo()
6262
)),
@@ -74,7 +74,7 @@ protected function process(EmailMessage $message): array
7474
if (!\is_null($message->getCC())) {
7575
foreach ($message->getCC() as $cc) {
7676
$ccString = !empty($cc->getName())
77-
? "{$cc->getName()}<{$cc->getEmail()}>"
77+
? "{$cc->getName()} <{$cc->getEmail()}>"
7878
: $cc->getEmail();
7979

8080
$body['cc'] = !empty($body['cc'])
@@ -86,7 +86,7 @@ protected function process(EmailMessage $message): array
8686
if (!\is_null($message->getBCC())) {
8787
foreach ($message->getBCC() as $bcc) {
8888
$bccString = !empty($bcc->getName())
89-
? "{$bcc->getName()}<{$bcc->getEmail()}>"
89+
? "{$bcc->getName()} <{$bcc->getEmail()}>"
9090
: $bcc->getEmail();
9191

9292
$body['bcc'] = !empty($body['bcc'])

src/Utopia/Messaging/Messages/Email/Recipient.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ public function __construct(
88
private string $email,
99
private string $name = '',
1010
) {
11+
if (empty($email)) {
12+
throw new \InvalidArgumentException('Recipient email must not be empty.');
13+
}
1114
}
1215

1316
public function getEmail(): string

0 commit comments

Comments
 (0)