Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 17 additions & 11 deletions app/src/main/kotlin/org/fossify/contacts/helpers/VcfImporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,26 @@ class VcfImporter(val activity: SimpleActivity) {
for (ezContact in ezContacts) {
val structuredName = ezContact.structuredName
val prefix = structuredName?.prefixes?.firstOrNull() ?: ""
val firstName = structuredName?.given ?: ""
var firstName = structuredName?.given ?: ""
val middleName = structuredName?.additionalNames?.firstOrNull() ?: ""
val surname = structuredName?.family ?: ""
val suffix = structuredName?.suffixes?.firstOrNull() ?: ""

// vCard 4.0 makes the structured name (N) optional while the
// formatted name (FN) is mandatory. When N is missing or yields
// no usable parts, fall back to FN. FN is a free-form display
// string with no guaranteed word order, so we keep it intact in
// firstName instead of guessing a given/family split, which
// would silently corrupt names like "von Neumann" or non-Western
// name orders.
val hasStructuredName = firstName.isNotBlank()
|| middleName.isNotBlank()
|| surname.isNotBlank()
val formattedName = ezContact.formattedName?.value?.trim().orEmpty()
if (!hasStructuredName && formattedName.isNotBlank()) {
firstName = formattedName
}

val nickname = ezContact.nickname?.values?.firstOrNull() ?: ""
var photoUri = ""

Expand Down Expand Up @@ -268,16 +284,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
}
Expand Down
Loading