diff --git a/lib/mail/body.rb b/lib/mail/body.rb index 53257c52e..911a0bc03 100644 --- a/lib/mail/body.rb +++ b/lib/mail/body.rb @@ -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 diff --git a/lib/mail/constants.rb b/lib/mail/constants.rb index 0436d1413..14a4334f8 100644 --- a/lib/mail/constants.rb +++ b/lib/mail/constants.rb @@ -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 diff --git a/lib/mail/field.rb b/lib/mail/field.rb index 9e784f667..1ff4700aa 100644 --- a/lib/mail/field.rb +++ b/lib/mail/field.rb @@ -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 diff --git a/lib/mail/message.rb b/lib/mail/message.rb index 6d5ae19a6..b299d31fc 100644 --- a/lib/mail/message.rb +++ b/lib/mail/message.rb @@ -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 @@ -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 @@ -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 diff --git a/lib/mail/part.rb b/lib/mail/part.rb index 9d7881f3e..4329d587f 100644 --- a/lib/mail/part.rb +++ b/lib/mail/part.rb @@ -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 diff --git a/spec/fixtures/emails/attachment_emails/attachment_pdf.eml b/spec/fixtures/emails/attachment_emails/attachment_pdf.eml index 1fd2ed7a1..3c01ff1b2 100644 --- a/spec/fixtures/emails/attachment_emails/attachment_pdf.eml +++ b/spec/fixtures/emails/attachment_emails/attachment_pdf.eml @@ -29,7 +29,7 @@ Date: Tue, 10 May 2005 11:26:39 -0600 From: Test Tester Reply-To: Test Tester To: xxxx@xxxx.com, xxxx@xxxx.com -Subject: Another PDF +Subject: Another PDF with 🎉 Unicode chars in it 🍿 Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_2192_32400445.1115745999735" diff --git a/spec/fixtures/emails/attachment_emails/attachment_pdf_lf.eml b/spec/fixtures/emails/attachment_emails/attachment_pdf_lf.eml index 771a96350..fb4718f22 100644 --- a/spec/fixtures/emails/attachment_emails/attachment_pdf_lf.eml +++ b/spec/fixtures/emails/attachment_emails/attachment_pdf_lf.eml @@ -29,7 +29,7 @@ Date: Tue, 10 May 2005 11:26:39 -0600 From: Test Tester Reply-To: Test Tester To: xxxx@xxxx.com, xxxx@xxxx.com -Subject: Another PDF +Subject: Another PDF with 🎉 Unicode chars in it 🍿 Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_2192_32400445.1115745999735"