Fix some compiling errors.
[modest] / src / modest-mail-operation.c
index df79714..c86338d 100644 (file)
@@ -473,6 +473,7 @@ modest_mail_operation_send_mail (ModestMailOperation *self,
 void
 modest_mail_operation_send_new_mail (ModestMailOperation *self,
                                     TnyTransportAccount *transport_account,
+                                    TnyMsg *draft_msg,
                                     const gchar *from,  const gchar *to,
                                     const gchar *cc,  const gchar *bcc,
                                     const gchar *subject, const gchar *plain_body,
@@ -481,6 +482,7 @@ modest_mail_operation_send_new_mail (ModestMailOperation *self,
                                     TnyHeaderFlags priority_flags)
 {
        TnyMsg *new_msg = NULL;
+       TnyFolder *folder = NULL;
        ModestMailOperationPrivate *priv = NULL;
 
        g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
@@ -517,6 +519,15 @@ modest_mail_operation_send_new_mail (ModestMailOperation *self,
        /* Call mail operation */
        modest_mail_operation_send_mail (self, transport_account, new_msg);
 
+       folder = modest_tny_account_get_special_folder (TNY_ACCOUNT (transport_account), TNY_FOLDER_TYPE_DRAFTS);
+       if (folder) {
+               if (draft_msg != NULL) {
+                       TnyHeader *header = tny_msg_get_header (draft_msg);
+                       tny_folder_remove_msg (folder, header, NULL);
+                       g_object_unref (header);
+               }
+       }
+
        /* Free */
        g_object_unref (G_OBJECT (new_msg));
 }
@@ -524,6 +535,7 @@ modest_mail_operation_send_new_mail (ModestMailOperation *self,
 void
 modest_mail_operation_save_to_drafts (ModestMailOperation *self,
                                      TnyTransportAccount *transport_account,
+                                     TnyMsg *draft_msg,
                                      const gchar *from,  const gchar *to,
                                      const gchar *cc,  const gchar *bcc,
                                      const gchar *subject, const gchar *plain_body,
@@ -562,6 +574,12 @@ modest_mail_operation_save_to_drafts (ModestMailOperation *self,
                             "modest: failed to create a new msg\n");
                goto end;
        }
+
+       if (draft_msg != NULL) {
+               TnyHeader *header = tny_msg_get_header (draft_msg);
+               tny_folder_remove_msg (folder, header, NULL);
+               g_object_unref (header);
+       }
        
        tny_folder_add_msg (folder, msg, &(priv->error));
        if (priv->error)
@@ -1366,7 +1384,7 @@ void modest_mail_operation_get_msg (ModestMailOperation *self,
        /* Get message from folder */
        if (folder) {
                /* Get account and set it into mail_operation */
-               priv->account = tny_folder_get_account (TNY_FOLDER(folder));            
+               priv->account = tny_folder_get_account (TNY_FOLDER(folder));
 
                helper = g_slice_new0 (GetMsgAsyncHelper);
                helper->mail_op = self;
@@ -1629,13 +1647,18 @@ modest_mail_operation_get_msgs_full (ModestMailOperation *self,
        priv->total = tny_list_get_length(header_list);
 
        /* Get account and set it into mail_operation */
-       if (tny_list_get_length (header_list) > 1) {
-               iter = tny_list_create_iterator (header_list);          
+       if (tny_list_get_length (header_list) >= 1) {
+               iter = tny_list_create_iterator (header_list);
                header = TNY_HEADER (tny_iterator_get_current (iter));
                folder = tny_header_get_folder (header);                
                priv->account = tny_folder_get_account (TNY_FOLDER(folder));
                g_object_unref (header);
                g_object_unref (folder);
+
+               if (tny_list_get_length (header_list) == 1) {
+                       g_object_unref (iter);
+                       iter = NULL;
+               }
        }
 
        /* Get msg size limit */
@@ -2001,7 +2024,4 @@ modest_mail_operation_notify_end (ModestMailOperation *self)
        state = modest_mail_operation_clone_state (self);
        g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, state, NULL);
        g_slice_free (ModestMailOperationState, state);
-
-       /* Notify the queue */
-       modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
 }