def Vcard.decode(card)
if card.respond_to? :to_str
string = card.to_str
elsif card.respond_to? :read
string = card.read(nil)
else
raise ArgumentError, "Vcard.decode cannot be called with a #{card.type}"
end
string.force_encoding "BINARY"
case string
when /^\xEF\xBB\xBF/
string = string.sub("\xEF\xBB\xBF", '')
when /^\xFE\xFF/
arr = string.unpack('n*')
arr.shift
string = arr.pack('U*')
when /^\xFF\xFE/
arr = string.unpack('v*')
arr.shift
string = arr.pack('U*')
when /^\x00B/i
string = string.unpack('n*').pack('U*')
when /^B\x00/i
string = string.unpack('v*').pack('U*')
end
string.force_encoding "utf-8"
entities = Vpim.expand(Vpim.decode(string))
if entities.detect { |e| ! e.kind_of? Array }
raise "Not a valid vCard"
end
vcards = []
for e in entities
vcards.push(new(e.flatten, 'VCARD'))
end
vcards
end