* temp fix to prevent crashing while doing wild folder changing / cancelling actions
[modest] / src / modest-mail-operation.c
index b0e77eb..6676eec 100644 (file)
@@ -105,7 +105,6 @@ struct _ModestMailOperationPrivate {
 typedef struct _GetMsgAsyncHelper {    
        ModestMailOperation *mail_op;
        GetMsgAsyncUserCallback user_callback;  
-       guint pending_ops;
        gpointer user_data;
 } GetMsgAsyncHelper;
 
@@ -435,7 +434,17 @@ modest_mail_operation_clone_state (ModestMailOperation *self)
        ModestMailOperationState *state;
        ModestMailOperationPrivate *priv;
 
+       /* FIXME: this should be fixed properly
+        * 
+        * in some cases, priv was NULL, so checking here to
+        * make sure.
+        */
+       g_return_val_if_fail (self, NULL);
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
+       g_return_val_if_fail (priv, NULL);
+
+       if (!priv)
+               return NULL;
 
        state = g_slice_new (ModestMailOperationState);
 
@@ -528,7 +537,8 @@ modest_mail_operation_send_new_mail (ModestMailOperation *self,
 
        /* Set priority flags in message */
        header = tny_msg_get_header (new_msg);
-       tny_header_set_flags (header, priority_flags);
+       if (priority_flags != 0)
+               tny_header_set_flags (header, priority_flags);
 
        /* Call mail operation */
        modest_mail_operation_send_mail (self, transport_account, new_msg);
@@ -598,7 +608,9 @@ modest_mail_operation_save_to_drafts (ModestMailOperation *self,
 
        if (draft_msg != NULL) {
                header = tny_msg_get_header (draft_msg);
+               /* Remove the old draft expunging it */
                tny_folder_remove_msg (folder, header, NULL);
+               tny_folder_sync (folder, TRUE, NULL);
                g_object_unref (header);
        }
        
@@ -842,7 +854,6 @@ update_account_thread (gpointer thr_user_data)
        ModestMailOperationPrivate *priv;
        ModestTnySendQueue *send_queue;
 
-
        info = (UpdateAccountInfo *) thr_user_data;
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(info->mail_op);
 
@@ -1039,7 +1050,7 @@ update_account_thread (gpointer thr_user_data)
        /* Notify about operation end. Note that the info could be
           freed before this idle happens, but the mail operation will
           be still alive */
-       g_idle_add (notify_update_account_queue, info->mail_op);
+       g_idle_add (notify_update_account_queue, g_object_ref (info->mail_op));
 
        /* Frees */
        g_object_unref (query);
@@ -1443,7 +1454,6 @@ void modest_mail_operation_get_msg (ModestMailOperation *self,
                helper = g_slice_new0 (GetMsgAsyncHelper);
                helper->mail_op = self;
                helper->user_callback = user_callback;
-               helper->pending_ops = 1;
                helper->user_data = user_data;
 
                tny_folder_get_msg_async (folder, header, get_msg_cb, get_msg_status_cb, helper);
@@ -1477,8 +1487,6 @@ get_msg_cb (TnyFolder *folder,
        self = helper->mail_op;
        g_return_if_fail (MODEST_IS_MAIL_OPERATION(self));
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
-       
-       helper->pending_ops--;
 
        /* Check errors and cancel */
        if (*error) {
@@ -1502,14 +1510,12 @@ get_msg_cb (TnyFolder *folder,
                helper->user_callback (self, NULL, msg, helper->user_data);
        }
 
-       /* Free */
  out:
-       if (helper->pending_ops == 0) {
-               g_slice_free (GetMsgAsyncHelper, helper);
+       /* Free */
+       g_slice_free (GetMsgAsyncHelper, helper);
                
-               /* Notify about operation end */
-               modest_mail_operation_notify_end (self);        
-       }
+       /* Notify about operation end */
+       modest_mail_operation_notify_end (self);        
 }
 
 static void     
@@ -1668,7 +1674,7 @@ get_msgs_full_thread (gpointer thr_user_data)
                priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
 
        /* Notify about operation end */
-       g_idle_add (notify_update_account_queue, info->mail_op);
+       g_idle_add (notify_update_account_queue, g_object_ref (info->mail_op));
 
        /* Free thread resources. Will be called after all previous idles */
        g_idle_add_full (G_PRIORITY_DEFAULT_IDLE + 1, get_msgs_full_destroyer, info, NULL);