Intermesh / groupoffice

Group Office groupware and CRM
https://www.group-office.com
Other
193 stars 46 forks source link

Importing vCard without Name #587

Closed gtech99 closed 4 years ago

gtech99 commented 4 years ago

GO can't import vCards that don't have the N field set. The error thrown is pretty ugly too.

I modified the code in go/modules/community/addressbook/convert/VCard.php line 268 to set the name of the contact to the same as the e-mail, if present. Probably not the best way to do it, but it works:

            if (isset($vcardComponent->N)) {
                    $n = $vcardComponent->N->getParts();
                    $entity->lastName = $n[0] ?? null;
                    $entity->firstName = $n[1] ?? null;
                    $entity->middleName = $n[2] ?? null;
                    $entity->prefixes = $n[3] ?? null;
                    $entity->suffixes = $n[4] ?? null;
                    $entity->name = (string) $vcardComponent->FN ?? self::EMPTY_NAME;
            }

            $this->importDate($entity, Date::TYPE_BIRTHDAY, $vcardComponent->BDAY);
            $this->importDate($entity, Date::TYPE_ANNIVERSARY, $vcardComponent->ANNIVERSARY);

            empty($vcardComponent->NOTE) ?: $entity->notes = (string) $vcardComponent->NOTE;
            $entity->emailAddresses = $this->importHasMany($entity->emailAddresses, $vcardComponent->EMAIL, EmailAddress::

class, function($value) { return ['email' => (string) $value]; });

            if (empty($entity->name) && empty($entity->lastName) && empty($entity->firstName) && is_array($entity->emailAddresses)) {
                    $entity->name = $entity->emailAddresses[0];
            }
mschering commented 4 years ago

Fixed in the next release.