aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/backend/ebook
diff options
context:
space:
mode:
Diffstat (limited to 'addressbook/backend/ebook')
-rw-r--r--addressbook/backend/ebook/e-card-compare.c75
-rw-r--r--addressbook/backend/ebook/e-destination.c25
2 files changed, 70 insertions, 30 deletions
diff --git a/addressbook/backend/ebook/e-card-compare.c b/addressbook/backend/ebook/e-card-compare.c
index 7ccfae0aa7..5cdc745dba 100644
--- a/addressbook/backend/ebook/e-card-compare.c
+++ b/addressbook/backend/ebook/e-card-compare.c
@@ -105,40 +105,72 @@ name_fragment_match (const gchar *a, const gchar *b)
ECardMatchType
e_card_compare_name_to_string (ECard *card, const gchar *str)
{
- gchar **namev;
+ gchar **namev, **givenv = NULL, **addv = NULL, **familyv = NULL;
gboolean matched_given = FALSE, matched_additional = FALSE, matched_family = FALSE, mismatch = FALSE;
ECardMatchType match_type;
- gint i;
+ gint match_count = 0;
+ gint i, j;
+ gchar *str_cpy, *s;
g_return_val_if_fail (E_IS_CARD (card), E_CARD_MATCH_NOT_APPLICABLE);
g_return_val_if_fail (card->name != NULL, E_CARD_MATCH_NOT_APPLICABLE);
g_return_val_if_fail (str != NULL, E_CARD_MATCH_NOT_APPLICABLE);
- namev = g_strsplit (str, " ", 0);
+ /* FIXME: utf-8 */
+ str_cpy = s = g_strdup (str);
+ while (*s) {
+ if (*s == ',' || *s == '"')
+ *s = ' ';
+ ++s;
+ }
+ namev = g_strsplit (str_cpy, " ", 0);
+ g_free (str_cpy);
+
+ if (card->name->given)
+ givenv = g_strsplit (card->name->given, " ", 0);
+ if (card->name->additional)
+ addv = g_strsplit (card->name->additional, " ", 0);
+ if (card->name->family)
+ familyv = g_strsplit (card->name->family, " ", 0);
for (i = 0; namev[i] && !mismatch; ++i) {
-
- if (card->name->given
- && !matched_given
- && name_fragment_match (card->name->given, namev[i])) {
-
- matched_given = TRUE;
- } else if (card->name->additional
- && !matched_additional
- && name_fragment_match (card->name->additional, namev[i])) {
+ if (*namev[i]) {
- matched_additional = TRUE;
-
- } else if (card->name->family
- && !matched_family
- && !g_utf8_strcasecmp (card->name->family, namev[i])) {
+ mismatch = TRUE;
- matched_family = TRUE;
+ if (mismatch && givenv) {
+ for (j = 0; givenv[j]; ++j) {
+ if (name_fragment_match (givenv[j], namev[i])) {
+ matched_given = TRUE;
+ mismatch = FALSE;
+ ++match_count;
+ break;
+ }
+ }
+ }
- } else {
+ if (mismatch && addv) {
+ for (j = 0; addv[j]; ++j) {
+ if (name_fragment_match (addv[j], namev[i])) {
+ matched_additional = TRUE;
+ mismatch = FALSE;
+ ++match_count;
+ break;
+ }
+ }
+ }
- mismatch = TRUE;
+ if (mismatch && familyv) {
+ for (j = 0; familyv[j]; ++j) {
+ if (!g_utf8_strcasecmp (familyv[j], namev[i])) {
+ matched_family = TRUE;
+ mismatch = FALSE;
+ ++match_count;
+ break;
+ }
+ }
+ }
}
}
@@ -163,6 +195,9 @@ e_card_compare_name_to_string (ECard *card, const gchar *str)
}
g_strfreev (namev);
+ g_strfreev (givenv);
+ g_strfreev (addv);
+ g_strfreev (familyv);
return match_type;
}
diff --git a/addressbook/backend/ebook/e-destination.c b/addressbook/backend/ebook/e-destination.c
index c5287e5e6d..970057f1fe 100644
--- a/addressbook/backend/ebook/e-destination.c
+++ b/addressbook/backend/ebook/e-destination.c
@@ -473,6 +473,8 @@ e_destination_set_name (EDestination *dest, const gchar *name)
if (changed) {
g_free (dest->priv->addr);
dest->priv->addr = NULL;
+ g_free (dest->priv->textrep);
+ dest->priv->textrep = NULL;
e_destination_changed (dest);
}
}
@@ -501,6 +503,8 @@ e_destination_set_email (EDestination *dest, const gchar *email)
if (changed) {
g_free (dest->priv->addr);
dest->priv->addr = NULL;
+ g_free (dest->priv->textrep);
+ dest->priv->textrep = NULL;
e_destination_changed (dest);
}
}
@@ -812,17 +816,18 @@ e_destination_get_textrep (const EDestination *dest)
if (e_destination_from_card (dest) && name != NULL)
return name;
- if (name && email) {
- gchar *rep = g_strdup_printf ("%s <%s>", name, email);
- if (dest->priv->textrep && !strcmp (rep, dest->priv->textrep)) {
- g_free (rep);
- } else {
- g_free (dest->priv->textrep);
- dest->priv->textrep = rep;
- }
- return dest->priv->textrep;
+ /* Make sure that our address gets quoted properly */
+ if (name && email && dest->priv->textrep == NULL) {
+ CamelInternetAddress *addr = camel_internet_address_new ();
+ camel_internet_address_add (addr, name, email);
+ g_free (dest->priv->textrep);
+ dest->priv->textrep = camel_address_encode (CAMEL_ADDRESS (addr));
+ camel_object_unref (CAMEL_OBJECT (addr));
}
+ if (dest->priv->textrep != NULL)
+ return dest->priv->textrep;
+
if (email)
return email;
@@ -908,7 +913,7 @@ static void
name_and_email_simple_query_cb (EBook *book, EBookSimpleQueryStatus status, const GList *cards, gpointer closure)
{
EDestination *dest = E_DESTINATION (closure);
-
+
if (status == E_BOOK_SIMPLE_QUERY_STATUS_SUCCESS && g_list_length ((GList *) cards) == 1) {
ECard *card = E_CARD (cards->data);
const gchar *email = e_destination_get_email (dest);