Added support for GroupWise soap threading.
authorChenthill Palanisamy <pchenthill@novell.com>
Fri, 5 Jun 2009 09:26:13 +0000 (14:56 +0530)
committerChenthill Palanisamy <pchenthill@novell.com>
Fri, 5 Jun 2009 09:26:13 +0000 (14:56 +0530)
camel/providers/groupwise/camel-groupwise-folder.c
camel/providers/groupwise/camel-groupwise-folder.h
camel/providers/groupwise/camel-groupwise-transport.c
servers/groupwise/e-gw-connection.c
servers/groupwise/e-gw-item.c
servers/groupwise/e-gw-item.h

index f19bb00..71fdd09 100644 (file)
@@ -1428,6 +1428,67 @@ end1:
        return;
 }
 
+static guint8*
+get_md5_digest (const guchar *str)
+{
+       guint8 *digest;
+       gsize length;
+       GChecksum *checksum;
+       
+       length = g_checksum_type_get_length (G_CHECKSUM_MD5);
+       digest = g_alloca (length);
+       
+       checksum = g_checksum_new (G_CHECKSUM_MD5);
+       g_checksum_update (checksum, str, -1);
+       g_checksum_get_digest (checksum, digest, &length);
+       g_checksum_free (checksum);
+
+       return digest;
+}
+
+static void
+groupwise_folder_set_threading_data (CamelGroupwiseMessageInfo *mi, EGwItem *item)
+{
+       const gchar *parent_threads;
+       gint count = 0;
+       const gchar *message_id = e_gw_item_get_message_id (item);
+       struct _camel_header_references *refs, *scan;
+       guint8 *digest;
+       gchar *msgid;
+       
+
+       if (!message_id)
+               return;
+
+       /* set message id */
+       msgid = camel_header_msgid_decode(message_id);
+       digest = get_md5_digest (msgid);
+       memcpy(mi->info.message_id.id.hash, digest, sizeof(mi->info.message_id.id.hash));
+       g_free (msgid);
+
+       parent_threads = e_gw_item_get_parent_thread_ids (item);
+
+       if (!parent_threads)
+               return;
+
+       refs = camel_header_references_decode (parent_threads);
+       count = camel_header_references_list_size(&refs);
+       mi->info.references = g_malloc(sizeof(*mi->info.references) + ((count-1) * sizeof(mi->info.references->references[0])));
+       scan = refs;
+       count = 0;
+
+       while (scan) {
+               digest = get_md5_digest ((const guchar *) scan->id);
+               memcpy(mi->info.references->references [count].id.hash, digest, sizeof(mi->info.message_id.id.hash));
+               
+               count++;
+               scan = scan->next;
+       }
+
+       mi->info.references->size = count;
+       camel_header_references_list_clear(&refs);
+}
+
 /* Update the GroupWise cache with the list of items passed. should happen in thread. */
 static void
 gw_update_cache (CamelFolder *folder, GList *list, CamelException *ex, gboolean uid_flag)
@@ -1620,7 +1681,8 @@ gw_update_cache (CamelFolder *folder, GList *list, CamelException *ex, gboolean
                        mi->info.uid = camel_pstring_strdup (e_gw_item_get_id(item));
                        mi->info.size = e_gw_item_get_mail_size (item);
                        mi->info.subject = camel_pstring_strdup(e_gw_item_get_subject(item));
-
+                       groupwise_folder_set_threading_data (mi, item);
+                       
                        camel_folder_summary_add (folder->summary,(CamelMessageInfo *)mi);
                        camel_folder_change_info_add_uid (changes, mi->info.uid);
                        camel_folder_change_info_recent_uid (changes, mi->info.uid);
@@ -1844,6 +1906,7 @@ gw_update_summary ( CamelFolder *folder, GList *list,CamelException *ex)
                if (!exists)
                        mi->info.size = e_gw_item_get_mail_size (item);
                mi->info.subject = camel_pstring_strdup(e_gw_item_get_subject(item));
+               groupwise_folder_set_threading_data (mi, item);
 
                if (exists) {
                        camel_folder_change_info_change_uid (changes, e_gw_item_get_id (item));
@@ -1879,7 +1942,7 @@ groupwise_folder_item_to_msg( CamelFolder *folder,
        CamelMultipart *multipart = NULL;
        gchar *body = NULL;
        gint body_len = 0;
-       const gchar *uid = NULL;
+       const gchar *uid = NULL, *message_id, *parent_threads;
        gboolean is_text_html = FALSE;
        gboolean has_mime_822 = FALSE, ignore_mime_822 = FALSE;
        gboolean is_text_html_embed = FALSE;
@@ -1990,7 +2053,20 @@ groupwise_folder_item_to_msg( CamelFolder *folder,
                multipart = camel_multipart_new ();
        }
 
-       camel_mime_message_set_message_id (msg, uid);
+       if (!has_mime_822 ) {
+               /* Set Message Id */
+               message_id = e_gw_item_get_message_id (item);
+               camel_medium_add_header (CAMEL_MEDIUM (msg), "Message-Id", message_id);
+
+               /* Set parent threads */
+               parent_threads = e_gw_item_get_parent_thread_ids (item);
+               if (parent_threads)
+                       camel_medium_add_header (CAMEL_MEDIUM (msg), "References", parent_threads);
+       }
+       
+       /* set item id */
+       camel_medium_add_header (CAMEL_MEDIUM (msg), "X-GW-ITEM-ID", uid);
+
        type = e_gw_item_get_item_type (item);
        if (type == E_GW_ITEM_TYPE_NOTIFICATION)
                camel_medium_add_header ( CAMEL_MEDIUM (msg), "X-Notification", "shared-folder");
index e1a5544..a79fda1 100644 (file)
@@ -80,7 +80,6 @@ CamelType camel_groupwise_folder_get_type (void);
 /* implemented */
 CamelFolder * camel_gw_folder_new(CamelStore *store, const gchar *folder_dir, const gchar *folder_name, CamelException *ex);
 void gw_update_summary ( CamelFolder *folder, GList *item_list,CamelException *ex);
-void groupwise_refresh_folder(CamelFolder *folder, CamelException *ex);
 
 G_END_DECLS
 
index 75a386e..3aa65af 100644 (file)
@@ -44,6 +44,8 @@
 #include "camel-groupwise-transport.h"
 #include "camel-groupwise-utils.h"
 
+#define REPLY_VIEW "default message attachments threading"
+
 static gboolean groupwise_send_to (CamelTransport *transport,
                                  CamelMimeMessage *message,
                                  CamelAddress *from,
@@ -186,16 +188,16 @@ groupwise_send_to (CamelTransport *transport,
        }
 
        item = camel_groupwise_util_item_from_message (cnc, message, from);
-
-       reply_request = (gchar *)camel_medium_get_header (CAMEL_MEDIUM (message), "In-Reply-To");
+       
+       reply_request = (gchar *)camel_medium_get_header (CAMEL_MEDIUM (message), "X-GW-ORIG-ITEM-ID");
        if (reply_request) {
                gchar *id;
                gint len = strlen (reply_request);
 
                id = (gchar *)g_malloc0 (len-1);
                id = memcpy(id, reply_request+2, len-3);
-               status = e_gw_connection_reply_item (cnc, id, NULL, &temp_item);
-               if (status != E_GW_CONNECTION_STATUS_OK)
+               status = e_gw_connection_reply_item (cnc, id, REPLY_VIEW, &temp_item);
+               if (status != E_GW_CONNECTION_STATUS_OK) 
                        g_warning ("Could not send a replyRequest...continuing without!!\n");
                else {
                        info = e_gw_item_get_link_info (temp_item);
index ae41722..bb08519 100644 (file)
@@ -494,6 +494,7 @@ form_login_request (const gchar *uri, const gchar * username, const gchar * pass
        /* build the SOAP message */
        msg = e_gw_message_new_with_header (uri, NULL, "loginRequest");
        e_gw_message_write_string_parameter (msg, "application", "types", build_timestamp);
+       e_gw_message_write_string_parameter (msg, "version", NULL, "1.02");
        soup_soap_message_start_element (msg, "auth", "types", NULL);
        soup_soap_message_add_attribute (msg, "type", "types:PlainText", "xsi",
                                         "http://www.w3.org/2001/XMLSchema-instance");
index 5ffc568..7be1d15 100644 (file)
@@ -128,6 +128,10 @@ struct _EGwItemPrivate {
 
        gboolean internet;
 
+       /* Message Threading */
+       gchar *message_id;
+       gchar *parent_threads;
+
        /*padding*/
        guint padding[10];
 };
@@ -482,6 +486,16 @@ e_gw_item_dispose (GObject *object)
                        g_free (priv->creation_date);
                        priv->creation_date = NULL;
                 }
+               
+               if (priv->message_id) {
+                       g_free (priv->message_id);
+                       priv->message_id = NULL;
+               }
+
+               if (priv->parent_threads) {
+                       g_free (priv->parent_threads);
+                       priv->parent_threads = NULL;
+               }
 
                free_changes (priv->additions);
                free_changes (priv->deletions);
@@ -565,6 +579,8 @@ e_gw_item_init (EGwItem *item, EGwItemClass *klass)
        priv->msg_body_id = NULL;
        priv->has_attachment = FALSE;
        priv->internet = FALSE;
+       priv->message_id = NULL;
+       priv->parent_threads = NULL;
        item->priv = priv;
 
 
@@ -949,6 +965,18 @@ e_gw_item_get_category_name (EGwItem *item)
        return item->priv->category_name;
 }
 
+const gchar*
+e_gw_item_get_parent_thread_ids (EGwItem *item)
+{
+       return item->priv->parent_threads;
+}
+
+const gchar*
+e_gw_item_get_message_id (EGwItem *item)
+{
+       return item->priv->message_id;
+}
+
 void e_gw_item_set_change (EGwItem *item, EGwItemChangeType change_type, const gchar *field_name, gpointer field_value)
 {
        GHashTable *hash_table;
@@ -2084,6 +2112,15 @@ e_gw_item_new_from_soap_parameter (const gchar *email, const gchar *container, S
                                g_free (value);
                        }
                        g_free (enabled);
+               } else if (!g_ascii_strcasecmp (name, "threading")) {
+                       SoupSoapParameter *subparam;
+                       
+                       subparam = soup_soap_parameter_get_first_child_by_name (child, "parent") ;
+                       if (subparam) 
+                               item->priv->parent_threads = soup_soap_parameter_get_string_value (subparam);
+                       
+               } else if (!g_ascii_strcasecmp (name, "messageId")) {
+                       item->priv->message_id = soup_soap_parameter_get_string_value (child);
                }
 
        }
index 016af61..8293c0c 100644 (file)
@@ -304,6 +304,10 @@ gboolean e_gw_item_has_attachment (EGwItem *item);
 
 gboolean e_gw_item_is_from_internet (EGwItem *item);
 
+const gchar *e_gw_item_get_parent_thread_ids (EGwItem *item);
+const gchar* e_gw_item_get_message_id (EGwItem *item);
+
+
 typedef struct {
        gchar *email;
        gchar *display_name;