Skip to content

Commit 9fb9241

Browse files
committed
fix: address PR review comments
- Add error handling for filesize() returning false on unreadable paths - Add error handling for file_get_contents() returning false - Include content_type field in Resend attachment payload
1 parent 51aa16d commit 9fb9241

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ protected function process(EmailMessage $message): array
4242
if ($attachment->getContent() !== null) {
4343
$size += \strlen($attachment->getContent());
4444
} else {
45-
$size += \filesize($attachment->getPath());
45+
$fileSize = \filesize($attachment->getPath());
46+
if ($fileSize === false) {
47+
throw new \Exception('Failed to read attachment file: '.$attachment->getPath());
48+
}
49+
$size += $fileSize;
4650
}
4751
}
4852

@@ -54,12 +58,17 @@ protected function process(EmailMessage $message): array
5458
if ($attachment->getContent() !== null) {
5559
$content = \base64_encode($attachment->getContent());
5660
} else {
57-
$content = \base64_encode(\file_get_contents($attachment->getPath()));
61+
$data = \file_get_contents($attachment->getPath());
62+
if ($data === false) {
63+
throw new \Exception('Failed to read attachment file: '.$attachment->getPath());
64+
}
65+
$content = \base64_encode($data);
5866
}
5967

6068
$attachments[] = [
6169
'filename' => $attachment->getName(),
6270
'content' => $content,
71+
'content_type' => $attachment->getType(),
6372
];
6473
}
6574
}

0 commit comments

Comments
 (0)