Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ require 'rake/testtask'
require 'rbconfig'
require 'fileutils'

spec = eval File.read('ruby-msg.gemspec')
gemspec_file = File.expand_path(File.dirname(__FILE__) + '/ruby-msg.gemspec')
spec = eval File.read(gemspec_file)

task :default => [:test]

Expand Down
13 changes: 11 additions & 2 deletions lib/mapi/mime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,17 @@ def to_s opts={}
opts = {:boundary_counter => 0}.merge opts
if multipart?
boundary = Mime.make_boundary opts[:boundary_counter] += 1, self
@body = [preamble, parts.map { |part| "\r\n" + part.to_s(opts) + "\r\n" }, "--\r\n" + epilogue].
flatten.join("\r\n--" + boundary)
begin
@body = [preamble, parts.map { |part| "\r\n" + part.to_s(opts) + "\r\n" }, "--\r\n" + epilogue].
flatten.join("\r\n--" + boundary)
rescue Encoding::CompatibilityError => e
if ''.respond_to?(:force_encoding)
@body = [preamble, parts.map { |part| "\r\n" + part.to_s(opts).force_encoding('ASCII-8BIT') + "\r\n" }, "--\r\n" + epilogue].
flatten.join("\r\n--" + boundary)
else
raise e
end
end
content_type, attrs = Mime.split_header @headers['Content-Type'][0]
attrs['boundary'] = boundary
@headers['Content-Type'] = [([content_type] + attrs.map { |key, val| %{#{key}="#{val}"} }).join('; ')]
Expand Down
Binary file added test/small-business-rates-relief.msg
Binary file not shown.
9 changes: 9 additions & 0 deletions test/test_msg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ def test_rendered_string_is_valid_encoding
end
end

def test_multipart_rendered_string_is_valid_encoding
msg = Mapi::Msg.open "#{TEST_DIR}/small-business-rates-relief.msg" do |msg|
string_version = msg.to_mime.to_s
if string_version.respond_to?(:valid_encoding?)
assert_equal true, string_version.valid_encoding?
end
end
end

def test_embedded_msg_renders_as_string
msg = Mapi::Msg.open "#{TEST_DIR}/embedded.msg" do |msg|
assert_match "message/rfc822", msg.to_mime.to_s
Expand Down