Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 812d7a9

Browse files
madbobnicolas-grekas
authored andcommitted
[Mailer] [Scaleway] Fix attachment handling
1 parent 0294563 commit 812d7a9

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/Symfony/Component/Mailer/Bridge/Scaleway/Tests/Transport/ScalewayApiTransportTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Mailer\Exception\HttpTransportException;
1919
use Symfony\Component\Mime\Address;
2020
use Symfony\Component\Mime\Email;
21+
use Symfony\Component\Mime\Part\DataPart;
2122
use Symfony\Contracts\HttpClient\ResponseInterface;
2223

2324
class ScalewayApiTransportTest extends TestCase
@@ -64,6 +65,10 @@ public function testSend()
6465
$this->assertSame(['email' => '[email protected]', 'name' => 'Saif Eddin'], $body['to'][0]);
6566
$this->assertSame('Hello!', $body['subject']);
6667
$this->assertSame('Hello There!', $body['text']);
68+
$this->assertCount(1, $body['attachments']);
69+
$this->assertSame('attachment.txt', $body['attachments'][0]['name']);
70+
$this->assertSame('text/plain', $body['attachments'][0]['type']);
71+
$this->assertSame(base64_encode('some attachment'), $body['attachments'][0]['content']);
6772

6873
return new JsonMockResponse(['emails' => [['message_id' => 'foobar']]], [
6974
'http_code' => 200,
@@ -76,7 +81,8 @@ public function testSend()
7681
$mail->subject('Hello!')
7782
->to(new Address('[email protected]', 'Saif Eddin'))
7883
->from(new Address('[email protected]', 'Fabien'))
79-
->text('Hello There!');
84+
->text('Hello There!')
85+
->addPart(new DataPart('some attachment', 'attachment.txt', 'text/plain'));
8086

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

src/Symfony/Component/Mailer/Bridge/Scaleway/Transport/ScalewayApiTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private function getPayload(Email $email, Envelope $envelope): array
9999
$payload['html'] = $email->getHtmlBody();
100100
}
101101
if ($attachements = $this->prepareAttachments($email)) {
102-
$payload['attachment'] = $attachements;
102+
$payload['attachments'] = $attachements;
103103
}
104104

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

0 commit comments

Comments
 (0)