Skip to content

Instantly share code, notes, and snippets.

@yuanying
Created January 19, 2010 06:57
Show Gist options
  • Save yuanying/280735 to your computer and use it in GitHub Desktop.
Save yuanying/280735 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -wKU
require 'osx/cocoa'
OSX.require_framework 'AddressBook'
def check_email from
#http://developer.apple.com/mac/library/DOCUMENTATION/UserExperience/Reference/AddressBook/Miscellaneous/AddressBook_Constants/Reference/reference.html
book = OSX::ABAddressBook.sharedAddressBook
me = book.me
OSX::ABAddressBook.sharedAddressBook.people.each do |person|
if person == me
next
end
emails = person.valueForProperty(OSX::KABEmailProperty)
if emails
count = emails.count
(0...count).each do |index|
email = emails.valueAtIndex(index)
return true if from.index(email)
end
end
end
return false
end
FROM = /^From:/
while (line = gets) do
if FROM =~ line && check_email(line)
exit 1
end
end
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment