Created
April 15, 2011 09:31
-
-
Save clee/921462 to your computer and use it in GitHub Desktop.
read from iChat conversation logs using MacRuby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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