[maemo-developers] Related to Contacts : Decoding .VCF File

From: Jörgen Scheibengruber jorgen.scheibengruber at nokia.com
Date: Mon Jul 5 15:53:22 EEST 2010
Am Freitag, den 02.07.2010, 12:27 +0200 schrieb ext Graham Cobb:
> On Friday 02 July 2010 10:20:24 Jörgen Scheibengruber wrote:
> > Which is exactly what e_contact_new_from_vcard, does. 
> 
> How does e_contact_new_from_vcard get told what charset the string is in?  Or 
> does it require it to be in UTF-8?

In the Maemo5 version of eds e_contact_new_from_vcard() internally uses
a heuristic (the same as gecko uses) to figure out the charset (if the
passed string is not utf-8). If you know the charset, then of course
it's best to g_convert() the string obtained from g_file_get_contents()
into utf-8 first, then there is no need for guessing...

> > It's as easy as: 
> >
> > char *contents;
> > if (g_file_get_contents ("file.vcf", &contents, NULL, NULL)) {
> > 	EContact *contact;
> > 	contact = e_contact_new_from_vcard (contents);
> > 	g_free (contents).
> > }
> 
> It's not really that easy.  Character sets are one of the hardest problems 
> when importing and exporting v-format data as files do not have metadata to 
> tell you the charset.

version 2.1 vcards actually allow to specify the encoding inline in the
vcard, but for 3.0 this was dropped. Which was maybe not the most clever
decision ever. Then again, everybody really should just use utf-8 :-P

> I don't recommend using g_file_get_contents to read the file unless you are 
> prepared to write code to handle the charset conversions.

g_convert() ?

Br,
Jörgen

More information about the maemo-developers mailing list