* implemented the send-queue stuff (partially); still
[modest] / src / modest-mail-operation.c
index 3c17847..afa4f5b 100644 (file)
 #include <camel/camel-stream-mem.h>
 #include <glib/gi18n.h>
 #include <modest-tny-account.h>
+#include <modest-tny-send-queue.h>
+#include <modest-runtime.h>
 #include "modest-text-utils.h"
-#include "modest-tny-msg-actions.h"
+#include "modest-tny-msg.h"
 #include "modest-tny-platform-factory.h"
 #include "modest-marshal.h"
 #include "modest-formatter.h"
@@ -213,10 +215,14 @@ modest_mail_operation_send_mail (ModestMailOperation *self,
                                 TnyTransportAccount *transport_account,
                                 TnyMsg* msg)
 {
+       TnySendQueue *send_queue;
+       
        g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
        g_return_if_fail (TNY_IS_TRANSPORT_ACCOUNT (transport_account));
 
-       tny_transport_account_send (transport_account, msg, NULL); /* FIXME */
+       send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
+       
+       tny_send_queue_add (send_queue, msg);
 }
 
 void
@@ -273,7 +279,7 @@ modest_mail_operation_send_new_mail (ModestMailOperation *self,
        add_attachments (new_msg, (GList*) attachments_list);
 
        /* Send mail */
-       tny_transport_account_send (transport_account, new_msg, NULL); /* FIXME */
+       modest_mail_operation_send_mail (self, transport_account, new_msg);
 
        /* Clean */
        g_object_unref (header);
@@ -308,7 +314,7 @@ create_reply_forward_mail (TnyMsg *msg, const gchar *from, gboolean is_reply, gu
        /* Get body from original msg. Always look for the text/plain
           part of the message to create the reply/forwarded mail */
        header = tny_msg_get_header (msg);
-       body   = modest_tny_msg_actions_find_body_part (msg, FALSE);
+       body   = modest_tny_msg_find_body_part (msg, FALSE);
 
        /* TODO: select the formatter from account prefs */
        formatter = modest_formatter_new ("text/plain");
@@ -335,8 +341,9 @@ create_reply_forward_mail (TnyMsg *msg, const gchar *from, gboolean is_reply, gu
                        break;
                }
        }
-       g_object_unref (G_OBJECT (formatter));
-
+       g_object_unref (G_OBJECT(formatter));
+       g_object_unref (G_OBJECT(body));
+       
        /* Fill the header */
        fact = modest_tny_platform_factory_get_instance ();
        new_header = TNY_HEADER (tny_platform_factory_new_header (fact));
@@ -402,8 +409,7 @@ modest_mail_operation_create_reply_mail (TnyMsg *msg,
        new_header = tny_msg_get_header (new_msg);
        reply_to = tny_header_get_replyto (header);
 
-       /* TODO: tinymail returns Invalid and it should return NULL */
-       if (strcmp (reply_to, "Invalid"))
+       if (reply_to)
                tny_header_set_to (new_header, reply_to);
        else
                tny_header_set_to (new_header, tny_header_get_from (header));
@@ -494,10 +500,11 @@ folder_refresh_cb (TnyFolder *folder, gboolean canceled, GError **err, gpointer
                g_object_unref (G_OBJECT (list));
                g_slice_free (RefreshFolderAsyncHelper, helper);
        } else {
-               tny_folder_refresh_async (TNY_FOLDER (tny_iterator_get_current (helper->iter)),
-                                         folder_refresh_cb,
+               TnyFolder *folder = TNY_FOLDER (tny_iterator_get_current (helper->iter));
+               tny_folder_refresh_async (folder, folder_refresh_cb,
                                          status_update_cb, 
                                          helper);
+               g_object_unref (G_OBJECT(folder));
        }
        g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
 }
@@ -509,7 +516,8 @@ update_folders_cb (TnyFolderStore *folder_store, TnyList *list, GError **err, gp
        ModestMailOperation *self;
        ModestMailOperationPrivate *priv;
        RefreshFolderAsyncHelper *helper;
-
+       TnyFolder *folder;
+       
        self  = MODEST_MAIL_OPERATION (user_data);
        priv  = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
 
@@ -530,10 +538,10 @@ update_folders_cb (TnyFolderStore *folder_store, TnyList *list, GError **err, gp
        helper->canceled = 0;
 
        /* Async refresh folders */
-       tny_folder_refresh_async (TNY_FOLDER (tny_iterator_get_current (helper->iter)),
-                                 folder_refresh_cb,
-                                 status_update_cb, 
-                                 helper);
+       folder = TNY_FOLDER (tny_iterator_get_current (helper->iter));
+       tny_folder_refresh_async (folder, folder_refresh_cb,
+                                 status_update_cb, helper);
+       g_object_unref (G_OBJECT(folder));
 }
 
 gboolean
@@ -687,10 +695,8 @@ modest_mail_operation_remove_folder (ModestMailOperation *self,
                TnyFolder *trash_folder;
                trash_folder = modest_tny_account_get_special_folder (TNY_ACCOUNT(folder_store),
                                                                      TNY_FOLDER_TYPE_TRASH);
-               
                /* TODO: error_handling */
-               modest_mail_operation_move_folder (self, 
-                                                  folder, 
+               modest_mail_operation_move_folder (self, folder, 
                                                   TNY_FOLDER_STORE (trash_folder));
        } else {
                tny_folder_store_remove_folder (folder_store, folder, NULL); /* FIXME */
@@ -758,8 +764,7 @@ modest_mail_operation_xfer_folder (ModestMailOperation *self,
 
        /* Create the destination folder */
        folder_name = tny_folder_get_name (folder);
-       dest_folder = modest_mail_operation_create_folder (self, 
-                                                          parent, folder_name);
+       dest_folder = modest_mail_operation_create_folder (self, parent, folder_name);
 
        /* Transfer messages */
        headers = TNY_LIST (tny_simple_list_new ());
@@ -772,12 +777,11 @@ modest_mail_operation_xfer_folder (ModestMailOperation *self,
        iter = tny_list_create_iterator (folders);
 
        while (!tny_iterator_is_done (iter)) {
-
                child = TNY_FOLDER (tny_iterator_get_current (iter));
-               modest_mail_operation_xfer_folder (self, child,
-                                                  TNY_FOLDER_STORE (dest_folder),
+               modest_mail_operation_xfer_folder (self, child, TNY_FOLDER_STORE (dest_folder),
                                                   delete_original);
                tny_iterator_next (iter);
+               g_object_unref (G_OBJECT(child));
        }
 
        /* Delete source folder (if needed) */