Skip to content

[Mailer] [Scaleway] Fix attachment handling #53653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Mailer\Exception\HttpTransportException;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Part\DataPart;
use Symfony\Contracts\HttpClient\ResponseInterface;

class ScalewayApiTransportTest extends TestCase
Expand Down Expand Up @@ -64,6 +65,10 @@ public function testSend()
$this->assertSame(['email' => 'saif.gmati@symfony.com', 'name' => 'Saif Eddin'], $body['to'][0]);
$this->assertSame('Hello!', $body['subject']);
$this->assertSame('Hello There!', $body['text']);
$this->assertCount(1, $body['attachments']);
$this->assertSame('attachment.txt', $body['attachments'][0]['name']);
$this->assertSame('text/plain', $body['attachments'][0]['type']);
$this->assertSame(base64_encode('some attachment'), $body['attachments'][0]['content']);

return new JsonMockResponse(['emails' => [['message_id' => 'foobar']]], [
'http_code' => 200,
Expand All @@ -76,7 +81,8 @@ public function testSend()
$mail->subject('Hello!')
->to(new Address('saif.gmati@symfony.com', 'Saif Eddin'))
->from(new Address('fabpot@symfony.com', 'Fabien'))
->text('Hello There!');
->text('Hello There!')
->addPart(new DataPart('some attachment', 'attachment.txt', 'text/plain'));

$message = $transport->send($mail);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private function getPayload(Email $email, Envelope $envelope): array
$payload['html'] = $email->getHtmlBody();
}
if ($attachements = $this->prepareAttachments($email)) {
$payload['attachment'] = $attachements;
$payload['attachments'] = $attachements;
}

return $payload;
Expand All @@ -115,7 +115,7 @@ private function prepareAttachments(Email $email): array
$attachments[] = [
'name' => $filename,
'type' => $headers->get('Content-Type')->getBody(),
'content' => base64_encode($attachment->bodyToString()),
'content' => str_replace("\r\n", '', $attachment->bodyToString()),
];
}

Expand Down