[evolution-activesync/wip/camel-more-gobject] Use GObject-based CamelMessageInfo



commit 9adb733e426582ada06e54c5fd5aa104405e839f
Author: Milan Crha <mcrha redhat com>
Date:   Wed Sep 14 22:07:14 2016 +0200

    Use GObject-based CamelMessageInfo
    
    Fixes also a build break due to missing link library.

 camel/Makefile.am              |    2 +
 camel/camel-eas-folder.c       |   24 +--
 camel/camel-eas-message-info.c |  431 ++++++++++++++++++++++++++++++++++++++++
 camel/camel-eas-message-info.h |   81 ++++++++
 camel/camel-eas-summary.c      |  185 +++--------------
 camel/camel-eas-summary.h      |   24 +--
 camel/camel-eas-utils.c        |   41 ++--
 configuration/Makefile.am      |    1 +
 8 files changed, 578 insertions(+), 211 deletions(-)
---
diff --git a/camel/Makefile.am b/camel/Makefile.am
index c6c60e3..b65463b 100644
--- a/camel/Makefile.am
+++ b/camel/Makefile.am
@@ -22,6 +22,7 @@ libcameleas_la_CPPFLAGS = \
 
 libcameleas_la_SOURCES =                       \
        camel-eas-folder.c                      \
+       camel-eas-message-info.c                \
        camel-eas-store-summary.c               \
        camel-eas-store.c                       \
        camel-eas-summary.c                     \
@@ -32,6 +33,7 @@ libcameleas_la_SOURCES =                      \
 
 noinst_HEADERS =                               \
        camel-eas-folder.h                      \
+       camel-eas-message-info.h                \
        camel-eas-private.h                     \
        camel-eas-store-summary.h               \
        camel-eas-store.h                       \
