[evolution-ews] Bug #654953 - Fetch Notes in contact



commit e8521d9e84372b31c612ec49897487ebdf014955
Author: Fabiano Fidêncio <fidencio redhat com>
Date:   Thu Mar 14 13:15:42 2013 +0100

    Bug #654953 - Fetch Notes in contact

 src/addressbook/e-book-backend-ews.c |   48 +++++++++++++++++++++++++++++++++-
 src/server/e-ews-item.c              |   18 ++++++++++++
 src/server/e-ews-item.h              |    1 +
 3 files changed, 66 insertions(+), 1 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-ews.c b/src/addressbook/e-book-backend-ews.c
index fce0352..2731973 100644
--- a/src/addressbook/e-book-backend-ews.c
+++ b/src/addressbook/e-book-backend-ews.c
@@ -107,7 +107,7 @@ enum {
 
 /* passing field uris for PhysicalAddress, PhoneNumbers causes error, so we use Default view to fetch them. 
Thus the summary props just have attachments  and 
  * some additional properties that are not return with Default view */
-#define CONTACT_ITEM_PROPS "item:Attachments item:HasAttachments contacts:Manager contacts:Department 
contacts:SpouseName contacts:AssistantName contacts:BusinessHomePage contacts:Birthday"
+#define CONTACT_ITEM_PROPS "item:Attachments item:HasAttachments item:Body contacts:Manager 
contacts:Department contacts:SpouseName contacts:AssistantName contacts:BusinessHomePage contacts:Birthday"
 
 #define PRIV_LOCK(p)   (g_rec_mutex_lock (&(p)->rec_mutex))
 #define PRIV_UNLOCK(p) (g_rec_mutex_unlock (&(p)->rec_mutex))
@@ -428,6 +428,17 @@ ebews_populate_ims (EContact *contact,
 }
 
 static void
+ebews_populate_notes (EContact *contact,
+                      EEwsItem *item)
+{
+       const gchar *notes = e_ews_item_get_notes (item);
+       if (!notes)
+               return;
+
+       e_contact_set (contact, E_CONTACT_NOTE, notes);
+}
+
+static void
 set_email_address (EContact *contact,
                    EContactField field,
                    EEwsItem *item,
@@ -601,6 +612,19 @@ ebews_set_ims (ESoapMessage *message,
 }
 
 static void
+ebews_set_notes (ESoapMessage *msg,
+                 EContact *contact)
+{
+       gchar *notes = e_contact_get (contact, E_CONTACT_NOTE);
+       if (!notes)
+               return;
+
+       e_ews_message_write_string_parameter_with_attribute (msg, "Body", NULL, notes, "BodyType", "Text");
+
+       g_free (notes);
+}
+
+static void
 ebews_set_emails (ESoapMessage *msg,
                   EContact *contact)
 {
@@ -817,6 +841,25 @@ ebews_set_im_changes (ESoapMessage *message,
 }
 
 static void
+ebews_set_notes_changes (ESoapMessage *message,
+                         EContact *new,
+                         EContact *old)
+{
+       gchar *old_notes, *new_notes;
+
+       old_notes = e_contact_get (old, E_CONTACT_NOTE);
+       new_notes = e_contact_get (new, E_CONTACT_NOTE);
+
+       if (g_strcmp0 (old_notes, new_notes)) {
+               convert_contact_property_to_updatexml (
+                               message, "Body", new_notes ?: "", "item", "BodyType", "Text");
+       }
+
+       g_free (old_notes);
+       g_free (new_notes);
+}
+
+static void
 ebews_set_email_changes (ESoapMessage *message,
                          EContact *new,
                          EContact *old)
@@ -863,6 +906,7 @@ static const struct field_element_mapping {
 
 } mappings[] = {
        /* The order should be maintained for create contacts to work */
+       { E_CONTACT_NOTE, ELEMENT_TYPE_COMPLEX, "Notes", NULL, ebews_populate_notes, ebews_set_notes, 
ebews_set_notes_changes },
        { E_CONTACT_FILE_AS, ELEMENT_TYPE_SIMPLE, "FileAs", e_ews_item_get_fileas},
        { E_CONTACT_FULL_NAME, ELEMENT_TYPE_COMPLEX, "CompleteName", NULL, ebews_populate_full_name, 
ebews_set_full_name, ebews_set_full_name_changes},
        { E_CONTACT_NICKNAME, ELEMENT_TYPE_SIMPLE, "Nickname", NULL, ebews_populate_nick_name},
@@ -2877,6 +2921,8 @@ e_book_backend_ews_get_backend_property (EBookBackend *backend,
                fields = g_slist_append (fields, g_strdup (e_contact_field_name (E_CONTACT_ADDRESS_OTHER)));
                fields = g_slist_append (fields, g_strdup (e_contact_field_name (E_CONTACT_BIRTH_DATE)));
 
+               fields = g_slist_append (fields, g_strdup (e_contact_field_name (E_CONTACT_NOTE)));
+
                fields_str = e_data_book_string_slist_to_comma_string (fields);
 
                e_data_book_respond_get_backend_property (book, opid, NULL, fields_str);
diff --git a/src/server/e-ews-item.c b/src/server/e-ews-item.c
index 4fa04a3..3e2abdd 100644
--- a/src/server/e-ews-item.c
+++ b/src/server/e-ews-item.c
@@ -124,6 +124,7 @@ struct _EEwsContactFields {
        gchar *spouse_name;
        gchar *culture;
        gchar *surname;
+       gchar *notes;
 };
 
 struct _EEwsTaskFields {
@@ -406,6 +407,7 @@ ews_free_contact_fields (struct _EEwsContactFields *con_fields)
                g_free (con_fields->spouse_name);
                g_free (con_fields->culture);
                g_free (con_fields->surname);
+               g_free (con_fields->notes);
                g_free (con_fields);
        }
 }
@@ -1027,6 +1029,13 @@ e_ews_item_set_from_soap_parameter (EEwsItem *item,
                        priv->item_id = g_new0 (EwsId, 1);
                        priv->item_id->id = e_soap_parameter_get_property (subparam, "Id");
                        priv->item_id->change_key = e_soap_parameter_get_property (subparam, "ChangeKey");
+               } else if (!g_ascii_strcasecmp (name, "Body")) {
+                       /*
+                        * For Exchange versions >= 2010_SP2 Notes property can be get
+                        * directly from contacts:Notes. But for backward compatibility
+                        * with old servers (< 2010_SP2) we prefer use item:Body.
+                        */
+                       priv->contact_fields->notes = e_soap_parameter_get_string_value (subparam);
                } else if (!g_ascii_strcasecmp (name, "Subject")) {
                        priv->subject = e_soap_parameter_get_string_value (subparam);
                } else if (!g_ascii_strcasecmp (name, "DateTimeReceived")) {
@@ -1821,6 +1830,15 @@ e_ews_item_get_surname (EEwsItem *item)
        return (const gchar *) item->priv->contact_fields->surname;
 }
 
+const gchar *
+e_ews_item_get_notes (EEwsItem *item)
+{
+       g_return_val_if_fail (E_IS_EWS_ITEM (item), NULL);
+       g_return_val_if_fail (item->priv->contact_fields != NULL, NULL);
+
+       return item->priv->contact_fields->notes;
+}
+
 time_t
 e_ews_item_get_birthday (EEwsItem *item)
 {
diff --git a/src/server/e-ews-item.h b/src/server/e-ews-item.h
index b91bcb2..f87429e 100644
--- a/src/server/e-ews-item.h
+++ b/src/server/e-ews-item.h
@@ -242,6 +242,7 @@ const gchar *       e_ews_item_get_profession       (EEwsItem *item);
 const gchar *  e_ews_item_get_spouse_name      (EEwsItem *item);
 const gchar *  e_ews_item_get_culture          (EEwsItem *item);
 const gchar *  e_ews_item_get_surname          (EEwsItem *item);
+const gchar *  e_ews_item_get_notes            (EEwsItem *item);
 
 /*Task fields*/
 const gchar *  e_ews_item_get_status           (EEwsItem *item);


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