Skip to content
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

CRLF to LF line ending conversion is applied depending on whether body is ASCII-only or not. #1614

Open
manueljacob opened this issue Jul 27, 2024 · 0 comments

Comments

@manueljacob
Copy link

I was debugging an error in a test suite that does checks on mails sent by ActionMailer. Mail::Body#to_s returned lines with LF or CRLF line endings depending on whether the body was ASCII-only or not. I tracked it down to the following:

Mail::Body.new("test a\r\n").to_s # => "test a\n"
Mail::Body.new("test ä\r\n").to_s # => "test ä\r\n"

The first line uses Mail::Encodings::SevenBit, which converts line endings, while the second line uses Mail::Encodings::EightBit, which does not. Commit f8b57f6 changed Mail::Encodings::EightBit to stop converting line endings. Although #1325 reports similar symptoms, it appears to be a different issue, as that one was introduced between versions 2.7.0 and 2.7.1.

Is this the intended behavior?

For my use case, it would be beneficial if there was a way to get the e-mail body with consistent line endings (probably LF) regardless of whether the body happens to contain a non-ASCII character or not. It seems to me like a better heuristic whether to convert line endings would be whether the content type is “text”.

In my test suite, there are instances of Mail::Message (returned by ActionMailer::Base.deliveries.last), on which I call .body.to_s. That’s probably anyway not quite what I want, as it doesn’t take into account the charset of the body. There is Mail::Message#decode_body_as_text, which is probably what I should use instead. It seems like that method would be a good place to apply the CRLF to LF conversion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant