Okay so I have some progress on this. I'm attaching a patch that makes some changes, mainly to address handling, and so far the addresses are exporting and importing correctly for me. ymmv.
Changes:
1. As I'd said previously the export function was printing commas and as far as I can tell that is out of spec. So I've changed the export function to delimit fields with semi-colon. (which is what import was looking for anyway)
2. The vcard 3.0 spec also seems to now frown upon printing charset data as a parameter inline with the vcard data. So I've taken those out of the export function. However I noticed that in the import function it is an OR, and that if it finds the charset data it does nothing with it. If it isn't there then no problem. That doesn't hurt anything so I've left it in there.
3. The original address regex:
} else if (preg_match('/ADR;type=(HOME|WORK)[,A-Z]*;(charset=[-a-zA-Z0-9.]+|type=pref):;;([^;]*);([^;]*);([^;]*);([^;]*);([^;]*)/i', $line, $matches)
only matches if the type is home or work AND OPTIONALLY something else. It seems to me (and my testing showed) that it won't match/function at all if the type is simply Other, or Parcel, or (what the export function prints) INTL. I've changed it to be:
} else if (preg_match('/ADR;type=(HOME|WORK|[A-Z0-9]*)[,A-Z]*(:|;charset=[-a-zA-Z0-9.]+:|;type=pref:)([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);
to match work or home OR other, and then allow for additional fields after that. It isn't perfect, such as when there is a distinct work and home address but Parcel, Post, Pref etc are listed first in the type= field.
3.a Also in the same lines...the regexes for the other vcard lines allowed the option of the charset field "(:|;charset...", but the ADR line assumed it to be there (or a type=pref directive). So I made it like the others to (hopefully) also be more flexible.
4.
- } else if (preg_match('/URL(;type=(HOME|WORK))?.*:(.+)/i', $line, $matches)) {
+ } else if (preg_match('/URL(;type=(HOME|WORK))?.*?:(.+)/i', $line, $matches)) {
just switches another one of the regex operators to be lazy, so that given "URL:http://www.something.com" it will now find the first colon and not cut off half the field.
I'm still seeing some phone numbers and other fields end up in different places after exporting and re-importing a contact, and I didn't touch the photo stuff. I'll probably do a little more but I didn't want to wait and have a ten page post all at the end.
As always let me know if you have any suggestions or corrections.
Ty,
Mark
application details:
cd to your fengoffice root and
sudo patch -p1 --dry-run < /path/to/vcard.patch (and if no errors show...)
sudo patch -p1 < /path/to/vcard.patch
to remove: sudo patch -R -p1 < /path/to/vcard.patch