Closed martin-jahn closed 2 years ago
@martin-jahn are you able to PR a failing test case? One of the DY engineers just tried to reproduce and could not.
Sure, I'll write that later today.
@martin-jahn #139 passes against the master branch. It is not a failing test case?
After I've made another commit now it passes. Although test decode removes <CR><LF> pairs (Mail.Encoders.SevenBitTest)
is failing. I don't understand why it works that way so I'd be glad to know what kind of reasoning is behind removing newline characters from messages. Because that test to me looks like it expects exact opposite to what the code is supposed to do. I know emails are weird so please don't take this as an attack to this project in any way.
@martin-jahn are you on Windows or using emails generated from Windows?
I'm not on Windows it's on Ubuntu 21.04. I've tested Elixir 1.10-1.13 and Erlang 22-24. Every time there's the same result. You literally have that in your tests as expected behaviour. This is a snippet from tests in this project. I can't even imagine why this would be a good idea. Because I would expect the result to be "This is a \ntest\n"
.
test "decode removes <CR><LF> pairs" do
message = "This is a \r\ntest\r\n"
assert Mail.Encoders.SevenBit.decode(message) == "This is a test"
end
Just for clarification I've downloaded the email from straight from gmail and Thunderbird. As every old enough internet standard email as well uses \r\n
for new lines. The file in the PR contains those as well. That email was generated in Python 3, sent to Zoho and delivered to gmail. Nowhere along the way was there any problem with how that email was displayed. I also have problem with email sent by a customer from Outlook in production. But that email can't be shared for obvious reasons.
Just to make sure you know, I've modified #139 so that my test passes but it breaks test in the snippet above.
I'm sorry I forgot to attach Python script which could be used to generate your own emails. Please run it under Python 3. I've used 3.9.5 but my guess would be that even 3.5 should work just as good.
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# me == my email address
# you == recipient's email address
sender = "customer@example.com"
recipient = "company@example.org"
# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = "Stuff"
msg['From'] = sender
msg['To'] = recipient
# Create the body of the message (a plain-text and an HTML version).
text = "Hello Joe\nThis is a receipt from ACME incorporated\n\nDate: 10/21/2021\n\nTotal: $128.53\n\nPayment Method\n------------------------------------------------------\nCredit Card\n\nVisa 7139\n\n\nThanks for your purchase Joe\n\nACME inc.\n"
part1 = MIMEText(text, 'plain')
msg.attach(part1)
# Send the message via local SMTP server.
mail = smtplib.SMTP_SSL('smtppro.zoho.eu', 465)
mail.ehlo()
mail.login('customer@example.com', 'secret password')
mail.sendmail(sender, recipient, msg.as_string())
mail.quit()
@martin-jahn RFC 2045 §2.7 explicitly states that \r\n
is used to separate longer lines, i.e. in decoding, they are removed and the longer lines joined together.
The code that removes the \r\n
is explicit and can be seen here: https://github.com/DockYard/elixir-mail/blob/fa9ddf50ddc94cbb19e581873d4d7991ea5fdac0/lib/mail/encoders/seven_bit.ex#L49
I don’t believe there is a problem with how we are handling this situation.
@martin-jahn considering @andrewtimberlake's comment I'll close for now. If you feel this is still an issue please let us know and I can reopen to discuss
Version
0.2.3
Test Case
Steps to reproduce
Email was created in a python script. This is nothing unusual about this. It can be done by any online service using python in a backend system. Parsing this email results in lost newline characters. I've tried to send this email with
\r\n
and\n
newline characters but it didn't work in both cases. Since I've been using Python standard library my guess is your library has an issue.Email content has been downloaded from gmail and thunderbird interfce. Both times it caused the same error. Email is showing correctly in gmail, thunderbird and zoho web interface.
Expected Behavior
Actual Behavior