geier / pycarddav

DEPRECATED - use vdirsyncer & khard -- easy to use CLI CardDAV client
http://lostpackets.de/pycarddav
MIT License
98 stars 35 forks source link

UnicodeDecodeError in model._pretty_base for PHOTO property #39

Open haphi opened 11 years ago

haphi commented 11 years ago

when running "pc_query -a" on a contact with a jpeg PHOTO, python fails with:

Traceback (most recent call last):
  File "/usr/bin/pc_query", line 88, in <module>
    controllers.query(conf)
  File "/usr/lib/python2.7/site-packages/pycarddav/controllers.py", line 107, in query
    lines = vcard.pretty
  File "/usr/lib/python2.7/site-packages/pycarddav/model.py", line 236, in pretty
    return self._pretty_base(self.alt_keys())
  File "/usr/lib/python2.7/site-packages/pycarddav/model.py", line 251, in _pretty_base
    line = key + types + ': ' + value[0]
 UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)

Possible solution might be to prevent "PHOTO" property from being pretty-printed or using a try/catch block to automatically filter any non-printable properties.

geier commented 11 years ago

Sorry for getting back to this so late. This really shouldn't happen, since all embedded images should be base64 encoded. I'm not really sure if just ignoring it (like in your pull request) is the best way to deal with this. Do you know which application created this vcard ? and do other applications display the image correctly?

haphi commented 11 years ago

I only have two vcards with "PHOTO"-properties, in both cases binary encoded. One was created by an android phone an synced through an OwnCloud-server, the other one has some 'history', that I cannot really trace back anymore. I thought ignoring at that point in the code would be OK as there is no good way to pretty-print non-printable data. Of course, come to think of it, instead of dropping the field alltogether, a 'binary' hint would be better, as the user should expect "pc_query -a" to show all existing tags.

geier commented 11 years ago

so does owncloud display the image correctly?

I guess a hint or something else is probably better than dropping it altogether

haphi commented 11 years ago

yes, ownclowd, the android address book and evolution all display the image correctly. so maybe something like this would be better:

                try:
                    line = key + types + ': ' + value[0]
                except UnicodeDecodeError:
                    line = key + types + ': <BINARY DATA>'
                collector.append(line)
geier commented 11 years ago

thanks for bringing this to my attention, it should be fixed in 07589c762582a75a977dae3cae3ce51f5c8e5c51 . I'll leave this issue open, since I still want to find out why this happens in the first place.

geier commented 11 years ago

If you want to be named in the contributors file, please give me a name, email address, etc