Bug 238543

Summary: www/pycarddav: Syncing a contact with UTF-8 characters fails
Product: Ports & Packages Reporter: Oliver Adler <bla>
Component: Individual Port(s)Assignee: freebsd-ports-bugs (Nobody) <ports-bugs>
Status: Closed Overcome By Events    
Severity: Affects Some People CC: bla, python, samir
Priority: --- Keywords: needs-patch, needs-qa
Version: LatestFlags: koobs: maintainer-feedback+
koobs: merge-quarterly?
Hardware: Any   
OS: Any   
See Also: https://github.com/geier/pycarddav/issues/127
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=220368
https://github.com/geier/pycarddav/pull/128
Attachments:
Description Flags
Instead of unconditionally returning unicode, i check for the used charset with chardet.detect()
none
svn diff to include Oliver's patch in the port
samir: maintainer-approval+
svn diff to include patch from Github samir: maintainer-approval+

Description Oliver Adler 2019-06-13 09:24:07 UTC
Created attachment 205028 [details]
Instead of unconditionally returning unicode, i check for the used charset with chardet.detect()

During syncing with an owncloud instance with the command:
$ pycardsyncer 
one gets the following error, in case utf8 characters like Ä (German umlaut A) are included in a contact there will show the following crash:

Traceback (most recent call last):
  File "/usr/local/bin/pycardsyncer", line 55, in <module>
    sync(conf)
  File "/usr/local/lib/python2.7/site-packages/pycarddav/controllers/sync.py", line 57, in sync
    my_dbtool.update(vcard, conf.account.name, href=href, etag=etag)
  File "/usr/local/lib/python2.7/site-packages/pycarddav/backend.py", line 272, in update
    stuple = (etag, vcard.name, vcard.fname, vcard_s, status, href, href)
  File "/usr/local/lib/python2.7/site-packages/pycarddav/model.py", line 201, in name
    return unicode(self['N'][0][0]) if self['N'] else ''
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 3: ordinal not in range(128)

I assume, that the error is not owncloud specific. It is only necessary to have a changed contact
with an utf8 character in the Name.

I could fix the problem and the patch is in the appendix.
Comment 1 Kubilay Kocak freebsd_committer freebsd_triage 2019-06-13 13:28:34 UTC
Thank you for the report and patch Oliver.

This looks like a good candidate to report (or PR) upstream, but having said that, this looks like upstream issue: https://github.com/geier/pycarddav/issues/127 

There are two relevant (open) PR's:

https://github.com/geier/pycarddav/pull/124 (Nov 2018)
https://github.com/geier/pycarddav/pull/128 (Apr 2016)

The PR's have not been merged and the issue has not been closed. On that note, upstream has the following repository note:

DEPRECATED - use vdirsyncer & khard 

And in the README:

This project is dead
pyCardDAV is deprecated. See the relevant issue. A good alternative is khard.

We should add DEPRECATED to this port with an EXPIRY_DATE, whether or not we resolve this specific issue with a ports-local patch

[1] https://github.com/ph1l/pycarddav/commit/662923657f2345fda67fbbc1a7863a5d3b6ba58a
Comment 2 Samir Noir 2019-06-25 05:27:41 UTC
Created attachment 205321 [details]
svn diff to include Oliver's patch in the port
Comment 3 Samir Noir 2019-06-25 05:29:47 UTC
I have the problem when I test by adding a contact with UTF-8 in the name in Nextcloud. Oliver's patch work well.

PR #220368 is related to the deprecating problem. The port removal with DEPRECATED and EXPIRATION_DATE could provide a message to propose desktuils/py-khard as a replacement. 

How longtime is acceptable to put in the EXPIRATION_DATE ?

I've added a diff in attachment to include Oliver's patch in the port.
Comment 4 Kubilay Kocak freebsd_committer freebsd_triage 2019-06-25 05:42:51 UTC
Thank you Samir, could you please set maintainer-approval flag to + on the attachment/patch please
Comment 5 Samir Noir 2019-06-26 00:22:38 UTC
I've putted the flag
Comment 6 Kubilay Kocak freebsd_committer freebsd_triage 2019-07-01 15:19:00 UTC
I just checked the upstream issue, and I'd probably take the pull request that fixes the issue:

https://github.com/geier/pycarddav/pull/128

@Samir Could you produce a patch adding this PR

@Oliver Could you test that patch once its produced to confirm it resolves the issue
Comment 7 Samir Noir 2019-07-11 03:18:35 UTC
Created attachment 205686 [details]
svn diff to include patch from Github

The patch in attachment, with the correction from Github. But when I try to use pc_query I have the following error :
 
   UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 12: ordinal not in range(128)

Which I don't have with Oliver patch
Comment 8 Rene Ladan freebsd_committer freebsd_triage 2020-03-07 12:29:26 UTC
So upstream is abandoned and this port needs EOL Python 2.7, closing this PR.