[evolution-ews] Use "X-EWS-KIND" attribute



commit 13ca0c376e5811cfb93968f8f494cc318a96f1a7
Author: Fabiano Fidêncio <fidencio redhat com>
Date:   Thu May 16 05:03:12 2013 +0200

    Use "X-EWS-KIND" attribute
    
    For now it's only an internal hidden information, to tell us what the
    contact is from the server's point of view, until there is a vCard 4.0
    implemented.
    
    Note: at least for now, is only possible to create DT_MAILUSER and
    DT_DISTLIST using Evolution EWS.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=654454

 src/addressbook/e-book-backend-ews.c |   96 +++++++++++++++++++++-------------
 src/addressbook/ews-oab-decoder.c    |   82 +++++++++++++++++++++++++++++
 src/addressbook/ews-oab-props.h      |   14 +++++
 3 files changed, 156 insertions(+), 36 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-ews.c b/src/addressbook/e-book-backend-ews.c
index 584b0d2..23ee418 100644
--- a/src/addressbook/e-book-backend-ews.c
+++ b/src/addressbook/e-book-backend-ews.c
@@ -1225,6 +1225,7 @@ typedef struct {
        EContact *contact;
        guint32 opid;
        GCancellable *cancellable;
+       gboolean is_dl;
 } EwsCreateContact;
 
 static void
