[Vobject] Generate (serialize) Vcard with UTF8
Jeffrey Harris
jeffrey at ic.org
Fri Jan 15 01:03:41 CST 2010
Hi Frédéric,
> First I parse the following vcard with "vcard = vobject.readOne(v)",
> this is working well and I can display the name "Frédéric" on my GUI:
> *BEGIN:VCARD
> VERSION:3.0
> FN:Frederic
> N;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:;Fr=C3=A9d=C3=A9ric;;;
> TEL:12345678
> **END:VCARD*
Quoted-Printable encoding isn't defined for vCard 3.0, instead the
standards moved forward to encodings being outside the scope of the
spec, so the entire VCARD object will be encoded.
vobject goes ahead and converts the quoted-printable to unicode.
Round-tripping quoted printable anything isn't current supported in
vobject, I don't see much utility in *writing* vCard 2.1.
The quoted-printable in this case isn't used for line-folding, so it
will parse. If you look at the n content-line:
>>> vcard.n.value
<Name: Fr?d?ric >
you have a vobject.vcard.Name object.
> When I try to re-generate the vcard, this is what I get:
>> vcard.serialize()
> *BEGIN:VCARD
> VERSION:3.0
> FN:Frederic
> N:;Frédéric;;;
> TEL:12345678
> END:VCARD
> *
serialize() will output utf-8 automatically. Probably I ought to add an
option to use some other encoding, but no one's ever complained, so I
haven't ever implemented that. It's non-trivial to do 75 byte
line-folding if your unicode data uses an arbitrary encoding, is
actually the reason I haven't done this. In practice I don't think any
modern clients care if the occasional folded Chinese text line ends up
being 200 bytes long, though.
What exactly is wrong with this output, from your perspective? It
sounds like you were surprised it's utf-8 and not unicode, given that
it's utf-8, it's now arguably more correct, since it's encoded properly
for vCard 3.0.
> How can I "force" serialize() to use
> "*ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8*" for the name ? (Actually I
> have the problem for Chinese characters but I use the French accent "é"
> here as an example, the problem should remain the same).
Well, if you really *must* have quoted-printable (either because you
must target 2.1, or ... I can't think why else you'd do that ;)
You could create and register behaviors with an encode() method that
re-added qp-encoding and charset parameters, and of course qp-encode the
value (there's a build in codec or function for that, if I recall
correctly). I'm guessing this just isn't what you want, though.
Hope that helps!
Jeffrey
More information about the VObject
mailing list