Skip to content
Browse files

Minor fixes for ruby 1.9 support.

  • Loading branch information...
1 parent d5c113b commit 8933c26e2bbe8c8780750ce9784211949c97b7a4 @aquasync committed
Showing with 17 additions and 9 deletions.
  1. +3 −3 lib/mapi/convert/note-mime.rb
  2. +2 −2 lib/mapi/msg.rb
  3. +1 −1 lib/mapi/property_set.rb
  4. +11 −3 lib/mapi/rtf.rb
View
6 lib/mapi/convert/note-mime.rb
@@ -81,9 +81,9 @@ def populate_headers
recips_by_type = recipients.group_by { |r| r.type }
# i want to the the types in a specific order.
[:to, :cc, :bcc].each do |type|
- # don't know why i bother, but if we can, we try to sort recipients by the numerical part
- # of the ole name, or just leave it if we can't
- recips = recips_by_type[type]
+ # for maximal (probably pointless) fidelity, we try to sort recipients by the
+ # numerical part of the ole name
+ recips = recips_by_type[type] || []
recips = (recips.sort_by { |r| r.obj.name[/\d{8}$/].hex } rescue recips)
# switched to using , for separation, not ;. see issue #4
# recips.empty? is strange. i wouldn't have thought it possible, but it was right?
View
4 lib/mapi/msg.rb
@@ -193,8 +193,8 @@ def self.parse_nameid obj
pseudo_prop = 0x8000 + offset
named = flags & 1 == 1
prop = if named
- str_off = *str.unpack('V')
- len = *names_data[str_off, 4].unpack('V')
+ str_off = str.unpack('V').first
+ len = names_data[str_off, 4].unpack('V').first
Ole::Types::FROM_UTF16.iconv names_data[str_off + 4, len]
else
a, b = str.unpack('v2')
View
2 lib/mapi/property_set.rb
@@ -249,7 +249,7 @@ def body
# for providing rtf decompression
def body_rtf
return @body_rtf if defined?(@body_rtf)
- @body_rtf = (RTF.rtfdecompr rtf_compressed.read rescue nil)
+ @body_rtf = (RTF.rtfdecompr rtf_compressed.read)# rescue nil)
end
# for providing rtf to html conversion
View
14 lib/mapi/rtf.rb
@@ -2,6 +2,14 @@
require 'strscan'
require 'rtf'
+class StringIO # :nodoc:
+ begin
+ instance_method :getbyte
+ rescue NameError
+ alias getbyte getc
+ end
+end
+
module Mapi
#
# = Introduction
@@ -46,9 +54,9 @@ def rtfdecompr data
flags = nil
while rtf.length < uncompr_size and !io.eof?
# each flag byte flags 8 literals/references, 1 per bit
- flags = ((flag_count += 1) % 8 == 0) ? io.getc : flags >> 1
+ flags = ((flag_count += 1) % 8 == 0) ? io.getbyte : flags >> 1
if 1 == (flags & 1) # each flag bit is 1 for reference, 0 for literal
- rp, l = io.getc, io.getc
+ rp, l = io.getbyte, io.getbyte
# offset is a 12 byte number. 2^12 is 4096, so thats fine
rp = (rp << 4) | (l >> 4) # the offset relative to block start
l = (l & 0xf) + 2 # the number of bytes to copy
@@ -58,7 +66,7 @@ def rtfdecompr data
rp = (rp + 1) % 4096
end
else
- rtf << buf[wp] = io.getc
+ rtf << buf[wp] = io.getbyte.chr
wp = (wp + 1) % 4096
end
end

0 comments on commit 8933c26

Please sign in to comment.
Something went wrong with that request. Please try again.