Giter Club home page Giter Club logo

vcard's Introduction

vCard module

Moved to GitLab

Build Status

This program can be used for strict validation and parsing of vCards. It currently supports vCard 3.0 (RFC 2426).

Additional scripts:

Installation / upgrade

sudo pip install --upgrade vcard

Examples

Development

Download:

git clone --recurse-submodules https://github.com/l0b0/vcard.git

Test:

make test

To test a specific Python version:

make PYTHON_VERSION=3.5.1 test

Test requirements:

  • gcc
  • gpg
  • tar
  • make
  • openssl development headers/libraries
  • pip
  • wget
  • zlib development headers/libraries

vcard's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vcard's Issues

vcard doesn't accept custom field type

RFC 2426 says fields such as ADR and TEL can have non-standard type prefixed by x called "x-name".

adr-type     = "dom" / "intl" / "postal" / "parcel" / "home"
                / "work" / "pref" / iana-type / x-name

But Vcard doesn't allow them:

Invalid parameter value (See RFC 2426 section 4 for param-value syntax): x-other
File: ../ldif2vcf/campus.vcf
File line: 14
vCard line: 11
Property: ADR
Property line: ADR;TYPE=x-other:;H5108C;;;;;

Is this a design choice ?

Escaped commas are not handled as such

For example:

FN:Doe\, Doe\, and Doe

This should be handled as a single name, but instead vcard reports "Invalid subvalue count (See RFC 2426 section 3 for details): 3 (expected 1)"

vcard end lines

My vcard exported from android:

00000060  0a 45 4e 44 3a 56 43 41  52 44 0a 0a              |.END:VCARD..|
0000006c

Vcard vcard/test/maximal.vcf:

000003f0  0a 45 4e 44 3a 56 43 41  52 44 0d 0a 0d 0a        |.END:VCARD....|
000003fe

Where in file vcard_defs.py is defined and hard cored:
CRLF_CHARS = CR_CHAR + LF_CHAR

I suggest you replace CRLF_CHARS with a constant to the function that detects what is the end of the current file and use it everywhere.

ERROR: “Could not process entire <file> - ## lines remain”

I keep getting this error, and it’s quite baffling. The ## lines remain seems to equal the number of lines in the file—as if to say, “Could not process entire , ALL lines remain”.

I would love to be able to use this validation feature! Please let me know what I can do to help fix this bug.

should support charset=utf-8

Example file that fails:

$ cat >vcardbug <<EOF
BEGIN:VCARD
VERSION:3.0
N;CHARSET=UTF-8:TestășTest;Foo;;;
FN;CHARSET=UTF-8:TestășTest  Foo
TEL;TYPE=VOICE:+40123123123
TEL;TYPE=VOICE:+40123123124
END:VCARD

EOF
$ unix2dos vcardbug
$ pip install --user --upgrade vcard
$ $HOME/.local/bin/vcard -v vcardbug
Traceback (most recent call last):
  File "/home/edwin/.local/bin/vcard", line 9, in <module>
    load_entry_point('vcard==0.8', 'console_scripts', 'vcard')()
  File "/home/edwin/.local/lib/python2.7/site-packages/vcard/vcard.py", line 471, in main
    result = validate_file(filename, verbose)
  File "/home/edwin/.local/lib/python2.7/site-packages/vcard/vcard.py", line 405, in validate_file
    vcard = VCard(vcard_text, filename)
  File "/home/edwin/.local/lib/python2.7/site-packages/vcard/vcard.py", line 375, in __init__
    self.properties = get_vcard_properties(lines)
  File "/home/edwin/.local/lib/python2.7/site-packages/vcard/vcard.py", line 333, in get_vcard_properties
    properties.append(get_vcard_property(property_line))
  File "/home/edwin/.local/lib/python2.7/site-packages/vcard/vcard.py", line 307, in get_vcard_property
    prop['values'] = get_vcard_property_values(values_string)
  File "/home/edwin/.local/lib/python2.7/site-packages/vcard/vcard.py", line 261, in get_vcard_property_values
    values.append(get_vcard_property_subvalues(sub))
  File "/home/edwin/.local/lib/python2.7/site-packages/vcard/vcard.py", line 241, in get_vcard_property_subvalues
    '{0}: {1}'.format(MSG_INVALID_SUBVALUE, subvalue),
