Skip to content

Commit 28cf730

Browse files
committed
Revert to original encoder and rescue
Another alternative spec-passing change
1 parent 483abcc commit 28cf730

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

lib/mapi/mime.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,13 @@ def to_s opts={}
106106
opts = {:boundary_counter => 0}.merge opts
107107
if multipart?
108108
boundary = Mime.make_boundary opts[:boundary_counter] += 1, self
109-
@body = [preamble, parts.map { |part| "\r\n" + part.to_s(opts) + "\r\n" }, "--\r\n" + epilogue].
110-
flatten.join("\r\n--" + boundary)
109+
begin
110+
@body = [preamble, parts.map { |part| "\r\n" + part.to_s(opts) + "\r\n" }, "--\r\n" + epilogue].
111+
flatten.join("\r\n--" + boundary)
112+
rescue Encoding::CompatibilityError
113+
@body = [preamble, parts.map { |part| "\r\n" + part.to_s(opts).force_encoding('ASCII-8BIT') + "\r\n" }, "--\r\n" + epilogue].
114+
flatten.join("\r\n--" + boundary)
115+
end
111116
content_type, attrs = Mime.split_header @headers['Content-Type'][0]
112117
attrs['boundary'] = boundary
113118
@headers['Content-Type'] = [([content_type] + attrs.map { |key, val| %{#{key}="#{val}"} }).join('; ')]

lib/mapi/msg.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class PropertyStore
101101
# change these to use mapi symbolic const names
102102
ENCODINGS = {
103103
0x000d => proc { |obj| obj }, # seems to be used when its going to be a directory instead of a file. eg nested ole. 3701 usually. in which case we shouldn't get here right?
104-
0x001f => proc { |obj| Ole::Types::FROM_UTF16.iconv(obj.read).force_encoding('ASCII-8BIT') }, # unicode
104+
0x001f => proc { |obj| Ole::Types::FROM_UTF16.iconv obj.read }, # unicode
105105
# ascii
106106
# FIXME hack did a[0..-2] before, seems right sometimes, but for some others it chopped the text. chomp
107107
0x001e => proc { |obj| obj.read.chomp 0.chr },

0 commit comments

Comments
 (0)