Skip to content

Commit

Permalink
better support for broken vcards (no FN prop)
Browse files Browse the repository at this point in the history
We are now trying to fix vcards that have no FN (reconstruct it from the
N property).

For reference: github issue #90
  • Loading branch information
geier committed Jan 29, 2014
1 parent 36b4ca7 commit b926bf9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pycarddav/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ def vcard_from_string(vcard_string):
vcard = vobject.readOne(vcard_string)
except vobject.base.ParseError as error:
raise Exception(error) # TODO proper exception

if 'fn' not in vcard.contents: # broken vcard (no FN)
logging.debug('vcard has no formatted name, reconstructing...')
name = vcard.contents['n'][0].split(';')
fname = name[2] + ' ' + name[1] + ' ' + name[0] + ' ' + name[3]
fname = fname.strip()
vcard.add('fn')
vcard.fn.value = fname
return vcard_from_vobject(vcard)


Expand Down Expand Up @@ -288,7 +296,10 @@ def generate_random_uid():
collector.append('BEGIN:VCARD')
collector.append('VERSION:3.0')
for key in ['FN', 'N']:
collector.append(key + ':' + self[key][0][0])
try:
collector.append(key + ':' + self[key][0][0])
except IndexError: # broken vcard without FN or N
collector.append(key + ':')
for prop in self.alt_keys():
for line in self[prop]:

Expand Down

0 comments on commit b926bf9

Please sign in to comment.