UnicodeEncodeError: 'ascii' codec can't encode characters in position 3-4: ordinal not in range(128)

If I remove the utf-8 chars, it still won't validate:

$ cat >vcardbug <<EOF
BEGIN:VCARD
VERSION:3.0
N;CHARSET=UTF-8:TestTest;Foo;;;
FN;CHARSET=UTF-8:TestTest  Foo
TEL;TYPE=VOICE:+40123123123
TEL;TYPE=VOICE:+40123123124
END:VCARD

EOF
$ unix2dos vcardbug
$ $HOME/.local/bin/vcard -v vcardbug
Invalid X-name (See RFC 2426 section 4 for x-name syntax)
File: vcardbug
File line: 7
vCard line: 2
Property: N
Property line: N;CHARSET=UTF-8:TestTest;Foo;;;

String: CHARSET

Some tests missing files to check

In test/test_package.py, before the unittest class is declared, there’s a bunch of variables defined with names like VCARDS_INVALID_TIME, VCARDS_INVALID_URI, and so forth.

Most of these reference files in the test/ directory, demonstrating that the tests should fail when given an invalid vCard file.

However, several of these definitions don’t list any vCard files at all. I presume this means that these error cases are not being tested.

Can’t `make test`

I get the following after running make test:

gpg --keyserver keys.gnupg.net --no-default-keyring --keyring download/keyring.gpg --recv-keys 6A45C816 36580288 7D9DC8D2 18ADD4FF A4135B38 A74B06BF EA5BBD71 ED9D77D5 E6DF025C 6F5E1540 F73C700D 3372DCFA
make: gpg: No such file or directory
make: *** [download/keyring.gpg] Error 1

Validate nested vCards

The AGENT type can contain an inline, escaped, vCard, which can then again contain further nested vCards.

VCardFormatError: Invalid line ending

code:

    for f in args:
        file_opened = open(f, "r")
        result = VCard(file_opened.read())
        if result is not None:
            print(result + '\n')

error:

Traceback (most recent call last):
  File "vcard.py", line 471, in 
    sys.exit(main())
  File "vcard.py", line 465, in main
    result = VCard(file_opened.read())
  File "vcard.py", line 360, in __init__
    lines = unfold_vcard_lines(self.text.splitlines(True))
  File "vcard.py", line 65, in unfold_vcard_lines
    {'File line': index + 1})
vcard_validators.VCardFormatError: Invalid line ending; should be \r\n (See RFC
2426 section 2.4.2 for details)
File line: 1

The actual line endings seems correct.
The same vcard parses just fine in other programs.

EDIT: opening the file with "codecs.open(f, 'r', 'utf-8')" fixed the newline issue,
but now i'm getting

vcard_validators.VCardFormatError: Invalid value count (See RFC 2426 section 3 for details): 2 (expected 5)
vCard line: 2
Property: N
Property line: N:Surname;Name

Make buildable without installing anything

Ideally, this project should be buildable even if no Python is installed. To make this possible the Makefile should download, verify and install all Python dependencies in the build directory.

vCard 2.1 Terminator

Hi,

I'm trying to write a vCard export according to the vCard 2.1 standard described in the following document: http://www.imc.org/pdi/vcard-21.rtf
It contains the follwing paragraph on page 5 section 1.1 vCard Object:
"[...]The vCard object is terminated with either the logical end of the data stream or the appearance of the End vCard Delimiter as the first character on a line:
END:VCARD"
It seems your vCard validator does not handle this case. When I terminate my vCard only with "\r\nEND:VCARD" I get the following error message from the validator:
"Could not process entire xyc.vcf - 4 lines remain"
The vCard file I created looks like this:
"BEGIN:VCARD
VERSION:2.1
N:d;d;;;
FN:sx
END:VCARD"
I addition, the way I understand the above paragprah, the following vCard should also be accepted:
"BEGIN:VCARD
VERSION:2.1
N:d;d;;;
FN:sx"
What I have to do to make my vCard acceptable for the validator is add two newlines at the end:
"BEGIN:VCARD
VERSION:2.1
N:d;d;;;
FN:sx
END:VCARD

"
So is this a bug in the validator or in my understanding of the specification? Maybe I am doing something wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.