Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixing #408 by not standarizing whitespace #609

Open
wants to merge 2 commits into from

2 participants

@malmckay

There may be a better fix, that can standardize line breaks that are outside of the binary blob, but I feel this is a good step forward

Parsing binary encoded attachments still fails for most jpgs in 1.8.7 (1.9+ is fine). Without this patch most binary encoded attachments fail in all versions, so, again, I feel this is good step forward.

PS This is a repeat pull request, my previous one was from HEAD, which included other commits

malmckay added some commits
@malmckay malmckay Fixing #408 by not standarizing whitespace
There may be a better fix, that can standardize whitespace outside of the binary blob, but I feel this is a good step forward
dc89eb1
@malmckay malmckay SPECFIX jpg attachments fail in 1.8.7 0f49c4e
@ConradIrwin
Collaborator

@malmckay What does this do to nominally plain-text emails that have been sent with a Binary content-type but with "\n" as a line-break? Do we actually want to look at the content type as well?

@malmckay

@ConradIrwin Good point. I looked at that in a slightly different way: If content-type is text and transfer-encoding is binary should we standardize line-breaks in the email body to CRLF?

I think not. Mail.gem's parsing (by this point) is not affected, and I don't believe Mail.gem users should assume CRLF for the body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 19, 2013
  1. @malmckay

    Fixing #408 by not standarizing whitespace

    malmckay authored
    There may be a better fix, that can standardize whitespace outside of the binary blob, but I feel this is a good step forward
  2. @malmckay
This page is out of date. Refresh to see the latest.
View
6 lib/mail/message.rb
@@ -1975,7 +1975,11 @@ def parse_message
def raw_source=(value)
value.force_encoding("binary") if RUBY_VERSION >= "1.9.1"
- @raw_source = value.to_crlf
+ if value.include?("Content-Transfer-Encoding: binary")
+ @raw_source = value
+ else
+ @raw_source = value.to_crlf
+ end
end
# see comments to body=. We take data and process it lazily
View
24 spec/fixtures/emails/mime_emails/raw_email_with_binary_encoded.eml
@@ -0,0 +1,24 @@
+From email_test@me.nowhere
+Return-Path: <email_test@me.nowhere>
+Received: from omta05sl.mx.bigpond.com by me.nowhere.else with ESMTP id 632BD5758 for <mikel@me.nowhere.else>; Sun, 21 Oct 2007 19:38:21 +1000
+Received: from oaamta05sl.mx.bigpond.com by omta05sl.mx.bigpond.com with ESMTP id <20071021093820.HSPC16667.omta05sl.mx.bigpond.com@oaamta05sl.mx.bigpond.com> for <mikel@me.nowhere.else>; Sun, 21 Oct 2007 19:38:20 +1000
+Received: from mikel091a by oaamta05sl.mx.bigpond.com with SMTP id <20071021093820.JFMT24025.oaamta05sl.mx.bigpond.com@mikel091a> for <mikel@me.nowhere.else>; Sun, 21 Oct 2007 19:38:20 +1000
+Date: Sun, 21 Oct 2007 19:38:13 +1000
+From: Mikel Lindsaar <email_test@me.nowhere>
+Reply-To: Mikel Lindsaar <email_test@me.nowhere>
+To: mikel@me.nowhere
+Message-Id: <009601c813c6$19df3510$0437d30a@mikel091a>
+Subject: Testing outlook
+Subject: Another PDF
+Mime-Version: 1.0
+Content-Type: multipart/alternative;
+ boundary=----=_Part_13069834_15179892.1376435426074
+
+
+------=_Part_13069834_15179892.1376435426074
+Content-Type: image/jpeg; name=2013-08-13_19-08-28-1.jpg
+Content-Transfer-Encoding: binary
+Content-Location: 2013-08-13_19-08-28-1.jpg
+
+BINARY_CONTENT_GOES_HERE
+------=_Part_13069834_15179892.1376435426074--
View
17 spec/mail/mime_messages_spec.rb
@@ -373,6 +373,23 @@
mail.attachments[1].filename.should eq 'smime.p7s'
end
+ Dir.glob(fixture('attachments', "test.*")).each do |test_attachment|
+ # This spec fails for (most?) jpegs in 1.8.7
+ next if test_attachment.end_with?('test.jpg')
+
+ it "should find binary encoded attachments of type #{File.extname(test_attachment)}" do
+ raw_mail = File.open(fixture('emails', 'mime_emails', 'raw_email_with_binary_encoded.eml'), 'rb').read
+ raw_file = File.open(test_attachment, "rb").read
+ p1, p2 = raw_mail.split('BINARY_CONTENT_GOES_HERE')
+
+ mail_with_file = p1 + raw_file + p2
+
+ mail = Mail.read_from_string(mail_with_file)
+ # mail.attachments.first.decoded.should eq raw_file
+ # Test size, not content. Testing content makes for very ugly spec failures
+ mail.attachments.first.decoded.size.should eq raw_file.size
+ end
+ end
end
describe "adding a file attachment" do
Something went wrong with that request. Please try again.