Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vobject fails to parse this vcard #160

Open
Volker-Weissmann opened this issue Dec 30, 2020 · 4 comments
Open

vobject fails to parse this vcard #160

Volker-Weissmann opened this issue Dec 30, 2020 · 4 comments

Comments

@Volker-Weissmann
Copy link

This code:

import vobject
el = """BEGIN:VCARD
VERSION:2.1
N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;=57=6F=6C=6C=6B=6E=C3=A4=75=65=6C=20=53=6F=63=6B=65=6E=62=61=72=74=20=
=45=50;;;
FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=57=6F=6C=6C=6B=6E=C3=A4=75=65=6C=20=53=6F=63=6B=65=6E=62=61=72=74=20=
=45=50
TEL;CELL:+123456
TEL;CELL:+123456
END:VCARD"""
print(vobject.readOne(el))

fails with the message

Traceback (most recent call last):
  File "/path/to/script.py", line 32, in <module>
    print(vobject.readOne(el))
  File "/home/volker/.local/lib/python3.9/site-packages/vobject/base.py", line 1155, in readOne
    return next(readComponents(stream, validate, transform, ignoreUnreadable,
  File "/home/volker/.local/lib/python3.9/site-packages/vobject/base.py", line 1101, in readComponents
    vline = textLineToContentLine(line, n)
  File "/home/volker/.local/lib/python3.9/site-packages/vobject/base.py", line 925, in textLineToContentLine
    return ContentLine(*parseLine(text, n), **{'encoded': True,
  File "/home/volker/.local/lib/python3.9/site-packages/vobject/base.py", line 813, in parseLine
    raise ParseError("Failed to parse line: {0!s}".format(line), lineNumber)
vobject.base.ParseError: At line 7: Failed to parse line: =45=50;;;
@svilendobrev
Copy link

instead of waiting for the library to be fixed...
Seems most/android phone exporters split long lines (>115) this way - ending on '=' then next line starts with '='. Most non-ascii names hit this limit easily.

newvcardtext = vcardtext.replace( '=\n=', '=')
works fine joining them back; use on single vcard or over whole vcf file/text, before parsing with vobject.

@Volker-Weissmann
Copy link
Author

Thank you, this works.

@elig0n
Copy link

elig0n commented Jun 4, 2022

You must allow QP decoding since the parser knows how to decode it:

print(vobject.readOne(el, allowQP=True))

@Volker-Weissmann
Copy link
Author

print(vobject.readOne(el, allowQP=True))

This also works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants