Created
October 17, 2011 01:54
-
-
Save yuanying/1291759 to your computer and use it in GitHub Desktop.
Check email from AddressBook with 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 ruby -wKU | |
framework 'AddressBook' | |
def check_email from | |
#http://developer.apple.com/mac/library/DOCUMENTATION/UserExperience/Reference/AddressBook/Miscellaneous/AddressBook_Constants/Reference/reference.html | |
book = ABAddressBook.sharedAddressBook | |
me = book.me | |
book.people.each do |person| | |
if person == me | |
next | |
end | |
emails = person.valueForProperty(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