Skip to content

Commit

Permalink
Minor fixes for ruby 1.9 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
aquasync committed Feb 1, 2009
1 parent d5c113b commit 8933c26
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/mapi/convert/note-mime.rb
Expand Up @@ -81,9 +81,9 @@ def populate_headers
recips_by_type = recipients.group_by { |r| r.type } recips_by_type = recipients.group_by { |r| r.type }
# i want to the the types in a specific order. # i want to the the types in a specific order.
[:to, :cc, :bcc].each do |type| [: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 # for maximal (probably pointless) fidelity, we try to sort recipients by the
# of the ole name, or just leave it if we can't # numerical part of the ole name
recips = recips_by_type[type] recips = recips_by_type[type] || []
recips = (recips.sort_by { |r| r.obj.name[/\d{8}$/].hex } rescue recips) recips = (recips.sort_by { |r| r.obj.name[/\d{8}$/].hex } rescue recips)
# switched to using , for separation, not ;. see issue #4 # switched to using , for separation, not ;. see issue #4
# recips.empty? is strange. i wouldn't have thought it possible, but it was right? # recips.empty? is strange. i wouldn't have thought it possible, but it was right?
Expand Down
4 changes: 2 additions & 2 deletions lib/mapi/msg.rb
Expand Up @@ -193,8 +193,8 @@ def self.parse_nameid obj
pseudo_prop = 0x8000 + offset pseudo_prop = 0x8000 + offset
named = flags & 1 == 1 named = flags & 1 == 1
prop = if named prop = if named
str_off = *str.unpack('V') str_off = str.unpack('V').first
len = *names_data[str_off, 4].unpack('V') len = names_data[str_off, 4].unpack('V').first
Ole::Types::FROM_UTF16.iconv names_data[str_off + 4, len] Ole::Types::FROM_UTF16.iconv names_data[str_off + 4, len]
else else
a, b = str.unpack('v2') a, b = str.unpack('v2')
Expand Down
2 changes: 1 addition & 1 deletion lib/mapi/property_set.rb
Expand Up @@ -249,7 +249,7 @@ def body
# for providing rtf decompression # for providing rtf decompression
def body_rtf def body_rtf
return @body_rtf if defined?(@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 end


# for providing rtf to html conversion # for providing rtf to html conversion
Expand Down
14 changes: 11 additions & 3 deletions lib/mapi/rtf.rb
Expand Up @@ -2,6 +2,14 @@
require 'strscan' require 'strscan'
require 'rtf' require 'rtf'


class StringIO # :nodoc:
begin
instance_method :getbyte
rescue NameError
alias getbyte getc
end
end

module Mapi module Mapi
# #
# = Introduction # = Introduction
Expand Down Expand Up @@ -46,9 +54,9 @@ def rtfdecompr data
flags = nil flags = nil
while rtf.length < uncompr_size and !io.eof? while rtf.length < uncompr_size and !io.eof?
# each flag byte flags 8 literals/references, 1 per bit # 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 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 # offset is a 12 byte number. 2^12 is 4096, so thats fine
rp = (rp << 4) | (l >> 4) # the offset relative to block start rp = (rp << 4) | (l >> 4) # the offset relative to block start
l = (l & 0xf) + 2 # the number of bytes to copy l = (l & 0xf) + 2 # the number of bytes to copy
Expand All @@ -58,7 +66,7 @@ def rtfdecompr data
rp = (rp + 1) % 4096 rp = (rp + 1) % 4096
end end
else else
rtf << buf[wp] = io.getc rtf << buf[wp] = io.getbyte.chr
wp = (wp + 1) % 4096 wp = (wp + 1) % 4096
end end
end end
Expand Down

0 comments on commit 8933c26

Please sign in to comment.