简体   繁体   中英

How to include charset in Vcard written using EZ-Vcard?

I am using the [EZ-VCards library][1] to generate some VCard data in a Java webapp.

It works fine and is quite straight-forward to use, except for encoding issues. The values are written using UTF-8 (I checked using a hex editor), but the encoding is not explicitely specified in the vcard.

As a result, when imported in a client program such as Outlook or the Contacts app in OSX, the accented characters are mis-reprensented. If the charset is specified, the values are imported correctly.

What I get :

FN:André Müller

What I would like to have :

FN;CHARSET=UTF-8:André Müller

How can I add this charset information using EZ-Vcard ? I read the doc (examples) and the JavaDoc API but could not find the way to do it.

EDIT: Michael's answer replied my original question, but unfortunately Outlook just won't play nice with UTF-8. So I need to encode in ISO-8859-1. I managed to manually create the a vcard string that works and imports correctly in Outlook as well as Apple Contacts and it looks like this :

N;CHARSET=ISO-8859-1:André;Müller;;; 
FN;CHARSET=ISO-8859-1:André Müller

At the web controller level, I ensure that the string that is returned is indeed encoded in iso-8859-1.

So how can I achieve this using EZ-Vcard ?

Try using quoted-printable encoding:

VCard vcard = new VCard();
FormattedName fn = vcard.setFormattedName("André Müller");
fn.getParameters().setEncoding(Encoding.QUOTED_PRINTABLE);
fn.getParameters().setCharset("ISO-8859-1");
vcard.write(System.out);

Prints:

BEGIN:VCARD
VERSION:3.0
FN;ENCODING=quoted-printable;CHARSET=ISO-8859-1:Andr=E9 M=FCller
PRODID:ez-vcard 0.9.8
END:VCARD

Please let me know if this works!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM