Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 581eac41 authored by Ricki Hirner's avatar Ricki Hirner
Browse files

Don't send Android's StructuredPostal.FORMATTED_ADDRESS as vCard LABEL anymore

- FORMATTED_ADDRESS is only used for displaying the contact on Android; it can't be set by users
- generated LABELs that don't have additional information are redundant and regularly confuse other clients and users
- the valid case that we receive a LABEL and should retain it is less important that the two cases mentioned above
parent 4c30847a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ class StructuredPostalBuilderTest {
            assertEquals("ZIP", result[0].values[StructuredPostal.POSTCODE])
            assertEquals("Country", result[0].values[StructuredPostal.COUNTRY])

            assertEquals("Street 1\n" +
            assertEquals("Street 1\n" +     // European format
                    "(Corner Street 2)\n" +
                    "PO Box 123\n" +
                    "Hood\n" +
+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ class StructuredPostalHandlerTest {
        assertArrayEquals(arrayOf("Sampleregion"), contact.addresses[0].property.regions.toTypedArray())
        assertArrayEquals(arrayOf("ZIP"), contact.addresses[0].property.postalCodes.toTypedArray())
        assertArrayEquals(arrayOf("Samplecountry"), contact.addresses[0].property.countries.toTypedArray())
        assertEquals("Full Formatted Address", contact.addresses[0].property.label)
        assertNull(contact.addresses[0].property.label)
    }


+6 −14
Original line number Diff line number Diff line
@@ -14,20 +14,6 @@ import java.util.*

/**
 * Data row builder for structured addresses.
 *
 * Android requires a formatted address. If the contact data doesn't contain a
 * formatted address, it's built like this:
 *
 *     | field             | example                      |
 *     |-------------------|------------------------------|
 *     | street            | Sample Street 123            |
 *     | poBox             | P/O Box 45                   |
 *     | extended          | Near the park                |
 *     | postalCode city   | 12345 Sampletown             |
 *     | country (region)  | Samplecountry (Sampleregion) |
 *
 * TODO: should be localized (there are many different international formats)
 *
 */
class StructuredPostalBuilder(dataRowUri: Uri, rawContactId: Long?, contact: Contact)
    : DataRowBuilder(Factory.mimeType(), dataRowUri, rawContactId, contact) {
@@ -37,6 +23,12 @@ class StructuredPostalBuilder(dataRowUri: Uri, rawContactId: Long?, contact: Con
        for (labeledAddress in contact.addresses) {
            val address = labeledAddress.property

            /* Generate the formatted address (the one contacts app show in the preview) in European format.
             *
             * If we wouldn't do that, the content provider would format it US-EN or JP style:
             * https://android.googlesource.com/platform/packages/providers/ContactsProvider.git/+/refs/heads/android13-release/src/com/android/providers/contacts/PostalSplitter.java#84
             *
             * Could be localized here (but it's still only for viewing the contact on Android and won't be put into a vCard). */
            var formattedAddress = address.label
            if (formattedAddress.isNullOrBlank()) {
                val lines = LinkedList<String>()
+10 −1
Original line number Diff line number Diff line
@@ -21,7 +21,16 @@ object StructuredPostalHandler: DataRowHandler() {
        val address = Address()
        val labeledAddress = LabeledProperty(address)

        address.label = values.getAsString(StructuredPostal.FORMATTED_ADDRESS)
        /* Sep 2022: We don't set the vCard LABEL anymore. Reasons:
         *
         * 1. It can't be entered by the user anyway because no contacts app has a separate field for "formatted address"
         *    [https://www.davx5.com/faq/entering-structured-addresses], which is only used as read-only field to display an address.
         * 2. It confuses other CalDAV user agents which don't support LABEL (the majority). When such a client receives
         *    and retains the LABEL although the structured address is changed, there are two inconsistent addresses.
         *    [https://github.com/nextcloud/contacts/issues/1900]
         */
        //address.label = values.getAsString(StructuredPostal.FORMATTED_ADDRESS)

        when (values.getAsInteger(StructuredPostal.TYPE)) {
            StructuredPostal.TYPE_HOME ->
                address.types += AddressType.HOME