* Fixes NB#84492, remove the messages in the outbox that belongs to a removed account
authorSergio Villar Senin <svillar@igalia.com>
Fri, 18 Apr 2008 10:09:38 +0000 (10:09 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Fri, 18 Apr 2008 10:09:38 +0000 (10:09 +0000)
* Added a new method to remove send_queues
* Fixed and invalid error report when a mail operation is never executed

pmo-trunk-r4429

src/modest-mail-operation-queue.c
src/modest-runtime.c
src/modest-runtime.h
src/modest-tny-account-store.c

index eacb4c3..aadb3b8 100644 (file)
@@ -328,7 +328,8 @@ modest_mail_operation_queue_remove (ModestMailOperationQueue *self,
 
        /* Check errors */
        status = modest_mail_operation_get_status (mail_op);
 
        /* Check errors */
        status = modest_mail_operation_get_status (mail_op);
-       if (status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
+       if (status != MODEST_MAIL_OPERATION_STATUS_SUCCESS &&
+           status != MODEST_MAIL_OPERATION_STATUS_INVALID) {
                /* This is a sanity check. Shouldn't be needed, but
                   prevent possible application crashes. It's useful
                   also for detecting mail operations with invalid
                /* This is a sanity check. Shouldn't be needed, but
                   prevent possible application crashes. It's useful
                   also for detecting mail operations with invalid
index 9d8a368..26ed013 100644 (file)
@@ -241,6 +241,24 @@ void modest_runtime_remove_all_send_queues ()
        modest_cache_mgr_flush (cache_mgr, MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE);
 }
 
        modest_cache_mgr_flush (cache_mgr, MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE);
 }
 
+void 
+modest_runtime_remove_send_queue (TnyTransportAccount *account)
+{
+
+       ModestCacheMgr *cache_mgr;
+       GHashTable     *send_queue_cache;
+
+       g_return_if_fail (TNY_IS_TRANSPORT_ACCOUNT (account));  
+       g_return_if_fail (_singletons);
+
+       cache_mgr = modest_singletons_get_cache_mgr (_singletons);
+       send_queue_cache = modest_cache_mgr_get_cache (cache_mgr,
+                                                      MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE); 
+
+       if (g_hash_table_lookup (send_queue_cache, account))
+               g_hash_table_remove (send_queue_cache, account);
+}
+
 ModestWindowMgr *
 modest_runtime_get_window_mgr (void)
 {
 ModestWindowMgr *
 modest_runtime_get_window_mgr (void)
 {
index 98b92e0..53bccbd 100644 (file)
@@ -195,6 +195,14 @@ ModestMailOperationQueue* modest_runtime_get_mail_operation_queue (void);
 ModestTnySendQueue* modest_runtime_get_send_queue        (TnyTransportAccount *account);
 
 /**
 ModestTnySendQueue* modest_runtime_get_send_queue        (TnyTransportAccount *account);
 
 /**
+ * modest_runtime_remove_send_queue:
+ * @account: a #TnyTransportAccount
+ * 
+ * Removes the send queue associated with the given transport account
+ **/
+void modest_runtime_remove_send_queue (TnyTransportAccount *account);
+
+/**
  * modest_runtime_remove_all_send_queues:
  * 
  * Removes all send queues, ready for them to be recreated, for instance 
  * modest_runtime_remove_all_send_queues:
  * 
  * Removes all send queues, ready for them to be recreated, for instance 
index 23aff8b..088f941 100644 (file)
@@ -1744,8 +1744,17 @@ on_account_disconnect_when_removing (TnyCamelAccount *account,
        g_object_unref (account);
 
        /* Clear the cache if it's an store account */
        g_object_unref (account);
 
        /* Clear the cache if it's an store account */
-       if (TNY_IS_STORE_ACCOUNT (account))
+       if (TNY_IS_STORE_ACCOUNT (account)) {
                tny_store_account_delete_cache (TNY_STORE_ACCOUNT (account));
                tny_store_account_delete_cache (TNY_STORE_ACCOUNT (account));
+       } else if (TNY_IS_TRANSPORT_ACCOUNT (account)) {
+               ModestTnySendQueue* send_queue;
+               send_queue = modest_runtime_get_send_queue (TNY_TRANSPORT_ACCOUNT (account));
+               if (modest_tny_send_queue_sending_in_progress (send_queue))
+                       tny_send_queue_cancel (TNY_SEND_QUEUE (send_queue),
+                                              TNY_SEND_QUEUE_CANCEL_ACTION_REMOVE, 
+                                              NULL);
+               modest_runtime_remove_send_queue (TNY_TRANSPORT_ACCOUNT (account));
+       }
 }
 
 static void
 }
 
 static void
@@ -1816,12 +1825,15 @@ on_account_removed (ModestAccountMgr *acc_mgr,
 
                        if (outbox_account) {
                                tny_list_remove (priv->store_accounts_outboxes, G_OBJECT (outbox_account));
 
                        if (outbox_account) {
                                tny_list_remove (priv->store_accounts_outboxes, G_OBJECT (outbox_account));
+                               /* Remove existing emails to send */
+                               tny_store_account_delete_cache (TNY_STORE_ACCOUNT (outbox_account));
                                g_object_unref (outbox_account);
                        }
 
                        local_account = modest_tny_account_store_get_local_folders_account (self);
                        modest_tny_local_folders_account_remove_folder_from_outbox (MODEST_TNY_LOCAL_FOLDERS_ACCOUNT (local_account),
                                                                                    outbox);
                                g_object_unref (outbox_account);
                        }
 
                        local_account = modest_tny_account_store_get_local_folders_account (self);
                        modest_tny_local_folders_account_remove_folder_from_outbox (MODEST_TNY_LOCAL_FOLDERS_ACCOUNT (local_account),
                                                                                    outbox);
+
                        g_hash_table_remove (priv->outbox_of_transport, transport_account);
 
                        /* Notify the change in the local account */
                        g_hash_table_remove (priv->outbox_of_transport, transport_account);
 
                        /* Notify the change in the local account */