Skip to content

Commit

Permalink
Changed guess encoding to short circuit to binary if the mime type is…
Browse files Browse the repository at this point in the history
… unknown, should be safe
  • Loading branch information
mikel committed Mar 28, 2010
1 parent 8ef2a00 commit 21f6df1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/mail/attachments_list.rb
Expand Up @@ -69,8 +69,14 @@ def []=(name, value)
@parts_list << Part.new(hash)
end

# Uses the mime type to try and guess the encoding, if it is a binary type, or unknown, then we
# set it to binary, otherwise as set to plain text
def guess_encoding
@mime_type.binary? ? "binary" : "text"
if @mime_type && !@mime_type.binary?
"7bit"
else
"binary"
end
end

def set_mime_type(filename)
Expand Down
8 changes: 8 additions & 0 deletions spec/mail/attachments_list_spec.rb
Expand Up @@ -63,6 +63,14 @@ def check_decoded(actual, expected)
:mime_type => "application/x-gzip" }
@mail.attachments[0].mime_type.should == 'application/x-gzip'
end

it "should allow you to override the mime_type" do
file_data = File.read(filename = fixture('attachments', 'test.png'))
@mail.attachments['invoice.jpg'] = { :data => "you smiling",
:mime_type => "image/x-jpg",
:transfer_encoding => "base64" }
@mail.attachments[0].mime_type.should == 'image/x-jpg'
end

end

Expand Down

0 comments on commit 21f6df1

Please sign in to comment.