[evolution-mapi] Bug #585353 - Marking Junk doesn't work on mapi account



commit ceb5d6c45a6ebeec04e51f0e0dec6c32f25bd42c
Author: Milan Crha <mcrha redhat com>
Date:   Tue Jun 8 18:25:54 2010 +0200

    Bug #585353 - Marking Junk doesn't work on mapi account

 src/camel/camel-mapi-folder.c |   58 +++++++++++++++++++++-------------------
 src/camel/camel-mapi-store.c  |   10 ++++++-
 2 files changed, 39 insertions(+), 29 deletions(-)
---
diff --git a/src/camel/camel-mapi-folder.c b/src/camel/camel-mapi-folder.c
index 18f5923..8428539 100644
--- a/src/camel/camel-mapi-folder.c
+++ b/src/camel/camel-mapi-folder.c
@@ -728,16 +728,14 @@ mapi_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
 	CamelMapiMessageInfo *mapi_info = NULL;
 	CamelStore *parent_store;
 
-	GSList *read_items = NULL, *unread_items = NULL, *to_free = NULL;
+	GSList *read_items = NULL, *unread_items = NULL, *to_free = NULL, *junk_items = NULL, *deleted_items = NULL, *l;
 	flags_diff_t diff, unset_flags;
 	const gchar *folder_id;
 	const gchar *full_name;
 	mapi_id_t fid, deleted_items_fid;
 	gint count, i;
 	guint32 options =0;
-
-	GSList *deleted_items, *deleted_head;
-	deleted_items = deleted_head = NULL;
+	gboolean is_junk_folder;
 
 	full_name = camel_folder_get_full_name (folder);
 	parent_store = camel_folder_get_parent_store (folder);
@@ -765,6 +763,8 @@ mapi_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
 	}
 	camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
+	is_junk_folder = (mapi_folder->type & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_JUNK;
+
 	count = camel_folder_summary_count (folder->summary);
 	CAMEL_MAPI_FOLDER_REC_LOCK (folder, cache_lock);
 	for (i=0; i < count; i++) {
@@ -795,22 +795,13 @@ mapi_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
 				camel_message_info_free (info);
 				g_free (mid);
 				continue;
-			} else {
-				if (diff.bits & CAMEL_MESSAGE_DELETED) {
-					if (diff.bits & CAMEL_MESSAGE_SEEN) {
-						read_items = g_slist_prepend (read_items, mid);
-						used = TRUE;
-					}
-					if (deleted_items) {
-						deleted_items = g_slist_prepend (deleted_items, mid);
-						used = TRUE;
-					} else {
-						g_slist_free (deleted_head);
-						deleted_head = NULL;
-						deleted_head = deleted_items = g_slist_prepend (deleted_items, mid);
-						used = TRUE;
-					}
-				}
+			}
+			if (diff.bits & CAMEL_MESSAGE_DELETED) {
+				deleted_items = g_slist_prepend (deleted_items, mid);
+				used = TRUE;
+			} else if (!is_junk_folder && (diff.bits & CAMEL_MESSAGE_JUNK) != 0) {
+				junk_items = g_slist_prepend (junk_items, mid);
+				used = TRUE;
 			}
 
 			if (diff.bits & CAMEL_MESSAGE_SEEN) {
@@ -843,14 +834,12 @@ mapi_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
 		camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 		exchange_mapi_connection_set_flags (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, read_items, 0, options);
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
-		g_slist_free (read_items);
 	}
 
 	if (unread_items) {
 		camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 		exchange_mapi_connection_set_flags (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, unread_items, CLEAR_READ_FLAG, options);
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
-		g_slist_free (read_items);
 	}
 
 	/* Remove messages from server*/
@@ -866,20 +855,33 @@ mapi_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 	}
 
+	
+	if (junk_items) {
+		mapi_id_t junk_fid = 0;
+
+		camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
+		exchange_mapi_util_mapi_id_from_string (camel_mapi_store_system_folder_fid (mapi_store, olFolderJunk), &junk_fid);
+		exchange_mapi_connection_move_items (camel_mapi_store_get_exchange_connection (mapi_store), fid, junk_fid, junk_items);
+		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
+
+		/* in junk_items are only emails which are not deleted */
+		deleted_items = g_slist_concat (deleted_items, g_slist_copy (junk_items));
+	}
+
 	/*Remove messages from local cache*/
-	while (deleted_items) {
-		gchar * deleted_msg_uid = g_strdup_printf ("%016" G_GINT64_MODIFIER "X%016" G_GINT64_MODIFIER "X", fid, *(mapi_id_t *)deleted_items->data);
+	for (l = deleted_items; l; l = l->next) {
+		gchar * deleted_msg_uid = g_strdup_printf ("%016" G_GINT64_MODIFIER "X%016" G_GINT64_MODIFIER "X", fid, *(mapi_id_t *)l->data);
 
 		CAMEL_MAPI_FOLDER_REC_LOCK (folder, cache_lock);
 		camel_folder_summary_remove_uid (folder->summary, deleted_msg_uid);
 		camel_data_cache_remove(mapi_folder->cache, "cache", deleted_msg_uid, NULL);
 		CAMEL_MAPI_FOLDER_REC_UNLOCK (folder, cache_lock);
-
-		deleted_items = g_slist_next (deleted_items);
 	}
 
+	g_slist_free (read_items);
 	g_slist_free (unread_items);
-	g_slist_free (deleted_head);
+	g_slist_free (deleted_items);
+	g_slist_free (junk_items);
 
 	g_slist_foreach (to_free, (GFunc) g_free, NULL);
 	g_slist_free (to_free);
@@ -1634,7 +1636,7 @@ camel_mapi_folder_init (CamelMapiFolder *mapi_folder)
 	mapi_folder->priv = CAMEL_MAPI_FOLDER_GET_PRIVATE (mapi_folder);
 
 	folder->permanent_flags = CAMEL_MESSAGE_ANSWERED | CAMEL_MESSAGE_DELETED |
-		CAMEL_MESSAGE_DRAFT | CAMEL_MESSAGE_FLAGGED | CAMEL_MESSAGE_SEEN;
+		CAMEL_MESSAGE_DRAFT | CAMEL_MESSAGE_FLAGGED | CAMEL_MESSAGE_SEEN | CAMEL_MESSAGE_JUNK;
 
 	folder->folder_flags = CAMEL_FOLDER_HAS_SUMMARY_CAPABILITY | CAMEL_FOLDER_HAS_SEARCH_CAPABILITY;
 
diff --git a/src/camel/camel-mapi-store.c b/src/camel/camel-mapi-store.c
index a0c3b58..04ad241 100644
--- a/src/camel/camel-mapi-store.c
+++ b/src/camel/camel-mapi-store.c
@@ -98,6 +98,7 @@ static gboolean		mapi_noop(CamelStore *, CamelException *);
 static CamelFolderInfo * mapi_build_folder_info(CamelMapiStore *mapi_store, const gchar *parent_name, const gchar *folder_name);
 static gboolean mapi_fid_is_system_folder (CamelMapiStore *mapi_store, const gchar *fid);
 static CamelFolder *mapi_get_trash (CamelStore *store, CamelException *ex);
+static CamelFolder *mapi_get_junk (CamelStore *store, CamelException *ex);
 
 static void mapi_update_folder_hash_tables (CamelMapiStore *store, const gchar *name, const gchar *fid, const gchar *parent_id);
 /* static const gchar * mapi_folders_hash_table_name_lookup (CamelMapiStore *store, const gchar *fid, gboolean use_cache); */
@@ -232,6 +233,7 @@ camel_mapi_store_class_init (CamelMapiStoreClass *class)
 	store_class->unsubscribe_folder = mapi_unsubscribe_folder;
 	store_class->noop = mapi_noop;
 	store_class->get_trash = mapi_get_trash;
+	store_class->get_junk = mapi_get_junk;
 }
 
 /*
@@ -299,7 +301,7 @@ static gboolean mapi_construct(CamelService *service, CamelSession *session,
 	store->flags &= ~CAMEL_STORE_VJUNK;
 	store->flags &= ~CAMEL_STORE_VTRASH;
 
-	store->flags |= CAMEL_STORE_SUBSCRIPTIONS;
+	store->flags |= CAMEL_STORE_SUBSCRIPTIONS | CAMEL_STORE_REAL_JUNK_FOLDER;
 
 	return TRUE;
 }
@@ -1801,3 +1803,9 @@ mapi_get_trash (CamelStore *store, CamelException *ex)
 {
 	return mapi_get_folder_with_type (store, CAMEL_FOLDER_TYPE_TRASH, ex);
 }
+
+static CamelFolder *
+mapi_get_junk (CamelStore *store, CamelException *ex)
+{
+	return mapi_get_folder_with_type (store, CAMEL_FOLDER_TYPE_JUNK, ex);
+}



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