Permalink
Browse files

Fix that setting an attachment with a :mime_type and :encoding would …

…override the :encoding

Fixes #123
  • Loading branch information...
1 parent 3fb6143 commit 832cfccd9685192b0597445a122f2ab7efccb51f @jeremy jeremy committed Jan 26, 2013
Showing with 9 additions and 1 deletion.
  1. +1 −0 CHANGELOG.rdoc
  2. +1 −1 lib/mail/attachments_list.rb
  3. +7 −0 spec/mail/attachments_list_spec.rb
View
@@ -10,6 +10,7 @@ Performance:
* Close pull request 488 - Speed up field construction & comparison (bpot)
Bugs:
+* Fix that setting an attachment with a :mime_type and :encoding would override the :encoding (jeremy)
* Fix that declaring an html_part but no text_part would use multipart/alternative anyway (jeremy)
* Close pull request 487 - Extract comments from group email addresses (bpot)
* Close pull request 481 - Correctly quote filename attributes (bpot)
@@ -60,7 +60,7 @@ def []=(name, value)
if value[:mime_type]
default_values[:content_type] = value.delete(:mime_type)
@mime_type = MIME::Types[default_values[:content_type]].first
- default_values[:content_transfer_encoding] = guess_encoding
+ default_values[:content_transfer_encoding] ||= guess_encoding
end
hash = default_values.merge(value)
@@ -99,6 +99,13 @@ def check_decoded(actual, expected)
check_decoded(@mail.attachments[0].decoded, file_data)
end
+ it "should allow you set a mime type and encoding without overriding the encoding" do
+ encoded = encode_base64('<foo/>')
+ @mail.attachments['test.png'] = { :mime_type => 'text/xml', :content => encoded, :encoding => 'base64' }
+ @mail.attachments[0].content_transfer_encoding.should eq 'base64'
+ check_decoded(@mail.attachments[0].decoded, '<foo/>')
+ end
+
it "should not allow you to pass in an encoded attachment with an unknown encoding" do
file_data = File.read(fixture('attachments', 'test.png'))
base64_encoded_data = encode_base64(file_data)

0 comments on commit 832cfcc

Please sign in to comment.