Skip to content
This repository has been archived by the owner on Dec 14, 2020. It is now read-only.

Don't split on empty folded headers #4

Merged
merged 3 commits into from
Jul 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/mail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@ module Mail # :doc:
require 'mail/mail'

require 'monkeys/received_element'
require 'monkeys/message'
end
9 changes: 9 additions & 0 deletions lib/monkeys/message.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Mail
class Message
def parse_message
header_part, body_part = raw_source.lstrip.split(/#{CRLF}#{CRLF}|#{CRLF}#{WSP}{2,}#{CRLF}/m, 2)
self.header = header_part
self.body = body_part
end
end
end
1 change: 1 addition & 0 deletions spec/fixtures/emails/mime_emails/sig_only_email.eml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Mime-Version: 1.0
Content-Type: multipart/signed; boundary=Sig_2GIY2xfzqSADMmu9sKGJqWm;
protocol="application/pgp-signature"; micalg=PGP-SHA1


--Sig_2GIY2xfzqSADMmu9sKGJqWm
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: quoted-printable
Expand Down
26 changes: 26 additions & 0 deletions spec/monkeys/message_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'spec_helper'

describe Mail::Message do
describe 'splitting' do
it "doesn't split the message at an empty folded header" do
message = Mail::Message.new("To: foo\r\n \r\nFrom: bar\r\n\r\nbody\r\n")
message.decoded.should == 'body'
end

# Borrowed from
# https://github.com/mikel/mail/commit/a2a45597bce66ebe788cedaaab848a37bd04b25a
it 'splits only once if there are "\r\n\r\n"s in the body' do
message = Mail::Message.new("To: Example <example@cirw.in>\r\n\r\nHello\r\n\r\nthere\r\n")
message.decoded.should == "Hello\n\nthere"
end

# Note: Non RFC Conformant
# http://tools.ietf.org/html/rfc2822#section-3.5
# Added to minimize behaviour differences with 2-4 stable, and to not break
# rspec ./spec/mail/message_spec.rb:274 # Mail::Message accepting a plain text string email should give allow for whitespace on the gap line between header and body
it 'allows 2 or more whitespaces on the gap line between header and body' do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@avinasha Allowing 2 or more whitespaces on the gap line, closer to 2-4 stable which allows 1 or more whitespaces on the gap line. Or should we strictly stick to RFC, and only split on \r\n\r\n?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Importing a corrupt mail is better than not importing, being non strict

message = Mail::Message.new("To: foo\r\n \r\nbody\r\n")
message.decoded.should == 'body'
end
end
end