Aleksander Machniak
2013-03-24 ae0821f1dd15baacd436d3337eb26a41d72204d0
Be less restrictive on vCard import, do not require FN when N exists
2 files modified
15 ■■■■ changed files
program/lib/Roundcube/rcube_vcard.php 4 ●●● patch | view | raw | blame | history
program/steps/addressbook/import.inc 11 ●●●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_vcard.php
@@ -491,7 +491,9 @@
            if (preg_match('/^END:VCARD$/i', $line)) {
                // parse vcard
                $obj = new rcube_vcard(self::cleanup($vcard_block), $charset, true, self::$fieldmap);
                if (!empty($obj->displayname) || !empty($obj->email)) {
                // FN and N is required by vCard format (RFC 2426)
                // on import we can be less restrictive, let's addressbook decide
                if (!empty($obj->displayname) || !empty($obj->surname) || !empty($obj->firstname) || !empty($obj->email)) {
                    $out[] = $obj;
                }
program/steps/addressbook/import.inc
@@ -209,6 +209,15 @@
        foreach ($vcards as $vcard) {
            $a_record = $vcard->get_assoc();
            // Generate contact's display name (must be before validation), the same we do in save.inc
            if (empty($a_record['name'])) {
                $a_record['name'] = rcube_addressbook::compose_display_name($a_record, true);
                // Reset it if equals to email address (from compose_display_name())
                if ($a_record['name'] == $a_record['email'][0]) {
                    $a_record['name'] = '';
                }
            }
            // skip invalid (incomplete) entries
            if (!$CONTACTS->validate($a_record, true)) {
                $IMPORT_STATS->invalid++;
@@ -250,7 +259,7 @@
            if ($success) {
                $IMPORT_STATS->inserted++;
                $IMPORT_STATS->names[] = $vcard->displayname ? $vcard->displayname : $email;
                $IMPORT_STATS->names[] = $a_record['name'] ? $a_record['name'] : $email;
            }
            else {
                $IMPORT_STATS->errors++;