This small script takes the content of Apple AddressBook and create a whitelist format of spamassassin. If the person has multilple addresses there will be one line by address. For example
whitelist_from [EMAIL PROTECTED] #Karl Dubost whitelist_from [EMAIL PROTECTED] #Karl Dubost whitelist_from [EMAIL PROTECTED] #Marguerite """ ab2sa.py Script for converting an Apple AddressBook to a whitelist for including in spam assassin user_prefs file Requires pyObjc Created by Karl Dubost on 2007-05-29. Inspired from Neil Martinsen-Burrell's script ab2alias.py W3C® SOFTWARE LICENSE see http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 """
#!/usr/bin/env python # encoding: utf-8 """ ab2sa.py Script for converting an Apple AddressBook to a whitelist for including in spam assassin user_prefs file Requires pyObjc http://pyobjc.sourceforge.net/ Created by Karl Dubost on 2007-05-29. Inspired from Neil Martinsen-Burrell's script ab2alias.py W3C® SOFTWARE LICENSE see http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 """ from AddressBook import * def name(person): """Give back a name string for an ABPerson.""" try: firstname = person.valueForProperty_(kABFirstNameProperty) except: first = '' try: lastname = person.valueForProperty_(kABLastNameProperty) except: last = '' if firstname is None: firstname = '' if lastname is None: lastname = '' fullname = firstname+' '+lastname return fullname.strip() def email(person): """Return the primary email for an ABPerson.""" emails = [] try: emailProperty = person.valueForProperty_(kABEmailProperty) if emailProperty is not None: for i in range(emailProperty.count()): emails.append(emailProperty.valueAtIndex_(i)) except: emails = '' return emails def main(): people = ABAddressBook.sharedAddressBook().people() for person in people: fullname = name(person) emails = email(person) if emails=='': pass else: for address in emails: print '\t'.join(['whitelist_from', address, '#'+fullname]) if __name__=='__main__': main()
-- Karl Dubost - http://www.w3.org/People/karl/ W3C Conformance Manager, QA Activity Lead QA Weblog - http://www.w3.org/QA/ *** Be Strict To Be Cool ***
