diff --git a/CHANGELOG.md b/CHANGELOG.md index a9a92d320..d3676186a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Fixed import of vCard 4.0 contacts with only FN field ([#465]) ## [1.6.0] - 2026-01-30 ### Added diff --git a/app/src/main/kotlin/org/fossify/contacts/helpers/VcfImporter.kt b/app/src/main/kotlin/org/fossify/contacts/helpers/VcfImporter.kt index d966813d9..680145b2d 100644 --- a/app/src/main/kotlin/org/fossify/contacts/helpers/VcfImporter.kt +++ b/app/src/main/kotlin/org/fossify/contacts/helpers/VcfImporter.kt @@ -55,9 +55,18 @@ class VcfImporter(val activity: SimpleActivity) { for (ezContact in ezContacts) { val structuredName = ezContact.structuredName val prefix = structuredName?.prefixes?.firstOrNull() ?: "" - val firstName = structuredName?.given ?: "" - val middleName = structuredName?.additionalNames?.firstOrNull() ?: "" - val surname = structuredName?.family ?: "" + var firstName = structuredName?.given ?: "" + var middleName = structuredName?.additionalNames?.firstOrNull() ?: "" + var surname = structuredName?.family ?: "" + + if (structuredName == null && ezContact.formattedName?.value?.isNotBlank() == true) { + val fn = ezContact.formattedName.value.trim() + val parts = fn.split("\\s+".toRegex(), limit = 2) + + firstName = parts.getOrNull(0) ?: "" + surname = parts.getOrNull(1) ?: "" + } + val suffix = structuredName?.suffixes?.firstOrNull() ?: "" val nickname = ezContact.nickname?.values?.firstOrNull() ?: "" var photoUri = "" @@ -268,16 +277,6 @@ class VcfImporter(val activity: SimpleActivity) { ringtone = ringtone ) - // if there is no N and ORG fields at the given contact, only FN, treat it as an organization - if ( - contact.getNameToDisplay().isEmpty() - && contact.organization.isEmpty() - && ezContact.formattedName?.value?.isNotEmpty() == true - ) { - contact.organization.company = ezContact.formattedName.value - contact.mimetype = CommonDataKinds.Organization.CONTENT_ITEM_TYPE - } - if (contact.isABusinessContact()) { contact.mimetype = CommonDataKinds.Organization.CONTENT_ITEM_TYPE }