Skip to content

[Mailer] Fix attachment content encoding for SendgridTransport #32645

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

Closed
wants to merge 1 commit into from
Closed
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 @@ -113,9 +113,11 @@ private function getAttachments(Email $email): array
$headers = $attachment->getPreparedHeaders();
$filename = $headers->getHeaderParameter('Content-Disposition', 'filename');
$disposition = $headers->getHeaderBody('Content-Disposition');
// Sendgrid does not accept line breaks for base64 encoded attachments
$content = 'base64' === $attachment->getEncoding() ? base64_encode($attachment->getBody()) : $attachment->bodyToString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like bypassing the encoding abstraction
can't we instead decide for the encoding earlier? (a line-break-less variant of base64)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have a specific base64 encoder, but it can’t be done earlier since the email is not aware of the transport. The transport would have to set the encoder on each attachment (DataPart instance) at send time


$att = [
'content' => $attachment->bodyToString(),
'content' => $content,
'type' => $headers->get('Content-Type')->getBody(),
'filename' => $filename,
'disposition' => $disposition,
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Mailer/Bridge/Sendgrid/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
"require-dev": {
"symfony/http-client": "^4.3"
},
"conflict": {
"symfony/mime": "<4.3.3"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Mailer\\Bridge\\Sendgrid\\": "" },
"exclude-from-classmap": [
Expand Down
8 changes: 8 additions & 0 deletions src/Symfony/Component/Mime/Part/TextPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ public function getPreparedHeaders(): Headers
return $headers;
}

/**
* @internal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't make sense to me to have an internal method for cross component uses
if we think this is a needed API, we should commit to it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm against making this public, that leaks internal information I don't want to expose.

*/
public function getEncoding(): string
{
return $this->encoding;
}

private function getEncoder(): ContentEncoderInterface
{
if ('8bit' === $this->encoding) {
Expand Down