diff --git a/camel/camel-eas-folder.c b/camel/camel-eas-folder.c
index e068f20..6804a0e 100644
--- a/camel/camel-eas-folder.c
+++ b/camel/camel-eas-folder.c
@@ -410,11 +410,11 @@ eas_synchronize_sync (CamelFolder *folder, gboolean expunge, GCancellable *cance
  more:
        for ( ; success && i < uids->len && item_list_len < 25; i++) {
                guint32 flags_changed;
-               CamelEasMessageInfo *mi = (void *)camel_folder_summary_get (folder->summary, uids->pdata[i]);
+               CamelMessageInfo *mi = camel_folder_summary_get (folder->summary, uids->pdata[i]);
                if (!mi)
                        continue;
 
-               flags_changed = mi->server_flags ^ mi->info.flags;
+               flags_changed = camel_eas_message_info_get_server_flags (CAMEL_EAS_MESSAGE_INFO (mi)) ^ 
camel_message_info_get_flags (mi);
 
                /* Exchange doesn't seem to have a sane representation
                   for most flags — not even replied/forwarded. */
@@ -423,13 +423,13 @@ eas_synchronize_sync (CamelFolder *folder, gboolean expunge, GCancellable *cance
                        item->server_id = g_strdup (uids->pdata[i]);
                        if (flags_changed & CAMEL_MESSAGE_SEEN) {
                                item->flags |= EAS_VALID_READ;
-                               if (mi->info.flags & CAMEL_MESSAGE_SEEN)
+                               if (camel_message_info_get_flags (mi) & CAMEL_MESSAGE_SEEN)
                                        item->flags |= EAS_EMAIL_READ;
                        }
 #if 0 /* ActiveSync doesn't let you update this */
                        if (flags_changed & CAMEL_MESSAGE_FLAGGED) {
                                item->flags |= EAS_VALID_IMPORTANCE;
-                               if (mi->info.flags & CAMEL_MESSAGE_FLAGGED)
+                               if (camel_message_info_get_flags (mi) & CAMEL_MESSAGE_FLAGGED)
                                        item->importance = EAS_IMPORTANCE_HIGH;
                                else
                                        item->importance = EAS_IMPORTANCE_LOW;
@@ -440,7 +440,7 @@ eas_synchronize_sync (CamelFolder *folder, gboolean expunge, GCancellable *cance
                        item_list_len++;
                } else if (flags_changed & CAMEL_MESSAGE_DELETED) {
                        deleted_uids = g_slist_prepend (deleted_uids, (gpointer) camel_pstring_strdup 
(uids->pdata [i]));
-                       camel_message_info_unref (mi);
+                       g_clear_object (&mi);
                }
        }
 
@@ -451,12 +451,12 @@ eas_synchronize_sync (CamelFolder *folder, gboolean expunge, GCancellable *cance
                                                         ((CamelEasSummary *) folder->summary)->sync_state,
                                                         priv->server_id, item_list, NULL, error);
                for (l = changing_mis; l; l = l->next) {
-                       CamelEasMessageInfo *mi = l->data;
+                       CamelMessageInfo *mi = l->data;
                        if (success) {
-                               mi->server_flags = mi->info.flags;
-                               mi->info.dirty = TRUE;
+                               camel_eas_message_info_set_server_flags (CAMEL_EAS_MESSAGE_INFO (mi), 
camel_message_info_get_flags (mi));
+
                        }
-                       camel_message_info_unref (mi);
+                       g_clear_object (&mi);
                }
                g_slist_free (changing_mis);
                changing_mis = NULL;
@@ -753,7 +753,6 @@ static gboolean
 eas_expunge_sync (CamelFolder *folder, GCancellable *cancellable, GError **error)
 {
        CamelEasStore *eas_store;
-       CamelEasMessageInfo *eas_info;
        CamelMessageInfo *info;
        CamelStore *parent_store;
        GSList *deleted_items = NULL;
@@ -783,11 +782,10 @@ eas_expunge_sync (CamelFolder *folder, GCancellable *cancellable, GError **error
 
                info = camel_folder_summary_get (folder->summary, uid);
 
-               eas_info = (CamelEasMessageInfo *) info;
-               if (eas_info && (eas_info->info.flags & CAMEL_MESSAGE_DELETED))
+               if (info && (camel_message_info_get_flags (info) & CAMEL_MESSAGE_DELETED))
                        deleted_items = g_slist_prepend (deleted_items, (gpointer) camel_pstring_strdup 
(uid));
 
-               camel_message_info_unref (info);
+               g_clear_object (&info);
        }
        camel_folder_summary_free_array (known_uids);
 
diff --git a/camel/camel-eas-message-info.c b/camel/camel-eas-message-info.c
new file mode 100644
index 0000000..3d6c59e
--- /dev/null
+++ b/camel/camel-eas-message-info.c
@@ -0,0 +1,431 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2016 Red Hat, Inc. (www.redhat.com)
+ *
+ * This library is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+
+#include "camel/camel.h"
+#include "camel-eas-summary.h"
+
+#include "camel-eas-message-info.h"
+
+struct _CamelEasMessageInfoPrivate {
+       guint32 server_flags;
+       gint32 item_type;
+       gchar *change_key;
+};
+
+enum {
+       PROP_0,
+       PROP_SERVER_FLAGS,
+       PROP_ITEM_TYPE,
+       PROP_CHANGE_KEY,
+};
+
+G_DEFINE_TYPE (CamelEasMessageInfo, camel_eas_message_info, CAMEL_TYPE_MESSAGE_INFO_BASE)
+
+static CamelMessageInfo *
+eas_message_info_clone (const CamelMessageInfo *mi,
+                       CamelFolderSummary *assign_summary)
+{
+       CamelMessageInfo *result;
+
+       g_return_val_if_fail (CAMEL_IS_EAS_MESSAGE_INFO (mi), NULL);
+
+       result = CAMEL_MESSAGE_INFO_CLASS (camel_eas_message_info_parent_class)->clone (mi, assign_summary);
+       if (!result)
+               return NULL;
+
+       if (CAMEL_IS_EAS_MESSAGE_INFO (result)) {
+               CamelEasMessageInfo *emi, *emi_result;
+
+               emi = CAMEL_EAS_MESSAGE_INFO (mi);
+               emi_result = CAMEL_EAS_MESSAGE_INFO (result);
+
+               camel_eas_message_info_set_server_flags (emi_result, camel_eas_message_info_get_server_flags 
(emi));
+               camel_eas_message_info_set_item_type (emi_result, camel_eas_message_info_get_item_type (emi));
+               camel_eas_message_info_take_change_key (emi_result, camel_eas_message_info_dup_change_key 
(emi));
+       }
+
+       return result;
+}
+
+static gboolean
+eas_message_info_load (CamelMessageInfo *mi,
+                      const CamelMIRecord *record,
+                      /* const */ gchar **bdata_ptr)
+{
+       CamelEasMessageInfo *emi;
+
+       g_return_val_if_fail (CAMEL_IS_EAS_MESSAGE_INFO (mi), FALSE);
+       g_return_val_if_fail (record != NULL, FALSE);
+       g_return_val_if_fail (bdata_ptr != NULL, FALSE);
+
+       if (!CAMEL_MESSAGE_INFO_CLASS (camel_eas_message_info_parent_class)->load ||
+           !CAMEL_MESSAGE_INFO_CLASS (camel_eas_message_info_parent_class)->load (mi, record, bdata_ptr))
+               return FALSE;
+
+       emi = CAMEL_EAS_MESSAGE_INFO (mi);
+
+       if (*bdata_ptr) {
+               gchar **values;
+
+               values = g_strsplit (*bdata_ptr, " ", -1);
+
+               if (values && values[0] && values[1] && values[2]) {
+                       camel_eas_message_info_set_server_flags (emi, g_ascii_strtoll (values[0], NULL, 10));
+                       camel_eas_message_info_set_item_type (emi, g_ascii_strtoll (values[1], NULL, 10));
+                       camel_eas_message_info_set_change_key (emi, values[2]);
+               }
+
+               g_strfreev (values);
+       }
+
+       return TRUE;
+}
+
+static gboolean
+eas_message_info_save (const CamelMessageInfo *mi,
+                      CamelMIRecord *record,
+                      GString *bdata_str)
+{
+       CamelEasMessageInfo *emi;
+
+       g_return_val_if_fail (CAMEL_IS_EAS_MESSAGE_INFO (mi), FALSE);
+       g_return_val_if_fail (record != NULL, FALSE);
+       g_return_val_if_fail (bdata_str != NULL, FALSE);
+
+       if (!CAMEL_MESSAGE_INFO_CLASS (camel_eas_message_info_parent_class)->save ||
+           !CAMEL_MESSAGE_INFO_CLASS (camel_eas_message_info_parent_class)->save (mi, record, bdata_str))
+               return FALSE;
+
+       emi = CAMEL_EAS_MESSAGE_INFO (mi);
+
+       g_string_append_printf (bdata_str, "%u %d %s",
+               camel_eas_message_info_get_server_flags (emi),
+               camel_eas_message_info_get_item_type (emi),
+               camel_eas_message_info_get_change_key (emi));
+
+       return TRUE;
+}
+
+static void
+eas_message_info_set_property (GObject *object,
+                              guint property_id,
+                              const GValue *value,
+                              GParamSpec *pspec)
+{
+       CamelEasMessageInfo *emi = CAMEL_EAS_MESSAGE_INFO (object);
+
+       switch (property_id) {
+       case PROP_SERVER_FLAGS:
+               camel_eas_message_info_set_server_flags (emi, g_value_get_uint (value));
+               return;
+
+       case PROP_ITEM_TYPE:
+               camel_eas_message_info_set_item_type (emi, g_value_get_int (value));
+               return;
+
+       case PROP_CHANGE_KEY:
+               camel_eas_message_info_set_change_key (emi, g_value_get_string (value));
+               return;
+       }
+
+       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+eas_message_info_get_property (GObject *object,
+                              guint property_id,
+                              GValue *value,
+                              GParamSpec *pspec)
+{
+       CamelEasMessageInfo *emi = CAMEL_EAS_MESSAGE_INFO (object);
+
+       switch (property_id) {
+
+       case PROP_SERVER_FLAGS:
+               g_value_set_uint (value, camel_eas_message_info_get_server_flags (emi));
+               return;
+
+       case PROP_ITEM_TYPE:
+               g_value_set_int (value, camel_eas_message_info_get_item_type (emi));
+               return;
+
+       case PROP_CHANGE_KEY:
+               g_value_take_string (value, camel_eas_message_info_dup_change_key (emi));
+               return;
+       }
+
+       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+eas_message_info_dispose (GObject *object)
+{
+       CamelEasMessageInfo *emi = CAMEL_EAS_MESSAGE_INFO (object);
+
+       g_free (emi->priv->change_key);
+       emi->priv->change_key = NULL;
+
+       /* Chain up to parent's method. */
+       G_OBJECT_CLASS (camel_eas_message_info_parent_class)->dispose (object);
+}
+
+static void
+camel_eas_message_info_class_init (CamelEasMessageInfoClass *class)
+{
+       CamelMessageInfoClass *mi_class;
+       GObjectClass *object_class;
+
+       g_type_class_add_private (class, sizeof (CamelEasMessageInfoPrivate));
+
+       mi_class = CAMEL_MESSAGE_INFO_CLASS (class);
+       mi_class->clone = eas_message_info_clone;
+       mi_class->load = eas_message_info_load;
+       mi_class->save = eas_message_info_save;
+
+       object_class = G_OBJECT_CLASS (class);
+       object_class->set_property = eas_message_info_set_property;
+       object_class->get_property = eas_message_info_get_property;
+       object_class->dispose = eas_message_info_dispose;
+
+       /**
+        * CamelEasMessageInfo:server-flags
+        *
+        * Last known server flags of the message.
+        *
+        * Since: 3.24
+        **/
+       g_object_class_install_property (
+               object_class,
+               PROP_SERVER_FLAGS,
+               g_param_spec_uint (
+                       "server-flags",
+                       "Server Flags",
+                       NULL,
+                       0, G_MAXUINT32, 0,
+                       G_PARAM_READWRITE));
+
+       /**
+        * CamelEasMessageInfo:item-type
+        *
+        * Item type of the message.
+        *
+        * Since: 3.24
+        **/
+       g_object_class_install_property (
+               object_class,
+               PROP_ITEM_TYPE,
+               g_param_spec_int (
+                       "item-type",
+                       "Item Type",
+                       NULL,
+                       0, G_MAXINT32, 0,
+                       G_PARAM_READWRITE));
+
+       /**
+        * CamelEasMessageInfo:change-key
+        *
+        * Change key of the message on the server.
+        *
+        * Since: 3.24
+        **/
+       g_object_class_install_property (
+               object_class,
+               PROP_CHANGE_KEY,
+               g_param_spec_string (
+                       "change-key",
+                       "Change Key",
+                       NULL,
+                       NULL,
+                       G_PARAM_READWRITE));
+}
+
+static void
+camel_eas_message_info_init (CamelEasMessageInfo *emi)
+{
+       emi->priv = G_TYPE_INSTANCE_GET_PRIVATE (emi, CAMEL_TYPE_EAS_MESSAGE_INFO, 
CamelEasMessageInfoPrivate);
+}
+
+guint32
+camel_eas_message_info_get_server_flags (const CamelEasMessageInfo *emi)
+{
+       CamelMessageInfo *mi;
+       guint32 result;
+
+       g_return_val_if_fail (CAMEL_IS_EAS_MESSAGE_INFO (emi), 0);
+
+       mi = CAMEL_MESSAGE_INFO (emi);
+
+       camel_message_info_property_lock (mi);
+       result = emi->priv->server_flags;
+       camel_message_info_property_unlock (mi);
+
+       return result;
+}
+
+gboolean
+camel_eas_message_info_set_server_flags (CamelEasMessageInfo *emi,
+                                        guint32 server_flags)
+{
+       CamelMessageInfo *mi;
+       gboolean changed;
+
+       g_return_val_if_fail (CAMEL_IS_EAS_MESSAGE_INFO (emi), FALSE);
+
+       mi = CAMEL_MESSAGE_INFO (emi);
+
+       camel_message_info_property_lock (mi);
+
+       changed = emi->priv->server_flags != server_flags;
+
+       if (changed)
+               emi->priv->server_flags = server_flags;
+
+       camel_message_info_property_unlock (mi);
+
+       if (changed && !camel_message_info_get_abort_notifications (mi)) {
+               g_object_notify (G_OBJECT (emi), "server-flags");
+               camel_message_info_set_dirty (mi, TRUE);
+       }
+
+       return changed;
+}
+
+gint32
+camel_eas_message_info_get_item_type (const CamelEasMessageInfo *emi)
+{
+       CamelMessageInfo *mi;
+       gint32 result;
+
+       g_return_val_if_fail (CAMEL_IS_EAS_MESSAGE_INFO (emi), 0);
+
+       mi = CAMEL_MESSAGE_INFO (emi);
+
+       camel_message_info_property_lock (mi);
+       result = emi->priv->item_type;
+       camel_message_info_property_unlock (mi);
+
+       return result;
+}
+
+gboolean
+camel_eas_message_info_set_item_type (CamelEasMessageInfo *emi,
+                                     gint32 item_type)
+{
+       CamelMessageInfo *mi;
+       gboolean changed;
+
+       g_return_val_if_fail (CAMEL_IS_EAS_MESSAGE_INFO (emi), FALSE);
+
+       mi = CAMEL_MESSAGE_INFO (emi);
+
+       camel_message_info_property_lock (mi);
+
+       changed = emi->priv->item_type != item_type;
+
+       if (changed)
+               emi->priv->item_type = item_type;
+
+       camel_message_info_property_unlock (mi);
+
+       if (changed && !camel_message_info_get_abort_notifications (mi)) {
+               g_object_notify (G_OBJECT (emi), "item-type");
+               camel_message_info_set_dirty (mi, TRUE);
+       }
+
+       return changed;
+}
+
+const gchar *
+camel_eas_message_info_get_change_key (const CamelEasMessageInfo *emi)
+{
+       CamelMessageInfo *mi;
+       const gchar *result;
+
+       g_return_val_if_fail (CAMEL_IS_EAS_MESSAGE_INFO (emi), NULL);
+
+       mi = CAMEL_MESSAGE_INFO (emi);
+
+       camel_message_info_property_lock (mi);
+       result = emi->priv->change_key;
+       camel_message_info_property_unlock (mi);
+
+       return result;
+}
+
+gchar *
+camel_eas_message_info_dup_change_key (const CamelEasMessageInfo *emi)
+{
+       CamelMessageInfo *mi;
+       gchar *result;
+
+       g_return_val_if_fail (CAMEL_IS_EAS_MESSAGE_INFO (emi), NULL);
+
+       mi = CAMEL_MESSAGE_INFO (emi);
+
+       camel_message_info_property_lock (mi);
+       result = g_strdup (emi->priv->change_key);
+       camel_message_info_property_unlock (mi);
+
+       return result;
+}
+
+gboolean
+camel_eas_message_info_set_change_key (CamelEasMessageInfo *emi,
+                                      const gchar *change_key)
+{
+       g_return_val_if_fail (CAMEL_IS_EAS_MESSAGE_INFO (emi), FALSE);
+
+       return camel_eas_message_info_take_change_key (emi, g_strdup (change_key));
+}
+
+gboolean
+camel_eas_message_info_take_change_key (CamelEasMessageInfo *emi,
+                                       gchar *change_key)
+{
+       CamelMessageInfo *mi;
+       gboolean changed;
+
+       g_return_val_if_fail (CAMEL_IS_EAS_MESSAGE_INFO (emi), FALSE);
+
+       mi = CAMEL_MESSAGE_INFO (emi);
+
+       camel_message_info_property_lock (mi);
+
+       changed = g_strcmp0 (emi->priv->change_key, change_key) != 0;
+
+       if (changed) {
+               g_free (emi->priv->change_key);
+               emi->priv->change_key = change_key;
+       } else if (change_key != emi->priv->change_key) {
+               g_free (change_key);
+       }
+
+       camel_message_info_property_unlock (mi);
+
+       if (changed && !camel_message_info_get_abort_notifications (mi)) {
+               g_object_notify (G_OBJECT (emi), "change-key");
+               camel_message_info_set_dirty (mi, TRUE);
+       }
+
+       return changed;
+}
diff --git a/camel/camel-eas-message-info.h b/camel/camel-eas-message-info.h
new file mode 100644
index 0000000..c214455
--- /dev/null
+++ b/camel/camel-eas-message-info.h
@@ -0,0 +1,81 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2016 Red Hat, Inc. (www.redhat.com)
+ *
+ * This library is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef CAMEL_EAS_MESSAGE_INFO_H
+#define CAMEL_EAS_MESSAGE_INFO_H
+
+#include <glib-object.h>
+
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_EAS_MESSAGE_INFO \
+       (camel_eas_message_info_get_type ())
+#define CAMEL_EAS_MESSAGE_INFO(obj) \
+       (G_TYPE_CHECK_INSTANCE_CAST \
+       ((obj), CAMEL_TYPE_EAS_MESSAGE_INFO, CamelEasMessageInfo))
+#define CAMEL_EAS_MESSAGE_INFO_CLASS(cls) \
+       (G_TYPE_CHECK_CLASS_CAST \
+       ((cls), CAMEL_TYPE_EAS_MESSAGE_INFO, CamelEasMessageInfoClass))
+#define CAMEL_IS_EAS_MESSAGE_INFO(obj) \
+       (G_TYPE_CHECK_INSTANCE_TYPE \
+       ((obj), CAMEL_TYPE_EAS_MESSAGE_INFO))
+#define CAMEL_IS_EAS_MESSAGE_INFO_CLASS(cls) \
+       (G_TYPE_CHECK_CLASS_TYPE \
+       ((cls), CAMEL_TYPE_EAS_MESSAGE_INFO))
+#define CAMEL_EAS_MESSAGE_INFO_GET_CLASS(obj) \
+       (G_TYPE_INSTANCE_GET_CLASS \
+       ((obj), CAMEL_TYPE_EAS_MESSAGE_INFO, CamelEasMessageInfoClass))
+
+G_BEGIN_DECLS
+
+/* extra summary flags*/
+enum {
+       CAMEL_EAS_MESSAGE_MSGFLAG_RN_PENDING = CAMEL_MESSAGE_FOLDER_FLAGGED << 1
+};
+
+typedef struct _CamelEasMessageInfo CamelEasMessageInfo;
+typedef struct _CamelEasMessageInfoClass CamelEasMessageInfoClass;
+typedef struct _CamelEasMessageInfoPrivate CamelEasMessageInfoPrivate;
+
+struct _CamelEasMessageInfo {
+       CamelMessageInfoBase parent;
+       CamelEasMessageInfoPrivate *priv;
+};
+
+struct _CamelEasMessageInfoClass {
+       CamelMessageInfoBaseClass parent_class;
+};
+
+GType          camel_eas_message_info_get_type (void);
+
+guint32                camel_eas_message_info_get_server_flags (const CamelEasMessageInfo *emi);
+gboolean       camel_eas_message_info_set_server_flags (CamelEasMessageInfo *emi,
+                                                        guint32 server_flags);
+gint32         camel_eas_message_info_get_item_type    (const CamelEasMessageInfo *emi);
+gboolean       camel_eas_message_info_set_item_type    (CamelEasMessageInfo *emi,
+                                                        gint32 item_type);
+const gchar *  camel_eas_message_info_get_change_key   (const CamelEasMessageInfo *emi);
+gchar *                camel_eas_message_info_dup_change_key   (const CamelEasMessageInfo *emi);
+gboolean       camel_eas_message_info_set_change_key   (CamelEasMessageInfo *emi,
+                                                        const gchar *change_key);
+gboolean       camel_eas_message_info_take_change_key  (CamelEasMessageInfo *emi,
+                                                        gchar *change_key);
+
+G_END_DECLS
+
+#endif /* CAMEL_EAS_MESSAGE_INFO_H */
diff --git a/camel/camel-eas-summary.c b/camel/camel-eas-summary.c
index 0916ed7..e497ff0 100644
--- a/camel/camel-eas-summary.c
+++ b/camel/camel-eas-summary.c
@@ -49,41 +49,11 @@
 #define SUM_DB_RET_ERR FALSE
 static SUM_DB_RETTYPE summary_header_from_db (CamelFolderSummary *s, CamelFIRecord *mir);
 static CamelFIRecord * summary_header_to_db (CamelFolderSummary *s, GError **error);
-static CamelMIRecord * message_info_to_db (CamelFolderSummary *s, CamelMessageInfo *info);
-static CamelMessageInfo * message_info_from_db (CamelFolderSummary *s, CamelMIRecord *mir);
-static SUM_DB_RETTYPE content_info_to_db (CamelFolderSummary *s, CamelMessageContentInfo *info, 
CamelMIRecord *mir);
-static CamelMessageContentInfo * content_info_from_db (CamelFolderSummary *s, CamelMIRecord *mir);
 
 /*End of Prototypes*/
 
 G_DEFINE_TYPE (CamelEasSummary, camel_eas_summary, CAMEL_TYPE_FOLDER_SUMMARY)
 
-static CamelMessageInfo *
-eas_message_info_clone(CamelFolderSummary *s, const CamelMessageInfo *mi)
-{
-       CamelEasMessageInfo *to;
-       const CamelEasMessageInfo *from = (const CamelEasMessageInfo *)mi;
-
-       to = (CamelEasMessageInfo *)CAMEL_FOLDER_SUMMARY_CLASS 
(camel_eas_summary_parent_class)->message_info_clone(s, mi);
-       to->server_flags = from->server_flags;
-       to->item_type = from->item_type;
-       to->change_key = g_strdup (from->change_key);
-
-       /* FIXME: parent clone should do this */
-       to->info.content = camel_folder_summary_content_info_new(s);
-
-       return (CamelMessageInfo *)to;
-}
-
-static void
-eas_message_info_free (CamelFolderSummary *s, CamelMessageInfo *mi)
-{
-       CamelEasMessageInfo *emi = (void *)mi;
-
-       g_free (emi->change_key);
-       CAMEL_FOLDER_SUMMARY_CLASS (camel_eas_summary_parent_class)->message_info_free (s, mi);
-}
-
 static void
 eas_summary_finalize (GObject *object)
 {
@@ -105,16 +75,9 @@ camel_eas_summary_class_init (CamelEasSummaryClass *class)
        object_class->finalize = eas_summary_finalize;
 
        folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (class);
-       folder_summary_class->message_info_size = sizeof (CamelEasMessageInfo);
-       folder_summary_class->content_info_size = sizeof (CamelEasMessageContentInfo);
-       folder_summary_class->message_info_clone = eas_message_info_clone;
-       folder_summary_class->message_info_free = eas_message_info_free;
+       folder_summary_class->message_info_type = CAMEL_TYPE_EAS_MESSAGE_INFO;
        folder_summary_class->summary_header_to_db = summary_header_to_db;
        folder_summary_class->summary_header_from_db = summary_header_from_db;
-       folder_summary_class->message_info_to_db = message_info_to_db;
-       folder_summary_class->message_info_from_db = message_info_from_db;
-       folder_summary_class->content_info_to_db = content_info_to_db;
-       folder_summary_class->content_info_from_db = content_info_from_db;
 }
 
 static void
@@ -138,7 +101,7 @@ camel_eas_summary_new (struct _CamelFolder *folder, const gchar *filename)
 
        summary = g_object_new (CAMEL_TYPE_EAS_SUMMARY,
                                "folder", folder, NULL);
-       camel_folder_summary_set_build_content (summary, TRUE);
+
        camel_folder_summary_load_from_db (summary, NULL);
 
        return summary;
@@ -182,110 +145,31 @@ summary_header_to_db (CamelFolderSummary *s, GError **error)
 
 }
 
-static CamelMessageInfo *
-message_info_from_db (CamelFolderSummary *s, CamelMIRecord *mir)
-{
-       CamelMessageInfo *info;
-       CamelEasMessageInfo *iinfo;
-
-       info = CAMEL_FOLDER_SUMMARY_CLASS (camel_eas_summary_parent_class)->message_info_from_db (s, mir);
-       if (info) {
-               gchar *part = mir->bdata;
-               gchar **values;
-
-               iinfo = (CamelEasMessageInfo *)info;
-               values = g_strsplit (part, " ", -1);
-
-               iinfo->server_flags = g_ascii_strtoll (values [0], NULL, 10);
-               iinfo->item_type = g_ascii_strtoll (values [1], NULL, 10);
-               iinfo->change_key = g_strdup (values [2]);
-
-               g_strfreev (values);
-       }
-
-       return info;
-}
-
-static CamelMIRecord *
-message_info_to_db (CamelFolderSummary *s, CamelMessageInfo *info)
-{
-       CamelEasMessageInfo *iinfo = (CamelEasMessageInfo *)info;
-       struct _CamelMIRecord *mir;
-
-       mir = CAMEL_FOLDER_SUMMARY_CLASS (camel_eas_summary_parent_class)->message_info_to_db (s, info);
-       if (mir)
-               mir->bdata = g_strdup_printf ("%u %d %s", iinfo->server_flags, iinfo->item_type, 
iinfo->change_key);
-
-       return mir;
-}
-
-static CamelMessageContentInfo *
-content_info_from_db (CamelFolderSummary *s, CamelMIRecord *mir)
-{
-       gchar *part = mir->cinfo;
-       guint32 type=0;
-
-       if (part) {
-               if (*part == ' ')
-                       part++;
-               if (part) {
-                       EXTRACT_FIRST_DIGIT (type);
-               }
-       }
-       mir->cinfo = part;
-       if (type)
-               return CAMEL_FOLDER_SUMMARY_CLASS (camel_eas_summary_parent_class)->content_info_from_db (s, 
mir);
-       else
-               return camel_folder_summary_content_info_new (s);
-}
-
-static SUM_DB_RETTYPE
-content_info_to_db (CamelFolderSummary *s, CamelMessageContentInfo *info, CamelMIRecord *mir)
-{
-
-       if (info->type) {
-               mir->cinfo = g_strdup ("1");
-               return CAMEL_FOLDER_SUMMARY_CLASS (camel_eas_summary_parent_class)->content_info_to_db (s, 
info, mir);
-       } else {
-               mir->cinfo = g_strdup ("0");
-               return SUM_DB_RET_OK;
-       }
-}
-
 void
 camel_eas_summary_add_message  (CamelFolderSummary *summary,
                                 const gchar *uid,
                                 CamelMimeMessage *message)
 {
-       CamelEasMessageInfo *mi;
+       CamelMessageInfo *mi;
        CamelMessageInfo *info;
-       const CamelFlag *flag;
-       const CamelTag *tag;
 
        info = camel_folder_summary_get (summary, uid);
 
        /* Create summary entry */
-       mi = (CamelEasMessageInfo *)camel_folder_summary_info_new_from_message (summary, message, NULL);
+       mi = camel_folder_summary_info_new_from_message (summary, message);
 
-       /* Copy flags 'n' tags */
-       mi->info.flags = camel_message_info_flags(info);
+       camel_message_info_set_abort_notifications (mi, TRUE);
 
-       flag = camel_message_info_user_flags(info);
-       while (flag) {
-               camel_message_info_set_user_flag((CamelMessageInfo *)mi, flag->name, TRUE);
-               flag = flag->next;
-       }
-       tag = camel_message_info_user_tags(info);
-       while (tag) {
-               camel_message_info_set_user_tag((CamelMessageInfo *)mi, tag->name, tag->value);
-               tag = tag->next;
-       }
-
-       mi->info.size = camel_message_info_size(info);
-       mi->info.uid = camel_pstring_strdup (uid);
-
-       camel_folder_summary_add (summary, (CamelMessageInfo *)mi);
-       camel_message_info_unref (info);
+       /* Copy flags 'n' tags */
+       camel_message_info_set_flags (mi, ~0, camel_message_info_get_flags (info));
+       camel_message_info_take_user_flags (mi, camel_message_info_dup_user_flags (info));
+       camel_message_info_take_user_tags (mi, camel_message_info_dup_user_tags (info));
+       camel_message_info_set_size (mi, camel_message_info_get_size (info));
+       camel_message_info_set_uid (mi, uid);
+
+       camel_message_info_set_abort_notifications (mi, FALSE);
+       camel_folder_summary_add (summary, mi, FALSE);
+       g_clear_object (&info);
 }
 
 void
@@ -293,31 +177,28 @@ camel_eas_summary_add_message_info        (CamelFolderSummary *summary,
                                         guint32 server_flags,
                                         CamelMessageInfo *mi)
 {
-       CamelMessageInfoBase *binfo = (CamelMessageInfoBase *) mi;
-       CamelEasMessageInfo *einfo = (CamelEasMessageInfo *) mi;
+       camel_message_info_set_flags (mi, server_flags, server_flags);
+       camel_eas_message_info_set_server_flags (CAMEL_EAS_MESSAGE_INFO (mi), server_flags);
+       camel_message_info_set_folder_flagged (mi, FALSE);
 
-       binfo->flags |= server_flags;
-       einfo->server_flags = server_flags;
-
-       binfo->flags &= ~CAMEL_MESSAGE_FOLDER_FLAGGED;
-       camel_folder_summary_add (summary, (CamelMessageInfo *)mi);
+       camel_folder_summary_add (summary, mi, FALSE);
 }
 
 static gboolean
-eas_update_user_flags (CamelMessageInfo *info, CamelFlag *server_user_flags)
+eas_update_user_flags (CamelMessageInfo *info,
+                      const CamelNamedFlags *server_user_flags)
 {
        gboolean changed = FALSE;
-       CamelMessageInfoBase *binfo = (CamelMessageInfoBase *) info;
        gboolean set_cal = FALSE;
 
-       if (camel_flag_get (&binfo->user_flags, "$has_cal"))
+       if (camel_message_info_get_user_flag (info, "$has_cal"))
                set_cal = TRUE;
 
-       changed = camel_flag_list_copy (&binfo->user_flags, &server_user_flags);
+       changed = camel_message_info_take_user_flags (info, camel_named_flags_copy (server_user_flags));
 
        /* reset the calendar flag if it was set in messageinfo before */
        if (set_cal)
-               camel_flag_set (&binfo->user_flags, "$has_cal", TRUE);
+               camel_message_info_set_user_flag (info, "$has_cal", TRUE);
 
        return changed;
 }
@@ -326,22 +207,21 @@ gboolean
 camel_eas_update_message_info_flags    (CamelFolderSummary *summary,
                                         CamelMessageInfo *info,
                                         guint32 server_flags,
-                                        CamelFlag *server_user_flags)
+                                        const CamelNamedFlags *server_user_flags)
 {
        CamelEasMessageInfo *einfo = (CamelEasMessageInfo *) info;
        gboolean changed = FALSE;
 
-       if (server_flags != einfo->server_flags) {
-               guint32 server_set, server_cleared;
+       if (server_flags != camel_eas_message_info_get_server_flags (einfo)) {
+               guint32 server_set, server_cleared, has_stored;
 
-               server_set = server_flags & ~einfo->server_flags;
-               server_cleared = einfo->server_flags & ~server_flags;
+               has_stored = camel_eas_message_info_get_server_flags (einfo);
+               server_set = server_flags & ~has_stored;
+               server_cleared = has_stored & ~server_flags;
 
                camel_message_info_set_flags (info, server_set | server_cleared,
-                                             (einfo->info.flags | server_set) & ~server_cleared);
-                einfo->server_flags = server_flags;
-               if (info->summary)
-                       camel_folder_summary_touch (info->summary);
+                                             (camel_message_info_get_flags (info) | server_set) & 
~server_cleared);
+                camel_eas_message_info_set_server_flags (einfo, server_flags);
                changed = TRUE;
        }
 
@@ -381,4 +261,3 @@ eas_summary_clear   (CamelFolderSummary *summary,
        camel_folder_change_info_free (changes);
        camel_folder_summary_free_array (known_uids);
 }
-
diff --git a/camel/camel-eas-summary.h b/camel/camel-eas-summary.h
index 17e59da..9e9b88d 100644
--- a/camel/camel-eas-summary.h
+++ b/camel/camel-eas-summary.h
@@ -27,7 +27,7 @@
 #define CAMEL_GW_SUMMARY_H
 
 #include <camel/camel.h>
-#include <libedataserver/eds-version.h>
+#include "camel-eas-message-info.h"
 
 /* Standard GObject macros */
 #define CAMEL_TYPE_EAS_SUMMARY \
@@ -52,26 +52,6 @@ G_BEGIN_DECLS
 
 typedef struct _CamelEasSummary CamelEasSummary;
 typedef struct _CamelEasSummaryClass CamelEasSummaryClass;
-typedef struct _CamelEasMessageInfo CamelEasMessageInfo;
-typedef struct _CamelEasMessageContentInfo CamelEasMessageContentInfo;
-
-/* extra summary flags*/
-enum {
-       CAMEL_GW_MESSAGE_JUNK = 1<<17,
-       CAMEL_GW_MESSAGE_NOJUNK = 1<<18
-};
-
-struct _CamelEasMessageInfo {
-       CamelMessageInfoBase info;
-
-       guint32 server_flags;
-       gint32 item_type;
-       gchar *change_key;
-} ;
-
-struct _CamelEasMessageContentInfo {
-       CamelMessageContentInfo info;
-} ;
 
 struct _CamelEasSummary {
        CamelFolderSummary parent;
@@ -94,7 +74,7 @@ gboolean
                                        (CamelFolderSummary *summary,
                                         CamelMessageInfo *info,
                                         guint32 server_flags,
-                                        CamelFlag *server_user_flags);
+                                        const CamelNamedFlags *server_user_flags);
 void   camel_eas_summary_add_message   (CamelFolderSummary *summary,
                                         const gchar *uid,
                                         CamelMimeMessage *message);
diff --git a/camel/camel-eas-utils.c b/camel/camel-eas-utils.c
index e8d311f..e2428df 100644
--- a/camel/camel-eas-utils.c
+++ b/camel/camel-eas-utils.c
@@ -343,11 +343,11 @@ camel_eas_utils_sync_updated_items (CamelEasFolder *eas_folder, GSList *items_up
 
        for (l = items_updated; l != NULL; l = g_slist_next (l)) {
                EasEmailInfo *item = l->data;
-               CamelEasMessageInfo *mi;
+               CamelMessageInfo *mi;
 
-               mi = (CamelEasMessageInfo *) camel_folder_summary_get (folder->summary, item->server_id);
+               mi = camel_folder_summary_get (folder->summary, item->server_id);
                if (mi) {
-                       gint flags = mi->info.flags;
+                       gint flags = camel_message_info_get_flags (mi);
 
                        if (item->flags & EAS_VALID_READ) {
                                if (item->flags & EAS_EMAIL_READ)
@@ -361,13 +361,10 @@ camel_eas_utils_sync_updated_items (CamelEasFolder *eas_folder, GSList *items_up
                                else
                                        flags &= ~CAMEL_MESSAGE_FLAGGED;
                        }
-                       if (camel_eas_update_message_info_flags (folder->summary, (CamelMessageInfo *)mi,
-                                                                flags, NULL))
-                               camel_folder_change_info_change_uid (ci, mi->info.uid);
+                       if (camel_eas_update_message_info_flags (folder->summary, mi, flags, NULL))
+                               camel_folder_change_info_change_uid (ci, camel_message_info_get_uid (mi));
 
-                       mi->info.dirty = TRUE;
-
-                       camel_message_info_unref (mi);
+                       g_clear_object (&mi);
                }
 
                g_object_unref (item);
@@ -399,7 +396,7 @@ camel_eas_utils_sync_created_items (CamelEasFolder *eas_folder, GSList *items_cr
        for (l = items_created; l != NULL; l = g_slist_next (l)) {
                EasEmailInfo *item = l->data;
                struct _camel_header_raw *camel_headers = NULL;
-               CamelEasMessageInfo *mi;
+               CamelMessageInfo *mi;
                int flags = 0;
                GSList *hl;
 
@@ -408,9 +405,9 @@ camel_eas_utils_sync_created_items (CamelEasFolder *eas_folder, GSList *items_cr
 
                printf("Got item with Server ID %s, flags %u\n", item->server_id, item->flags);
 
-               mi = (CamelEasMessageInfo *) camel_folder_summary_get (folder->summary, item->server_id);
+               mi = camel_folder_summary_get (folder->summary, item->server_id);
                if (mi) {
-                       camel_message_info_unref (mi);
+                       g_clear_object (&mi);
                        g_object_unref (item);
                        continue;
                }
@@ -421,18 +418,15 @@ camel_eas_utils_sync_created_items (CamelEasFolder *eas_folder, GSList *items_cr
                        camel_header_raw_append (&camel_headers, hdr->name, hdr->value, 0);
                }
 
-               mi = (CamelEasMessageInfo *)camel_folder_summary_info_new_from_header (folder->summary, 
camel_headers);
-               if (mi->info.content == NULL) {
-                       //mi->info.content = camel_folder_summary_content_info_new_from_header 
(folder->summary, camel_headers);
-                       mi->info.content = camel_folder_summary_content_info_new (folder->summary);
-                       mi->info.content->type = camel_content_type_new ("multipart", "mixed");
-               }
+               mi = camel_folder_summary_info_new_from_header (folder->summary, camel_headers);
 
                camel_header_raw_clear (&camel_headers);
 
-               mi->info.uid = camel_pstring_strdup (item->server_id);
-               mi->info.size = item->estimated_size;
-               mi->info.date_received = item->date_received;
+               camel_message_info_set_abort_notifications (mi, TRUE);
+
+               camel_message_info_set_uid (mi, item->server_id);
+               camel_message_info_set_size (mi, item->estimated_size);
+               camel_message_info_set_date_received (mi, item->date_received);
 
                if (item->attachments)
                        flags |= CAMEL_MESSAGE_ATTACHMENTS;
@@ -446,11 +440,12 @@ camel_eas_utils_sync_created_items (CamelEasFolder *eas_folder, GSList *items_cr
                if (item->importance == EAS_IMPORTANCE_HIGH)
                        flags |= CAMEL_MESSAGE_FLAGGED;
 
-               camel_eas_summary_add_message_info (folder->summary, flags,
-                                                   (CamelMessageInfo *) mi);
+               camel_message_info_set_abort_notifications (mi, FALSE);
+               camel_eas_summary_add_message_info (folder->summary, flags, mi);
                camel_folder_change_info_add_uid (ci, item->server_id);
                camel_folder_change_info_recent_uid (ci, item->server_id);
 
+               g_clear_object (&mi);
                g_object_unref (item);
 
                count++;
diff --git a/configuration/Makefile.am b/configuration/Makefile.am
index bb38af1..b89ec51 100644
--- a/configuration/Makefile.am
+++ b/configuration/Makefile.am
@@ -19,6 +19,7 @@ module_eas_mail_config_la_SOURCES = \
 
 module_eas_mail_config_la_LIBADD = \
        $(top_builddir)/libeasclient/libeasclient.la \
+       $(top_builddir)/libevoeas/libevoeas.la \
        $(EVOLUTION_MAIL_LIBS) \
        $(LIBEDATASERVER_LIBS) \
        $(LIBEBACKEND_LIBS) \


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