Skip to content

Instantly share code, notes, and snippets.

@davglass
Created February 4, 2009 05:14
Show Gist options
  • Save davglass/57951 to your computer and use it in GitHub Desktop.
Save davglass/57951 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import vobject
from cStringIO import StringIO
import os, sys, string
'''
Simple script to parse an Apple Addressbook export file and
turn it into a Mutt aliases file
--
Install vobject:
easy_install vobject
'''
f = open('./vCards.vcf')
fileStr = StringIO(f.read()).getvalue()
v = vobject.readComponents(fileStr)
store = []
for i in v:
try:
if i.fn and i.email:
if i.fn.value != i.email.value:
nick = i.fn.value.replace(' ', '').replace('.', '').lower()
if not nick in store:
store.append(nick)
print "alias %s %s <%s>" % (nick, i.fn.value, i.email.value)
except AttributeError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment