[evolution-ews/evolution-ews-3-12] Use (hashed) PidTagEmailAddress for OAB item UID



commit 6f69508dba9bd823984f718c4e62e0cdb8a85f54
Author: David Woodhouse <David Woodhouse intel com>
Date:   Thu Sep 4 14:02:53 2014 +0100

    Use (hashed) PidTagEmailAddress for OAB item UID
    
    The PidTagSmtpAddress isn't always unique.
    
    (cherry picked from commit b560d914a59570bd1955db348087ec0053837e91)

 src/addressbook/ews-oab-decoder.c |   29 ++++++++++++++++++++++-------
 1 files changed, 22 insertions(+), 7 deletions(-)
---
diff --git a/src/addressbook/ews-oab-decoder.c b/src/addressbook/ews-oab-decoder.c
index da2d26f..e3a4a43 100644
--- a/src/addressbook/ews-oab-decoder.c
+++ b/src/addressbook/ews-oab-decoder.c
@@ -63,6 +63,19 @@ typedef struct {
 } EwsDeferredSet;
 
 static void
+ews_populate_string_sha1 (EContact *contact,
+                         EContactField field,
+                         gpointer value,
+                         gpointer user_data)
+{
+       gchar *sum;
+
+       sum = g_compute_checksum_for_string (G_CHECKSUM_SHA1, (const gchar *) value, -1);
+       e_contact_set (contact, field, sum);
+       g_free (sum);
+}
+
+static void
 ews_populate_simple_string (EContact *contact,
                             EContactField field,
                             gpointer value,
@@ -207,6 +220,7 @@ static const struct prop_field_mapping {
        void (*populate_function) (EContact *contact, EContactField field, gpointer value, gpointer 
user_data);
        void (*defered_populate_function) (EwsDeferredSet *dset, guint32 prop_id, gpointer value);
 } prop_map[] = {
+       {EWS_PT_EMAIL_ADDRESS, E_CONTACT_UID, ews_populate_string_sha1},
        {EWS_PT_SMTP_ADDRESS, E_CONTACT_EMAIL_1, ews_populate_simple_string},
        {EWS_PT_DISPLAY_NAME, E_CONTACT_FULL_NAME, ews_populate_simple_string},
        {EWS_PT_ACCOUNT, E_CONTACT_NICKNAME, ews_populate_simple_string},
@@ -894,7 +908,7 @@ ews_decode_addressbook_record (EwsOabDecoder *eod,
        EwsOabDecoderPrivate *priv = GET_PRIVATE (eod);
        EwsDeferredSet *dset = NULL;
        guint bit_array_size, i, len;
-       gchar *bit_str, *uid;
+       gchar *bit_str;
        gboolean ret = TRUE;
 
        len = g_slist_length (props);
@@ -962,12 +976,13 @@ exit:
        g_free (dset);
 
        /* set the smtp address as contact's uid */
-       uid = (gchar *) e_contact_get (contact, E_CONTACT_EMAIL_1);
-       if (uid && *uid) {
-               e_contact_set (contact, E_CONTACT_UID, uid);
-               g_free (uid);
-       } else
-               ret = FALSE;
+       if (!e_contact_get_const(contact, E_CONTACT_UID)) {
+               const gchar *uid = e_contact_get_const (contact, E_CONTACT_EMAIL_1);
+               if (uid && *uid)
+                       e_contact_set (contact, E_CONTACT_UID, uid);
+               else
+                       ret = FALSE;
+       }
 
        return ret;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]