diff --git a/lib/mail.rb b/lib/mail.rb index 5073af7..e0c36b5 100644 --- a/lib/mail.rb +++ b/lib/mail.rb @@ -90,4 +90,5 @@ module Mail # :doc: require 'mail/mail' require 'monkeys/received_element' + require 'monkeys/message' end diff --git a/lib/monkeys/message.rb b/lib/monkeys/message.rb new file mode 100644 index 0000000..c5bc420 --- /dev/null +++ b/lib/monkeys/message.rb @@ -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 diff --git a/spec/fixtures/emails/mime_emails/sig_only_email.eml b/spec/fixtures/emails/mime_emails/sig_only_email.eml index 54a97ad..07af52c 100644 --- a/spec/fixtures/emails/mime_emails/sig_only_email.eml +++ b/spec/fixtures/emails/mime_emails/sig_only_email.eml @@ -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 diff --git a/spec/monkeys/message_spec.rb b/spec/monkeys/message_spec.rb new file mode 100644 index 0000000..b11f049 --- /dev/null +++ b/spec/monkeys/message_spec.rb @@ -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 \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 + message = Mail::Message.new("To: foo\r\n \r\nbody\r\n") + message.decoded.should == 'body' + end + end +end