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

Split on an exact \r\n\r\n sequence if it exists #501

Merged
merged 1 commit into from Feb 12, 2013
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/mail/message.rb
Expand Up @@ -1889,7 +1889,7 @@ def text?
# Additionally, I allow for the case where someone might have put whitespace # Additionally, I allow for the case where someone might have put whitespace
# on the "gap line" # on the "gap line"
def parse_message def parse_message
header_part, body_part = raw_source.lstrip.split(/#{CRLF}#{WSP}*#{CRLF}(?!#{WSP})/m, 2) header_part, body_part = raw_source.lstrip.split(/#{CRLF}#{CRLF}|#{CRLF}#{WSP}*#{CRLF}(?!#{WSP})/m, 2)
self.header = header_part self.header = header_part
self.body = body_part self.body = body_part
end end
Expand Down
38 changes: 38 additions & 0 deletions spec/mail/message_spec.rb
Expand Up @@ -189,6 +189,44 @@ def basic_email
deserialized.parts.map(&:body).should == ['body', '<b>body</b>'] deserialized.parts.map(&:body).should == ['body', '<b>body</b>']
end end
end end

describe "splitting" do
it "should split the body from the header" do
message = Mail::Message.new("To: Example <example@cirw.in>\r\n\r\nHello there\r\n")
message.decoded.should == "Hello there\n"
end

it "should split when the body starts with a space" do
message = Mail::Message.new("To: Example <example@cirw.in>\r\n\r\n Hello there\r\n")
message.decoded.should == " Hello there\n"
end

it "should split if the body starts with an empty line" do
message = Mail::Message.new("To: Example <example@cirw.in>\r\n\r\n\r\nHello there\r\n")
message.decoded.should == "\nHello there\n"
end

it "should split if the body starts with a blank line" do
message = Mail::Message.new("To: Example <example@cirw.in>\r\n\r\n\t\r\nHello there\r\n")
message.decoded.should == "\t\nHello there\n"
end

it 'should split after headers that contain "\r\n "' do
message = Mail::Message.new("To: Example\r\n <example@cirw.in>\r\n\r\n Hello there\r\n")
message.decoded.should == " Hello there\n"
end

it 'should split 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\n"
end

# N.B. this is not in any RFCs
it "should split on a line with whitespace on it" do
message = Mail::Message.new("To: Example <example@cirw.in>\r\n \r\nHello there\r\n")
message.decoded.should == "Hello there\n"
end
end
end end


describe "envelope line handling" do describe "envelope line handling" do
Expand Down