home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 108 / MacAddict108.iso / Software / Internet & Communication / JunkMatcher 1.5.5.dmg / JunkMatcher.app / Contents / Resources / Engine / addressBook.py next >
Encoding:
Python Source  |  2005-06-01  |  2.1 KB  |  61 lines

  1. #
  2. #  addressBook.py
  3. #  JunkMatcher
  4. #
  5. #  Created by Benjamin Han on 2/1/05.
  6. #  Copyright (c) 2005 Benjamin Han. All rights reserved.
  7. #
  8.  
  9. # This program is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU General Public License
  11. # as published by the Free Software Foundation; either version 2
  12. # of the License, or (at your option) any later version.
  13.  
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. # GNU General Public License for more details.
  18.  
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  22.  
  23. #!/usr/bin/env python
  24.  
  25. from consts import *
  26.  
  27. import sets
  28. import AddressBook
  29.  
  30.  
  31. def getAddressesFromABook ():
  32.     """(MAC OS X ONLY)  Returns a set of email addresses, excluding a user's own email addresses."""
  33.     book = AddressBook.ABAddressBook.sharedAddressBook()    
  34.     me = book.me()    # can be None
  35.     if me:
  36.         people = filter(lambda p:p is not me, book.people())
  37.     else:
  38.         people = book.people()
  39.  
  40.     return reduce(lambda x, y: x | y,
  41.                   map(lambda emails: sets.Set(map(lambda i: emails.valueAtIndex_(i).lower(), range(emails.count()))),
  42.                       filter(lambda emails: emails,
  43.                              map(lambda p: p.valueForProperty_(u'Email'), people))),
  44.                   sets.Set())
  45.  
  46. ##     ret = sets.Set()
  47. ##     for emails in filter(lambda emails: emails, map(lambda p: p.valueForProperty_(u'Email'), people)):
  48. ##         ret |= sets.Set(map(lambda i: emails.valueAtIndex_(i).lower(), range(emails.count())))
  49.     
  50. ##     for p in people:
  51. ##         emails = p.valueForProperty_(u'Email')
  52. ##         if emails:
  53. ##             ret |= sets.Set(map(lambda i: emails.valueAtIndex_(i).lower(), range(emails.count())))
  54.  
  55. ##     return ret
  56.  
  57.  
  58. if __name__ == '__main__':
  59.     addrs = getAddressesFromABook()
  60.     print addrs
  61.