Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Mailer] Remove line breaks in email attachment content with Sendgrid API#33672

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@fyfey
Copy link

@fyfeyfyfey commentedSep 23, 2019
edited by chalasr
Loading

Line breaks are not allowed in attachment content when sending over the
API.

QA
Branch?4.3
Bug fix?yes
New feature?no
Deprecations?no
TicketsFix#33671,Closes#32645
LicenseMIT
Doc PR

This is a fix for#33671. Send grid's API throws a 400 error when sending email attachments with default base64 encoding.
Removing the line breaks resolves this issue.

$email =newEmail();
$email->from('foo@example.com')
->to('bar@example.com')
->attach('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod','lorem.txt');
Copy link
Member

Choose a reason for hiding this comment

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

There is no line-break in this content, so this is not testing your patch.

Copy link
Member

Choose a reason for hiding this comment

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

@stof it does, line-breaks are added by the MIME-compliant base64 encoder:

return$firstLine.trim(chunk_split($encodedString,$maxLineLength,"\r\n"));

Choose a reason for hiding this comment

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

This is so confusing that we should add a comment before the->attach() method. Something like:

// even it content doesn't include new lines, the Base64 encoding performed later may add them->attach('...)

noniagriconomie reacted with thumbs up emoji
@chalasrchalasr added this to the4.3 milestoneSep 23, 2019
$email =newEmail();
$email->from('foo@example.com')
->to('bar@example.com')
->attach('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod','lorem.txt');

Choose a reason for hiding this comment

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

This is so confusing that we should add a comment before the->attach() method. Something like:

// even it content doesn't include new lines, the Base64 encoding performed later may add them->attach('...)

noniagriconomie reacted with thumbs up emoji
@stof
Copy link
Member

Maybe the actual issue is the usage ofbodyToString on the DataPart, relying on the base64 encoding built for SMTP while this is sent to an HTTP API.

Btw, this may also impact other API providers.

@fabpot
Copy link
Member

@stof is right. We had the same kind of issue withSmtpEnvelope which was optimized for SMTP. We fixed that in 4.4 by renaming it toEnvelope but more importantly moved the SMTP logic to the SMTP classes. Maybe something we need to do here as well. I haven't looked at the code to have an idea on how to do it properly though.

@chalasr
Copy link
Member

The SendGrid HTTP API requires attachments to be base64 encoded though (but with "strict" base64 i.e. no line-break). But API transports could indeed bypass the encoding system and usebase64_encode() directly if needed, that's what I propose in#32645 for the very same bug.

@nicolas-grekasnicolas-grekas changed the titleRemove line breaks in email attachment content.[Mailer] Remove line breaks in email attachment content.Jan 4, 2020
@nicolas-grekasnicolas-grekas changed the title[Mailer] Remove line breaks in email attachment content.[Mailer] Remove line breaks in email attachment contentJan 4, 2020
@nicolas-grekasnicolas-grekas changed the title[Mailer] Remove line breaks in email attachment content[Mailer] Remove line breaks in email attachment content to Sendgrid APIJan 4, 2020
@nicolas-grekasnicolas-grekas changed the title[Mailer] Remove line breaks in email attachment content to Sendgrid API[Mailer] Remove line breaks in email attachment content with Sendgrid APIJan 4, 2020
@nicolas-grekasnicolas-grekasforce-pushed thefix/sendgrid-attachment-content branch fromd329461 toa28a7f9CompareJanuary 4, 2020 12:46
@nicolas-grekas
Copy link
Member

Thank you@fyfey.

nicolas-grekas added a commit that referenced this pull requestJan 4, 2020
…tuart Fyfe)This PR was squashed before being merged into the 4.3 branch.Discussion----------[Mailer] Remove line breaks in email attachment contentLine breaks are not allowed in attachment content when sending over theAPI.| Q             | A| ------------- | ---| Branch?       | 4.3| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       |Fix#33671,Closes#32645| License       | MIT| Doc PR        |This is a fix for#33671. Send grid's API throws a 400 error when sending email attachments with default base64 encoding.Removing the line breaks resolves this issue.Commits-------a28a7f9 [Mailer] Remove line breaks in email attachment content
@nicolas-grekasnicolas-grekas merged commita28a7f9 intosymfony:4.3Jan 4, 2020
This was referencedJan 21, 2020
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@javiereguiluzjaviereguiluzjaviereguiluz left review comments

@stofstofstof left review comments

@chalasrchalasrchalasr left review comments

Assignees

No one assigned

Labels

Projects

None yet

Milestone

4.3

Development

Successfully merging this pull request may close these issues.

6 participants

@fyfey@stof@fabpot@chalasr@nicolas-grekas@javiereguiluz

[8]ページ先頭

©2009-2025 Movatter.jp