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

Adding charset encoding to elements in VCard #106

Closed
DJViking opened this issue Jul 3, 2020 · 5 comments
Closed

Adding charset encoding to elements in VCard #106

DJViking opened this issue Jul 3, 2020 · 5 comments

Comments

@DJViking
Copy link

DJViking commented Jul 3, 2020

In order to support special characters on iPhone we had to (with VCard v2.1) add Charset=UTF-8 to each elements.
WIthout it tthe special characters did not display properly on iPhone. It works fine on Android with and without the Charset.

N;CHARSET=UTF-8:Solskjær;Åge
ADR;WORK;CHARSET=UTF-8:Address with ÆØÅ Special Characters;1234;Norway

I could not find any way to add this with ez-vcard.

@DJViking DJViking changed the title Adding encoding to elements in VCard Adding charset encoding to elements in VCard Jul 3, 2020
@DJViking
Copy link
Author

DJViking commented Jul 3, 2020

I found out how.
Setting parameter
address.setProperty("Chartset", "UTF-8");

@mangstadt
Copy link
Owner

To just add a CHARSET parameter to a property:

vcard.getStructuredName().getParameters().setCharset("UTF-8");

If you are still having trouble, you can try encoding the property value in quoted-printable encoding. My understanding is that this is the most widely supported technique amongst vCard readers.

Quoted-printable encoding allows for non-ASCII characters to be included in a property value, no matter what character set the vCard as a whole uses. By default, ez-vcard uses UTF-8 when encoding a value in quoted-printable encoding (the CHARSET parameter is automatically added when quoted-printable encoding is used).

StructuredName n = new StructuredName();
n.setFamily("Solskjær");
n.setGiven("Åge");
n.getParameters().setEncoding(Encoding.QUOTED_PRINTABLE);

VCard vcard = new VCard(VCardVersion.V2_1);
vcard.setStructuredName(n);
vcard.write(System.out);

//outputs: N;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:Solskj=C3=A6r;=C3=85ge

@DJViking
Copy link
Author

DJViking commented Jul 3, 2020

Thanks. A much better approach than what I just found.

@DJViking
Copy link
Author

DJViking commented Jul 3, 2020

On VCard V3.0 and V4.0 this produces an warning on validation
n.getParameters().setEncoding(Encoding.QUOTED_PRINTABLE);

W04 ENCODING parameter value ("QUOTED_PRINTABLE") is not supported by this vCard version.

It didn't like my Charset parameter either.

W06 Charset parameter is not supported by this vCard version.

Though I could just stick with V2.1

@mangstadt
Copy link
Owner

That is correct. According to the specifications, only 2.1 supports quoted-printable encoding and the CHARSET parameter.

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