Skip to content

[Mime] QpContentEncoder removes intentional line break #49295

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
fforsthuber opened this issue Feb 8, 2023 · 7 comments
Closed

[Mime] QpContentEncoder removes intentional line break #49295

fforsthuber opened this issue Feb 8, 2023 · 7 comments

Comments

@fforsthuber
Copy link

fforsthuber commented Feb 8, 2023

Symfony version(s) affected

6.2.5

Description

[symfony/mime] QpContentEncoder removes intentional line break

Under certain conditions Symfony\Component\Mime\Encoder\QpContentEncoder seems to remove an intentional line break in the rendered email body.
When i set the the body text via Symfony\Component\Mime\Email::text() with the following value:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaa

i receive the follwing rendered email body:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

The raw quoted printable text will be:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa=

aaaaaaaaaaaaaaaaaaaaaaaaa

I would expect that the line break here is rendered as it was placed in the Email::text() argument.

Thanks for your support

How to reproduce

To reproduce the issue i prepared a setup with mailhog:
https://github.com/fforsthuber/sf-mailer-line-break-problem

See README for setup

Possible Solution

No response

Additional Context

No response

@fforsthuber
Copy link
Author

If i remove this line:
https://github.com/symfony/mime/blob/6.2/Encoder/QpContentEncoder.php#L45
the line break is rendered as expected

@fforsthuber fforsthuber changed the title [symfony/mailer] QpContentEncoder removes intentional line break [symfony/mime] QpContentEncoder removes intentional line break Feb 9, 2023
@dmaicher
Copy link
Contributor

dmaicher commented Feb 9, 2023

https://www.freesoft.org/CIE/RFC/1521/6.htm says

Rule #4 (Line Breaks): A line break in a text body, independent of
what its representation is following the canonical representation
of the data being encoded, must be represented by a (RFC 822) line
break, which is a CRLF sequence, in the Quoted-Printable encoding.
Since the canonical representation of types other than text do not
generally include the representation of line breaks, no hard line
breaks (i.e. line breaks that are intended to be meaningful and
to be displayed to the user) should occur in the quoted-printable
encoding of such types. Of course, occurrences of "=0D", "=0A",
"0A=0D" and "=0D=0A" will eventually be encountered.

So I guess generally that preg_replace seems correct?

@dmaicher
Copy link
Contributor

dmaicher commented Feb 9, 2023

The implementation in swiftmailer looked a bit different: https://github.com/swiftmailer/swiftmailer/blob/master/lib/classes/Swift/Encoder/QpEncoder.php#L279

@dmaicher
Copy link
Contributor

dmaicher commented Feb 9, 2023

Actually I cannot reproduce this issue.

I just tested it via

bin/console mailer:test my@email.com --body=$'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaa'

and the email I receive is

image

@fforsthuber
Copy link
Author

Hmm, that's strange.
Can you reproduce it with the setup i posted ?
The difference is the usage of file_get_contents() to get the email body.
I don't know if that makes a difference

@OskarStark OskarStark changed the title [symfony/mime] QpContentEncoder removes intentional line break [Mime] QpContentEncoder removes intentional line break Feb 10, 2023
@dmaicher
Copy link
Contributor

dmaicher commented Feb 10, 2023

I can also not reproduce this with your php snippet. The email arrives just fine.

image

Raw email:

image

So I don't think there is any issue on Symfony mailer

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@xabbuh xabbuh closed this as not planned Won't fix, can't repro, duplicate, stale Aug 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants