mangstadt/ez-vcard

Wrong value for vCard property VERSION returned

Closed this issue · 4 comments

From Peter via email:

Hi Mike,

thank you for providing ez-vcard. We use it to validate vCards that are provided by other parties. When the validation is o.k. we want to display the vCard using Angular VCF (vcf - npm (npmjs.com)). When it is not o.k. we want to return an error message to the other party. Unfortunately, the validation done by VCF works different than ez-vcard. So we have some kind of collaboration problem.

We receceive a vCard like this. The structure of this vCard is compliant to RFC 2425, version 2.1, but property VERSION is set to “1.0”:

BEGIN:VCARD
VERSION:1.0
N;LANGUAGE=en:Doe;John
FN:John Doe
ORG:Big Company
TITLE:Boss
TEL;WORK;VOICE:0123456789
X-MS-OL-DEFAULT-POSTAL-ADDRESS:0
EMAIL;PREF;INTERNET:John.Doe@big-company.com
REV:20231122T151319Z
END:VCARD

However, the java method VCard.getVersion() returns “2.1”. When no proper value is set, the expectation is that VCard.getVersion() returns null. But when “2.1” is returned the validation seems to be o.k. for me. However it is not because VCF doesn’t display vCards where property VERSION is set to “1.0”.

I checked the RFC and found the following statement “The value of this property must be 2.1 to correspond to this specification”. So my expectation seems to be reasonable. What do you think about the issue? Do you have any advice for me on how to get the ‘real’ value of the property or how to get a proper error message.

Thank you very much in advance.

Kind regards

Peter

Hi Peter,

ez-vcard logs the invalid version number as a parse warning, and then treats it as an extended (custom) property:

List<List<ParseWarning>> warnings = new ArrayList<>();
Path path = Paths.get("peter.vcf");
VCard vcard = Ezvcard.parse(path).warnings(warnings).first();

System.out.println(vcard.getExtendedProperty("VERSION").getValue());
System.out.println(warnings);

Outputs:

1.0
[[Line 2 (VERSION property): (27) Skipped.  Unknown version number found. Treating it as a regular property.  The entire line is: "VERSION:1.0"]]

Regards,
Mike

From Peter via email:

Hi Mike,

thank you very much for your support. Your solution works fine for me, however, I’am still struggling with the version property…

When Property VERSION is absent, neither a parse warning nor a validation warning is issued.

Please see this example:

BEGIN:VCARD
N;LANGUAGE=en:Doe;John
FN:John Doe
ORG:Big Company
TITLE:Boss
TEL;WORK;VOICE:0123456789
X-MS-OL-DEFAULT-POSTAL-ADDRESS:0
EMAIL;PREF;INTERNET:John.Doe@big-company.com
REV:20231122T151319Z
END:VCARD

Using Ezvcard.parse(path).warnings(warnings).first() the list of warnings is empty.

Using ValidationWarnings = Ezvcard.parse(path).first().validate(vcardVersion) the ValidationWarnings object is empty too.

vcard.getExtendedProperty("VERSION") return a NULL value when property VERSION is absent but it also returns a NULL value, when property VERSION is set to a proper value, e.g. “2.1”. So this method is not useful too.

Would you please check again? Is there any possibility to check if property VERSION is provided at all?

Kind regards

Peter

Hi Peter,

There is currently no direct way of detecting whether a VERSION property is missing from a vCard.

As a workaround, you could parse the vCard twice using different default versions and compare the versions of the parsed vCards.

Path path = Paths.get("peter.vcf");

VCardVersion v1;
try (VCardReader reader = new VCardReader(path, VCardVersion.V2_1)) {
  VCard vcard = reader.readNext();
  v1 = vcard.getVersion();
}

VCardVersion v2;
try (VCardReader reader = new VCardReader(path, VCardVersion.V3_0)) {
  VCard vcard = reader.readNext();
  v2 = vcard.getVersion();
}

boolean versionPropertyIsMissing = (v1 != v2);

Regards,
Mike

From Peter via email:

Hi Mike,

thank you very much for your code example. The workaround is great! I have checked the functionality within my application. Now everything is fine.

Kind regards

Peter