Commit 3d3c0838 authored by Sriram Karra's avatar Sriram Karra

Read a vCard file from server and parse out the name fields. Small beginning

parent d2afd85a
##
## Created : Wed Apr 03 19:02:15 IST 2013
## Last Modified : Thu Apr 04 13:21:22 IST 2013
## Last Modified : Thu Apr 04 15:40:58 IST 2013
##
## Copyright (C) 2013 Sriram Karra <karra.etc@gmail.com>
##
......@@ -43,7 +43,7 @@ class CDContact(Contact):
if vco:
self.init_props_from_vco(vco)
assert(itemid)
self.set_itemid(itemid)
self.set_itemid(itemid)
##
## First the inherited abstract methods from the base classes
......@@ -72,4 +72,34 @@ class CDContact(Contact):
## The Rest...
def init_props_from_vco (self, vco):
pass
self._snarf_names_gender_from_vco(vco)
def _snarf_names_gender_from_vco (self, vco):
if not vco:
return
if vco.n and vco.n.value:
if vco.n.value.given:
self.set_firstname(vco.n.value.given)
if vco.n.value.family:
self.set_lastname(vco.n.value.family)
if vco.n.value.additional:
self.set_middlename(vco.n.value.additional)
if vco.n.value.prefix:
self.set_prefix(vco.n.value.prefix)
if vco.n.value.suffix:
self.set_suffix(vco.n.value.suffix)
## FIXME: Need to handle the formatted name when it is present. There
## are known cases when the formatted name is different from the
## Last/First - for e.g. in apple addressbook, the FN is the orgname
## if the user has checked the 'company' box. So I guess the right way
## to handle the formatted name business is to faithfully copy
## whatever is there.
## FIXME: vCard3.0 does not really support standard gender
## fields... This is going to be a perennial problem.
##
## Created : Wed Apr 03 12:59:03 IST 2013
## Last Modified : Thu Apr 04 13:21:58 IST 2013
## Last Modified : Thu Apr 04 15:29:07 IST 2013
##
## Copyright (C) 2013 Sriram Karra <karra.etc@gmail.com>
##
......@@ -21,6 +21,7 @@
from folder import Folder
from contact_cd import CDContact
from vobject import vobject
from caldavclientlibrary.protocol.url import URL
from caldavclientlibrary.protocol.webdav.definitions import davxml
......@@ -129,7 +130,8 @@ class CDContactsFolder(Folder):
continue
data, etag = result
cdc = CDContact(self, vco=data, itemid=uri)
vco = vobject.readOne(data)
cdc = CDContact(self, vco=vco, itemid=uri)
self.add_contact(cdc)
logging.debug('Successfully fetched and added contact: %s',
uri)
......@@ -143,7 +145,7 @@ class CDContactsFolder(Folder):
logging.info('Total contained contacts: %d', len(cons.keys()))
logging.info('Items in brief: ')
for itemid, con in cons.iteritems():
logging.info(' Itemid: %s', itemid)
logging.info(' Name: %-25s Itemid: %s', con.get_disp_name(), itemid)
def get_root_path (self):
return self._get_prop('root_path')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment