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

[Enhancement] Don't write unnecessary ";" at end of structured properties #57

Closed
rfc2822 opened this issue Jun 8, 2016 · 7 comments
Closed

Comments

@rfc2822
Copy link
Contributor

rfc2822 commented Jun 8, 2016

When playing around with iCloud, I have found out that they use the whole line of the structured name (N) as the display name for groups. So, this group:

VERSION:3.0
X-ADDRESSBOOKSERVER-KIND:group
FN:My Group
N:My Group,,,,

will be shown as "My Group,,,,". While this is clearly an iCloud bug, I wonder whether it might be possible to just generate the actually used components, for example N:My Group instead of N:My Group,,,, when only the family name is set. See also the first example in RFC 2426 3.1.2 where the Honorific Suffixes are left out without a trailing ;:

N:Public;John;Quinlan;Mr.;Esq.

instead of

N:Public;John;Quinlan;Mr.;Esq.;

This should be applicable to other structured fields too and could reduce the complexity (and size) of generated VCards.

@rfc2822 rfc2822 changed the title [Enhancement] Don't write unnecessary ";" at end of structured components [Enhancement] Don't write unnecessary ";" at end of structured properties Jun 8, 2016
@mangstadt
Copy link
Owner

Is there a typo in your first example? Should those commas be semi-colons?

Commas and semi-colons are treated differently by the N property. Commas are used as delimiters when a component has more than one item in it.

For example, the following property has two prefixes:

N:Public;John;Quinlan;Mr.,Dr.;Esq.;

The first example you gave technically translates as a list of family names. According to the specification, it is not possible to have more than one family name, so iCloud may be treating the comma characters as normal characters, which is why iCloud is using "My Group,,,," as the group name.

What happens when you pass N:GroupName;;;; into iCloud? Does iCloud include the trailing semicolons in the group name?

@rfc2822
Copy link
Contributor Author

rfc2822 commented Jun 11, 2016

What happens when you pass N:GroupName;;;; into iCloud? Does iCloud include the trailing semicolons in the group name?

You're right, this is a typo. I have passed a StructuredName which just family name set into iCloud and the result was a group called Name,,,, or Name;;;;. I don't remember anymore, but I guess it was "Name;;;;" (because this was the full N in the uploaded VCard). When doing vCard.addExtendedProperty("N", fn); instead, it works.

@mangstadt
Copy link
Owner

Fixed in e2a4dd3.

Call VCardWriter.setTargetApplication() like so:

VCard vcard = new VCard();
StructuredName n = new StructuredName();
n.setFamily("GroupName");
vcard.setStructuredName(n);

VCardWriter writer = new VCardWriter(System.out, VCardVersion.V3_0);
writer.setTargetApplication(TargetApplication.ICLOUD);
writer.write(vcard);
writer.close();

Output:

BEGIN:VCARD
VERSION:3.0
PRODID:ez-vcard 0.9.11-SNAPSHOT
N:GroupName
END:VCARD

Thank you for reporting this.

@rfc2822
Copy link
Contributor Author

rfc2822 commented Jun 15, 2016

Thanks, but one question: As far as I understand it, the trailing ;s are unnecessary in any case, so wouldn't it best to always remove them (and not only for a specific target application)?

mangstadt added a commit that referenced this issue Jun 17, 2016
They are now trimmed by default. This setting can be changed by calling
"VCardWriter.setIncludeTrailingSemicolons()".  Removed
"TargetApplication.ICLOUD".

The large list of files in this commit is due to the fact that the
"VCardPropertyScribe.writeText()" signature was changed.

#57
@mangstadt
Copy link
Owner

mangstadt commented Jun 17, 2016

The example you gave in your first post isn't quite accurate.

N:Public;John;Quinlan;Mr.;Esq.

The reason why there is no trailing semicolon in this example is that there are no more components after the "Esq." component. "Esq." is the "suffix" component, which is the last one.

The formal grammar in the vCard 3.0 spec does state that trailing semicolons are optional:

 ;For name="N"
 ;This type MUST be included in a vCard object.
 param = text-param
 ; Text parameters allowed
 value = n-value
 n-value = 0*4(text-value *("," text-value) ";")
 text-value *("," text-value)
 ; Family; Given; Middle; Prefix; Suffix.
 ; Example: Public;John;Quincy,Adams;Reverend Dr. III

And the vCard 2.1 spec gives an example without the trailing semi-colons:

N:Veni, Vidi, Vici;The Restaurant.

However, vCard 4.0 requires all four semicolons to be there:

N-value = list-component 4(";" list-component)

From a performance perspective, the better approach would be to trim the semicolons, since it reduces the size of the vCard file.

Trailing semicolons are now trimmed by default for 2.1 and 3.0 vCards. I removed TargetApplication.ICLOUD and added a method to VCardReader that lets you adjust this setting if the consumer you're targeting requires something specific.

See commits 04cd767 and 882ee75.

@rfc2822
Copy link
Contributor Author

rfc2822 commented Jun 17, 2016

From a performance perspective, the better approach would be to trim the semicolons, since it reduces the size of the vCard file.

Yes, this was my first thought.

Thank you very much for digging into this and providing this enhancement!

@mangstadt
Copy link
Owner

No problem. Thanks for bringing the issue to my attention!

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

2 participants