@@ -1331,11 +1332,18 @@ ews_create_contact_cb (GObject *object,
        g_return_if_fail (ebews->priv->summary != NULL);
 
        if (error == NULL) {
-               EEwsItem *item = (EEwsItem *) items->data;
+               EEwsItem *item = items->data;
                EContactPhoto *photo;
+               EVCardAttribute *attr;
+
+               attr = e_vcard_attribute_new (NULL, "X-EWS-KIND");
+               e_vcard_add_attribute_with_value (
+                               E_VCARD (create_contact->contact),
+                               attr,
+                               create_contact->is_dl ? "DT_DISTLIST" : "DT_MAILUSER");
 
                /* set item id */
-               item_id = e_ews_item_get_id ((EEwsItem *) items->data);
+               item_id = e_ews_item_get_id (item);
 
                e_contact_set (create_contact->contact, E_CONTACT_UID, item_id->id);
                e_contact_set (create_contact->contact, E_CONTACT_REV, item_id->change_key);
@@ -1454,6 +1462,7 @@ e_book_backend_ews_create_contacts (EBookBackend *backend,
        create_contact->opid = opid;
        create_contact->contact = g_object_ref (contact);
        create_contact->cancellable = g_object_ref (cancellable);
+       create_contact->is_dl = is_dl;
 
        fid = e_ews_folder_id_new (priv->folder_id, NULL, FALSE);
 
@@ -2607,10 +2616,36 @@ ebews_sync_deleted_items (EBookBackendEws *ebews,
        g_slist_free_full (deleted_ids, g_free);
 }
 
+static EContact *
+ebews_get_contact_info (EBookBackendEws *ebews,
+                       EEwsItem *item,
+                       GCancellable *cancellable,
+                       GError **error)
+{
+       EContact *contact;
+       gint i, element_type;
+
+       contact = e_contact_new ();
+
+       for (i = 0; i < G_N_ELEMENTS (mappings); i++) {
+               element_type = mappings[i].element_type;
+
+               if (element_type == ELEMENT_TYPE_SIMPLE && !mappings[i].populate_contact_func) {
+                       const gchar *val = mappings[i].get_simple_prop_func (item);
+
+                       if (val != NULL)
+                               e_contact_set (contact, mappings[i].field_id, val);
+               } else {
+                       mappings[i].populate_contact_func (ebews, contact, item, cancellable, error);
+               }
+       }
+
+       return contact;
+}
+
 static void
 ebews_store_contact_items (EBookBackendEws *ebews,
                            GSList *new_items,
-                           gboolean distribution_list,
                           GCancellable *cancellable,
                            GError **error)
 {
@@ -2623,32 +2658,19 @@ ebews_store_contact_items (EBookBackendEws *ebews,
 
        for (l = new_items; l != NULL; l = g_slist_next (l)) {
                EContact *contact;
-               gint i, element_type;
-               EEwsItem *item;
+               EEwsItem *item = l->data;
+               EVCardAttribute *attr;
 
-               item = (EEwsItem *) l->data;
+               item = l->data;
                if (e_ews_item_get_item_type (item) == E_EWS_ITEM_TYPE_ERROR) {
                        g_object_unref (item);
                        continue;
                }
 
-               contact = e_contact_new ();
-
-               if (!distribution_list) {
-                       for (i = 0; i < G_N_ELEMENTS (mappings); i++) {
-                               element_type = mappings[i].element_type;
+               contact = ebews_get_contact_info (ebews, item, cancellable, error);
 
-                               if (element_type == ELEMENT_TYPE_SIMPLE && 
!mappings[i].populate_contact_func) {
-                                       const gchar *val = mappings[i].get_simple_prop_func (item);
-
-                                       if (val != NULL)
-                                               e_contact_set (contact, mappings[i].field_id, val);
-                               } else
-                                       mappings[i].populate_contact_func (ebews, contact, item, cancellable, 
error);
-                       }
-               } else {
-                       /* store display_name, fileas, item id */       
-               }
+               attr = e_vcard_attribute_new (NULL, "X-EWS-KIND");
+               e_vcard_add_attribute_with_value (E_VCARD (contact), attr, "DT_MAILUSER");
 
                e_book_backend_sqlitedb_new_contact (priv->summary, priv->folder_id, contact, TRUE, error);
                e_book_backend_notify_update (E_BOOK_BACKEND (ebews), contact);
@@ -2671,27 +2693,20 @@ ebews_get_vcards_list (EBookBackendEws *ebews,
 
        for (l = new_items; l != NULL; l = g_slist_next (l)) {
                EContact *contact;
-               gint i, element_type;
-               EEwsItem *item;
+               EEwsItem *item = l->data;
                gchar *vcard_string = NULL;
+               EVCardAttribute *attr;
 
-               item = (EEwsItem *) l->data;
                if (e_ews_item_get_item_type (item) == E_EWS_ITEM_TYPE_ERROR) {
                        g_object_unref (item);
                        continue;
                }
 
-               contact = e_contact_new ();
+               contact = ebews_get_contact_info (ebews, item, cancellable, error);
+
+               attr = e_vcard_attribute_new (NULL, "X-EWS-KIND");
+               e_vcard_add_attribute_with_value (E_VCARD (contact), attr, "DT_MAILUSER");
 
-               for (i = 0; i < G_N_ELEMENTS (mappings); i++) {
-                       element_type = mappings[i].element_type;
-                       if (element_type == ELEMENT_TYPE_SIMPLE && !mappings[i].populate_contact_func) {
-                               const gchar *val = mappings[i].get_simple_prop_func (item);
-                               if (val != NULL)
-                                       e_contact_set (contact, mappings[i].field_id, val);
-                       } else
-                               mappings[i].populate_contact_func (ebews, contact, item, cancellable, error);
-               }
                vcard_string = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30);
                *vcards = g_slist_append (*vcards, g_strdup(vcard_string));
                g_free (vcard_string);
@@ -2811,12 +2826,17 @@ ebews_store_distribution_list_items (EBookBackendEws *ebews,
                                      GError **error)
 {
        EContact *contact;
+       EVCardAttribute *attr;
+
        g_return_if_fail (ebews->priv->summary != NULL);
 
        contact = ebews_get_dl_info (ebews, id, d_name, members, error);
        if (contact == NULL)
                return;
 
+       attr = e_vcard_attribute_new (NULL, "X-EWS-KIND");
+       e_vcard_add_attribute_with_value (E_VCARD (contact), attr, "DT_DISTLIST");
+
        e_book_backend_sqlitedb_new_contact (ebews->priv->summary, ebews->priv->folder_id, contact, TRUE, 
error);
        e_book_backend_notify_update (E_BOOK_BACKEND (ebews), contact);
 
@@ -2832,12 +2852,16 @@ ebews_vcards_append_dl (EBookBackendEws *ebews,
                        GError **error)
 {
        EContact *contact;
+       EVCardAttribute *attr;
        gchar *vcard_string = NULL;
 
        contact = ebews_get_dl_info (ebews, id, d_name, members, error);
        if (contact == NULL)
                return;
 
+       attr = e_vcard_attribute_new (NULL, "X-EWS-KIND");
+       e_vcard_add_attribute_with_value (E_VCARD (contact), attr, "DT_DISTLIST");
+
        vcard_string = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30);
        *vcards = g_slist_append (*vcards, g_strdup(vcard_string));
 
@@ -2895,7 +2919,7 @@ ebews_fetch_items (EBookBackendEws *ebews,
 
        if (new_items) {
                if (store_to_cache)
-                       ebews_store_contact_items (ebews, new_items, FALSE, cancellable, error);
+                       ebews_store_contact_items (ebews, new_items, cancellable, error);
                else
                        ebews_get_vcards_list (ebews, new_items, vcards, cancellable, error);
        }
diff --git a/src/addressbook/ews-oab-decoder.c b/src/addressbook/ews-oab-decoder.c
index 8bea126..7727dac 100644
--- a/src/addressbook/ews-oab-decoder.c
+++ b/src/addressbook/ews-oab-decoder.c
@@ -764,6 +764,82 @@ ews_destroy_oab_prop (guint32 prop_id,
        }
 }
 
+static const gchar *
+ews_decode_addressbook_get_display_type (guint32 value)
+{
+       const gchar *display_type = NULL;
+
+       switch (value) {
+               case EWS_DT_MAILUSER:
+               /*
+                * DT_MAILUSER means that the display type could be, besides itself, one of
+                * these extended types: DT_ROOM, DT_EQUIPMENT, DT_SEC_DISTLIST. Considering
+                * this, we can just ignore this case here and treat it properly in the
+                * ews_decode_addressbook_get_display_type_extended() function.
+                */
+                       break;
+               case EWS_DT_DISTLIST:
+                       display_type = "DT_DISTLIST";
+                       break;
+               case EWS_DT_FORUM:
+                       display_type = "DT_FORUM";
+                       break;
+               case EWS_DT_AGENT:
+                       display_type = "DT_AGENT";
+                       break;
+               case EWS_DT_ORGANIZATION:
+                       display_type = "DT_ORGANIZATION";
+                       break;
+               case EWS_DT_PRIVATE_DISTLIST:
+                       display_type = "DT_PRIVATE_DISTLIST";
+                       break;
+               case EWS_DT_REMOTE_MAILUSER:
+                       display_type = "DT_PRIVATE_MAILUSER";
+                       break;
+       }
+
+       return display_type;
+}
+
+static const gchar *
+ews_decode_addressbook_get_display_type_extended (guint32 value)
+{
+       const gchar *display_type = "DT_MAILUSER";
+
+       switch (value) {
+               case EWS_DT_ROOM:
+                       display_type = "DT_ROOM";
+                       break;
+               case EWS_DT_EQUIPMENT:
+                       display_type = "DT_EQUIPMENT";
+                       break;
+               case EWS_DT_SEC_DISTLIST:
+                       display_type = "DT_SEC_DISTLIST";
+                       break;
+       }
+
+       return display_type;
+}
+
+static void
+ews_decode_addressbook_write_display_type (EContact **contact,
+                                          guint32 value,
+                                          gboolean extended)
+{
+       EVCardAttribute *attr;
+       const gchar *display_type;
+
+       if (extended)
+               display_type = ews_decode_addressbook_get_display_type_extended (value);
+       else
+               display_type = ews_decode_addressbook_get_display_type (value);
+
+       if (display_type != NULL) {
+               attr = e_vcard_attribute_new (NULL, "X-EWS-KIND");
+               e_vcard_add_attribute_with_value (E_VCARD (*contact), attr, display_type);
+       }
+}
+
 /**
  * ews_decode_addressbook_record 
  * @eod: 
@@ -812,6 +888,12 @@ ews_decode_addressbook_record (EwsOabDecoder *eod,
 
                val = ews_decode_oab_prop (eod, prop_id, cancellable, error);
 
+               if (prop_id == EWS_PT_DISPLAY_TYPE)
+                       ews_decode_addressbook_write_display_type (&contact, GPOINTER_TO_UINT (val), FALSE);
+
+               if (prop_id == EWS_PT_DISPLAY_TYPE_EX)
+                       ews_decode_addressbook_write_display_type (&contact, GPOINTER_TO_UINT (val), TRUE);
+
                /* Check the contact map and store the data in EContact */
                index = g_hash_table_lookup (priv->prop_index_dict, GINT_TO_POINTER (prop_id));
                if (contact && index) {
diff --git a/src/addressbook/ews-oab-props.h b/src/addressbook/ews-oab-props.h
index b204838..e98ff1e 100644
--- a/src/addressbook/ews-oab-props.h
+++ b/src/addressbook/ews-oab-props.h
@@ -41,6 +41,8 @@
 #define        EWS_PT_ROOT_DEPARTMENT          0x8C98001E
 
 /* Ews OAB address-book record property tags that we are or may be interested in */
+#define EWS_PT_DISPLAY_TYPE            0x39000003
+#define EWS_PT_DISPLAY_TYPE_EX         0x39050003
 #define EWS_PT_EMAIL_ADDRESS           0x3003001E
 #define EWS_PT_SMTP_ADDRESS            0x39FE001F
 #define EWS_PT_DISPLAY_NAME            0x3001001F
@@ -75,4 +77,16 @@
 #define EWS_PT_TRUNCATED_PROPS         0x68051003
 #define EWS_PT_THUMBNAIL_PHOTO         0x8C9E0102
 
+/* EWS OAB address-book display types */
+#define EWS_DT_MAILUSER                        0x00000000
+#define EWS_DT_DISTLIST                        0x00000001
+#define EWS_DT_FORUM                   0x00000002
+#define EWS_DT_AGENT                   0x00000003
+#define EWS_DT_ORGANIZATION            0x00000004
+#define EWS_DT_PRIVATE_DISTLIST                0x00000005
+#define EWS_DT_REMOTE_MAILUSER         0x00000006
+#define EWS_DT_ROOM                    0x00000007
+#define EWS_DT_EQUIPMENT               0x00000008
+#define EWS_DT_SEC_DISTLIST            0x00000009
+
 #endif /* _EWS_OAB_PROPS */


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