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

quoted-printable encoding fails to escape email-ending periods #954

Closed
indirect opened this issue Jan 12, 2016 · 1 comment
Closed

quoted-printable encoding fails to escape email-ending periods #954

indirect opened this issue Jan 12, 2016 · 1 comment

Comments

@indirect
Copy link

The SMTP standard uses \r\n.\r\n (a period on a line by itself) to indicate "end of message". While using Mail::Part (via ActionMailer), I discovered that Mail::Part#encode does not escape lines that consist of a single period on a line by itself, which causes the receiving SMTP server to cut the email short.

Here's example code that reproduces the issue:

html_body = "<p>This is HTML and it can have linebreaks anywhere, which this will have.
This is the next sentence, but it's too late. Everything on this line and after will be rejected by the server.</h1>"

def create_mail(html_body)
  mail = Mail.new do
    to      'nicolas@test.lindsaar.net.au'
    from    'Mikel Lindsaar <mikel@test.lindsaar.net.au>'
    subject 'First multipart email sent with Mail'
    content_type 'text/html; charset=UTF-8'
    body html_body
  end
  mail.transport_encoding = 'quoted-printable'
  mail
end

puts create_mail(html_body).encoded

The resulting output includes these lines:

Content-Transfer-Encoding: quoted-printable

<p>This is HTML and it can have linebreaks anywhere, which this will have=
.
This is the next sentence, but it's too late. Everything on this line and=
 after will be rejected by the server.</h1>=

As mentioned in said output, the second half of the content of the email cannot be delivered, because the server rejects all lines after the first line containing nothing but a single period.

In order to implement quoted-printable encoding in a way that can be transmitted over SMTP, the Mail::Part#encode method needs to escape lines containing nothing but a period by adding another period to the beginning of the line. Two periods are interpreted as a single period that does not end the email according to rfc5321 section 4.5.2.

@jeremy
Copy link
Collaborator

jeremy commented May 17, 2017

"Dot stuffing" is the responsibility of the SMTP client. Ruby Net::SMTP has had some bugs with this: https://bugs.ruby-lang.org/issues/9627

Worked around this one in Mail as part of SMTP delivery: #683

@jeremy jeremy closed this as completed May 17, 2017
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

2 participants