Discussion:
[Bitpim-devel] Prep for 0.7.15 and vcard stuff
Roger Binns
2004-08-02 07:59:33 UTC
Permalink
I am desperately trying to get the vcard stuff into a workable
state by the end of Monday so we can do a build.

It is all sorts of fun exporting to vcard mainly because of
all the other programs out there not conforming.

For anyone who wants a project, improving the vcard import
and export is nice and self contained. Shout if you are
interested.

Roger
Roger Binns
2004-08-03 08:56:06 UTC
Permalink
Post by Roger Binns
I am desperately trying to get the vcard stuff into a workable
state by the end of Monday so we can do a build.
It is all sorts of fun exporting to vcard mainly because of
all the other programs out there not conforming.
For anyone who wants a project, improving the vcard import
and export is nice and self contained. Shout if you are
interested.
I have now written all the code for vcard export and would
appreciate people testing it before I do the build. Visually
the output is 100% correct, however I haven't found a single
program that will actually import them except Windows Address
Book! (Of course all the others just claim something is
wrong with the file but give no further details.)

The preferred form of testing is to import examples/vcards.vcf
and then export it again since all the fields are exercised
that way.

Any bug fixes and updates will be appreciated.

I will do the builds on Tuesday evening as I will be at the
LinuxWorld show during the day.

Roger
Adit Panchal
2004-08-05 23:57:50 UTC
Permalink
I found a slight problem with vCard exporting regarding the issue of
first and last name separation. For example, when exporting to either
to "Apple" or "vCard 3.0", the output of a simple contact from BitPim
is the following:

BEGIN:VCARD
VERSION:3.0
FN;ENCODING=QUOTED-PRINTABLE:John Doe=20
TEL;TYPE=CELL,PREF:1234567890
END:VCARD

When I try to import it into Apple Address Book, the first and last
name are all lumped together into the last name field. The phone number
imports fine.

After I correct this error within Address Book, the exported card looks
like the following:

BEGIN:VCARD
VERSION:3.0
N:Doe;John;;;
FN:John Doe
TEL;type=CELL;type=pref:(123) 456-7890
CATEGORY:Coworkers
END:VCARD

When I re-import this vCard back into Address Book or BitPim, it works
fine in both apps. I assume that the formatting of the "Apple" card
should be changed. I tried looking at your code to see how hard this
would be to change, but I am not familiar enough with it to make the
respective changes. I haven't had time to test all of the fields in
examples/vcards.vcf file, but this was the most outstanding issue I
could find.

Adit
Roger Binns
2004-08-06 05:37:26 UTC
Permalink
Post by Adit Panchal
BEGIN:VCARD
VERSION:3.0
FN;ENCODING=QUOTED-PRINTABLE:John Doe=20
TEL;TYPE=CELL,PREF:1234567890
END:VCARD
When I try to import it into Apple Address Book, the first and last
name are all lumped together into the last name field. The phone
number imports fine.
That is actually a sort of error in the Apple Address Book. Note
that I don't include an 'N' field which is the individual name
components broken out.

On re-reading the spec, VERSION, FN and N are required.
I was only supplying whichever ones BitPim actually had the data
for. I have now changed the code to always output FN and N
generating the data for bits it doesn't have. (It still doesn't
stop both Palm Desktop and Evolution not liking the file).

The trailing space (=20) I believe actually comes from part
of the import process, which the export is faithfully reproducing.
I'll have to look into that.
Post by Adit Panchal
After I correct this error within Address Book, the exported card
BEGIN:VCARD
VERSION:3.0
N:Doe;John;;;
FN:John Doe
TEL;type=CELL;type=pref:(123) 456-7890
CATEGORY:Coworkers
END:VCARD
That is pretty much the same thing as what BitPim exported.
The type= stuff can be written both as type=val1,val2 and as
type=val1;type=val2 according to the spec. (Needless to say
BitPim vcard import handles both even if both are on the
same line).
Post by Adit Panchal
When I re-import this vCard back into Address Book or BitPim, it works
fine in both apps. I assume that the formatting of the "Apple" card
should be changed. I tried looking at your code to see how hard this
would be to change, but I am not familiar enough with it to make the
respective changes. I haven't had time to test all of the fields in
examples/vcards.vcf file, but this was the most outstanding issue I
could find.
The code works at two levels. One is dealing with the formatting of
strings. vcard 3.0 requires all commas and semi-colons to be
backslash quoted. vcard 2.1 uses them as seperators, but doesn't
require quoting and most programs get hopelessly confused.

The code is all in vcard.py. format_stringv2 just removes commas
and semi-colons to make the issue go away. format_stringv3 quotes
them.

The other out_* functions output the various fields, and is based on
each key for a phonebook entry (see top of phonebook.py). One phonebook
key (eg names) will translate into one or more vcard fields (eg N, FN and
NICKNAME for names). [Note the out_line function is the actual
one that generates the resulting string including calling the formatters,
using quoted printable if necessary, and wrapping at 70 columns]

Sometimes there are different flavours of out functions. For example
Apple erroneously use "CATEGORY" as the vcard field name instead of
"CATEGORIES".

Additionally most places are limited in what they can accept. For example
BitPim lets each entry have between zero and an infinite number of names
whereas most other programs have a limit of exactly one.

All of these variations are brought together in the profiles at the bottom
of vcard.py. They specify which string formatter to use, what number to
output for the vcard version number, which out_ functions to use for
the various phonebook keys, and what limit to use for fields that have
them.

Roger

Loading...