Author Topic: Feng Office 1.6.2 : Vcard import is not importing e-mails, address and photo  (Read 4331 times)

marcopico

  • Newbie
  • *
  • Posts: 6
    • View Profile
Hello,

i tried to import a Vcard file from my Evolution contact list.
The import went well, but i noticed that some information are missing like :
- e-mail adresses
- Adresses
- Photo

Hope this can help,
thanks for developping Fengoffice !

Marco

markc

  • Freshman
  • *
  • Posts: 47
    • View Profile
I have this issue also. In fact...I created a test contact and filled out every field and then exported to vcard.

Importing back in from that 'native' (if you will) vcard also has this issue. The first thing that jumps out at me is that the vcard export function is comma delimiting the address field whereas the import function's regex is looking for semi-colons.

I'll look at some other implementations to see if maybe I'm missing something and then I'll see if I can offer a patch for this.

markc

  • Freshman
  • *
  • Posts: 47
    • View Profile
From what I can find...

vcard 2.1
http://www.imc.org/pdi/vcard-21.txt

vcard 3.0
http://www.ietf.org/rfc/rfc2425.txt
http://www.ietf.org/rfc/rfc2426.txt

1. The current build_vcard function in ./application/controllers/ContactController.class.php inserts a parameter for the charset into many of the fields. According to RFC2426:
Quote
The [VCARD] CHARSET type parameter has been eliminated. Character set can only be specified on the CHARSET parameter on the Content-Type MIME header field.

this practice is no longer allowed in the 3.0 spec (and this function is printing 3.0 as its version). So I'm making a patch that takes those out. I don't think that fixes the overall problem, but that's what the spec says. Also I don't think MIME headers really apply to plaintext vcard files and the topic of character sets and encoding predates me a bit so I can only assume the maintainers knew what they were doing in making this change.

2. Another couple excerpts:
rfc2425
Quote
Each attribute defined in the text/directory body MAY have multiple values, if allowed in the definition of the profile in which the attribute is used. The general rule for encoding multi-valued items is to simply create a new content line for each value (including the type name).  However, it should be noted that some value types support encoding multiple values in a single content line by separating the values with a comma ",".  This approach has been taken for several of the content types defined below (date, time, integer, float), for space-saving reasons.

rfc2426
Quote
The text components are separated by the SEMI-COLON character (ASCII decimal 59). Where it makes semantic sense, individual text components can include multiple text values (e.g., a "street" component with multiple lines) separated by the COMMA character (ASCII decimal 44).

I believe these (and other pieces) say that not only are there multiple address fields, but that each field can have multiple lines using commas. You can also apparently put multiple entire ADR records (also works for a few other types) on one line using commas, but there was no mention that I could find of separating the fields themselves with commas. So I'll also change the field delimiters to semi-colons.

The regexs in the import function seem to already expect semi-colons so no change there. They are also looking for the charset though so I'll patch that out.

It's a start. If anyone sees anything I've got wrong please let me know.

Thank you,
Mark

markc

  • Freshman
  • *
  • Posts: 47
    • View Profile
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:
Code: [Select]
  } 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:
Code: [Select]
  } 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.
Code: [Select]
-  } 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

ignacio

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
Thank you, we'll take a look at this.