Skip to content

Commit

Permalink
Restore LF line ending parsing
Browse files Browse the repository at this point in the history
References #1208
  • Loading branch information
jeremy committed Mar 1, 2018
1 parent 93e811c commit 6a019d5
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/mail/body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def initialize(string = '')
else
# Do join first incase we have been given an Array in Ruby 1.9
if string.respond_to?(:join)
@raw_source = string.join('')
@raw_source = ::Mail::Utilities.to_crlf(string.join(''))
elsif string.respond_to?(:to_s)
@raw_source = string.to_s
@raw_source = ::Mail::Utilities.to_crlf(string.to_s)
else
raise "You can only assign a string or an object that responds_to? :join or :to_s to a body."
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mail/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Constants
control = control.dup.force_encoding(Encoding::BINARY)
end

CRLF = /\r\n/
CRLF = /\r?\n/
WSP = /[#{white_space}]/
FWS = /#{CRLF}#{WSP}*/
TEXT = /[#{text}]/ # + obs-text
Expand Down
2 changes: 1 addition & 1 deletion lib/mail/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def field_class_for(name)
# treated in its unfolded form for further syntactic and semantic
# evaluation.
def unfold(string)
string.gsub(/#{CRLF}(#{WSP})/m, '\1')
string.gsub(/#{Constants::CRLF}(#{Constants::WSP})/m, '\1')
end
end
end
6 changes: 3 additions & 3 deletions lib/mail/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1984,7 +1984,7 @@ def text?

private

HEADER_SEPARATOR = /#{CRLF}#{CRLF}/
HEADER_SEPARATOR = /#{Constants::CRLF}#{Constants::CRLF}/

# 2.1. General Description
# A message consists of header fields (collectively called "the header
Expand All @@ -2000,7 +2000,7 @@ def parse_message
end

def raw_source=(value)
@raw_source = ::Mail::Utilities.to_crlf(value)
@raw_source = value
end

# see comments to body=. We take data and process it lazily
Expand Down Expand Up @@ -2029,7 +2029,7 @@ def process_body_raw

def set_envelope_header
raw_string = raw_source.to_s
if match_data = raw_string.match(/\AFrom\s(#{TEXT}+)#{CRLF}/m)
if match_data = raw_string.match(/\AFrom\s(#{TEXT}+)#{Constants::CRLF}/m)
set_envelope(match_data[1])
self.raw_source = raw_string.sub(match_data[0], "")
end
Expand Down
4 changes: 2 additions & 2 deletions lib/mail/part.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def get_return_values(key)

# A part may not have a header.... so, just init a body if no header
def parse_message
header_part, body_part = raw_source.split(/#{CRLF}#{WSP}*#{CRLF}/m, 2)
if header_part =~ HEADER_LINE
header_part, body_part = raw_source.split(/#{Constants::CRLF}#{Constants::WSP}*#{Constants::CRLF}/m, 2)
if header_part =~ Constants::HEADER_LINE
self.header = header_part
self.body = body_part
else
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/emails/attachment_emails/attachment_pdf.eml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Date: Tue, 10 May 2005 11:26:39 -0600
From: Test Tester <[email protected]>
Reply-To: Test Tester <[email protected]>
To: [email protected], [email protected]
Subject: Another PDF
Subject: Another PDF with 🎉 Unicode chars in it 🍿
Mime-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_2192_32400445.1115745999735"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Date: Tue, 10 May 2005 11:26:39 -0600
From: Test Tester <[email protected]>
Reply-To: Test Tester <[email protected]>
To: [email protected], [email protected]
Subject: Another PDF
Subject: Another PDF with 🎉 Unicode chars in it 🍿
Mime-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_2192_32400445.1115745999735"
Expand Down

0 comments on commit 6a019d5

Please sign in to comment.