From: Tim Waugh Date: Mon, 19 Jan 2015 23:11:51 +0000 (+0000) Subject: Handle vcard entries with addresses but no address labels (bug #742441). X-Git-Tag: glabels-3_4_0~106 X-Git-Url: https://git.sur5r.net/?p=glabels;a=commitdiff_plain;h=abb54d7416428501e26f9a121135ddc043034b61 Handle vcard entries with addresses but no address labels (bug #742441). Fixes Bug #742441. A vcard entry that has no address labels but does include structured address components can be handled by fabricating the address label from the address components. --- diff --git a/src/merge-vcard.c b/src/merge-vcard.c index 57e1817d..1ab8e606 100644 --- a/src/merge-vcard.c +++ b/src/merge-vcard.c @@ -256,6 +256,23 @@ gl_merge_vcard_close (glMerge *merge) } +static gchar * +maybe_field (const gchar *str) +{ + if (str && *str) { + /* Copy it, allocating enough for an extra newline */ + gchar *copy = g_strconcat (str, "\n", NULL); + /* Strip trailing whitespace */ + size_t len = strlen (g_strchomp (copy)); + /* Add back in a single newline */ + if (len > 0) + copy[len] = '\n'; + return copy; + } + + return g_strdup (""); +} + /*--------------------------------------------------------------------------*/ /* Get next record from merge source, NULL if no records left (i.e EOF) */ /*--------------------------------------------------------------------------*/ @@ -293,6 +310,51 @@ gl_merge_vcard_get_record (glMerge *merge) gchar *value; value = g_strdup (e_contact_get_const (contact, field_id)); + if (!value && + field_id >= E_CONTACT_ADDRESS_LABEL_HOME && + field_id <= E_CONTACT_ADDRESS_LABEL_OTHER) { + EContactAddress *address; + EContactField addrfield; + addrfield = (field_id - + E_CONTACT_ADDRESS_LABEL_HOME + + E_CONTACT_ADDRESS_HOME); + address = e_contact_get (contact, addrfield); + if (address) { + gchar *val; + gchar *field; + GString *gstr = g_string_new (""); + + field = maybe_field (address->street); + g_string_append_printf (gstr, "%s", field); + g_free (field); + + field = maybe_field (address->ext); + g_string_append_printf (gstr, "%s", field); + g_free (field); + + field = maybe_field (address->locality); + g_string_append_printf (gstr, "%s", field); + g_free (field); + + field = maybe_field (address->region); + g_string_append_printf (gstr, "%s", field); + g_free (field); + + field = maybe_field (address->code); + g_string_append_printf (gstr, "%s", field); + g_free (field); + + field = maybe_field (address->country); + g_string_append_printf (gstr, "%s", field); + g_free (field); + + value = g_strdup (gstr->str); + g_strchomp (value); + g_string_free (gstr, TRUE); + e_contact_address_free (address); + } + } + if (value) { field = g_new0 (glMergeField, 1); field->key = g_strdup (e_contact_pretty_name (field_id));