Skip to content

Instantly share code, notes, and snippets.

@clee
Created April 15, 2011 09:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clee/921462 to your computer and use it in GitHub Desktop.
Save clee/921462 to your computer and use it in GitHub Desktop.
read from iChat conversation logs using MacRuby
#!/usr/bin/env macruby
framework 'Foundation'
framework 'AppKit'
class Person
def initWithCoder(decoder)
# empty implementation needed for ancient iChat conversations
end
end
class Presentity
def initWithCoder(decoder)
if decoder.allowsKeyedCoding
@service = decoder.decodeObjectForKey(:ServiceName)
@sender = decoder.decodeObjectForKey(:ID)
else
@service = decoder.decodeObject
@sender = decoder.decodeObject
end
[@service, @sender]
end
end
class InstantMessage
def initWithCoder(decoder)
if decoder.allowsKeyedCoding
@sender = decoder.decodeObjectForKey(:Sender)
@when = decoder.decodeObjectForKey(:Time)
@text = decoder.decodeObjectForKey(:MessageText)
@flags = decoder.decodeObjectForKey(:Flags)
else
@sender = decoder.decodeObject
@when = decoder.decodeObject
@text = decoder.decodeObject
@flags = Pointer.new_with_type('I')
decoder.decodeValueOfObjCType('I', at: @flags)
end
attributes = {NSDocumentTypeDocumentAttribute => NSHTMLTextDocumentType, NSExcludedElementsDocumentAttribute => ['doctype', 'xml', 'html', 'head', 'body']}
mhtml = @text.dataFromRange(NSMakeRange(0, @text.length), documentAttributes: attributes, error: nil)
[@sender, @when, NSString.stringWithUTF8String(mhtml)]
end
end
if __FILE__ == $0
ARGV.each do |fileName|
contents = open(fileName, 'rb').read
o = (contents[0,8] == 'bplist00' ? NSKeyedUnarchiver : NSUnarchiver).unarchiveObjectWithData(contents.to_data)
puts o.inspect
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment