1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "modest-mail-operation.h"
31 /* include other impl specific header files */
34 #include <tny-mime-part.h>
35 #include <tny-store-account.h>
36 #include <tny-folder-store.h>
37 #include <tny-folder-store-query.h>
38 #include <tny-camel-stream.h>
39 #include <tny-simple-list.h>
40 #include <tny-send-queue.h>
41 #include <camel/camel-stream-mem.h>
42 #include <glib/gi18n.h>
43 #include <modest-tny-account.h>
44 #include <modest-tny-send-queue.h>
45 #include <modest-runtime.h>
46 #include "modest-text-utils.h"
47 #include "modest-tny-msg.h"
48 #include "modest-tny-folder.h"
49 #include "modest-tny-platform-factory.h"
50 #include "modest-marshal.h"
51 #include "modest-error.h"
53 /* 'private'/'protected' functions */
54 static void modest_mail_operation_class_init (ModestMailOperationClass *klass);
55 static void modest_mail_operation_init (ModestMailOperation *obj);
56 static void modest_mail_operation_finalize (GObject *obj);
58 static void update_folders_cb (TnyFolderStore *self,
63 enum _ModestMailOperationSignals
65 PROGRESS_CHANGED_SIGNAL,
70 typedef struct _ModestMailOperationPrivate ModestMailOperationPrivate;
71 struct _ModestMailOperationPrivate {
74 ModestMailOperationStatus status;
78 #define MODEST_MAIL_OPERATION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
79 MODEST_TYPE_MAIL_OPERATION, \
80 ModestMailOperationPrivate))
82 #define CHECK_EXCEPTION(priv, new_status) if (priv->error) {\
83 priv->status = new_status;\
86 typedef struct _RefreshFolderAsyncHelper
88 ModestMailOperation *mail_op;
93 } RefreshFolderAsyncHelper;
95 typedef struct _XFerMsgAsyncHelper
97 ModestMailOperation *mail_op;
99 TnyFolder *dest_folder;
101 } XFerMsgAsyncHelper;
105 static GObjectClass *parent_class = NULL;
107 static guint signals[NUM_SIGNALS] = {0};
110 modest_mail_operation_get_type (void)
112 static GType my_type = 0;
114 static const GTypeInfo my_info = {
115 sizeof(ModestMailOperationClass),
116 NULL, /* base init */
117 NULL, /* base finalize */
118 (GClassInitFunc) modest_mail_operation_class_init,
119 NULL, /* class finalize */
120 NULL, /* class data */
121 sizeof(ModestMailOperation),
123 (GInstanceInitFunc) modest_mail_operation_init,
126 my_type = g_type_register_static (G_TYPE_OBJECT,
127 "ModestMailOperation",
134 modest_mail_operation_class_init (ModestMailOperationClass *klass)
136 GObjectClass *gobject_class;
137 gobject_class = (GObjectClass*) klass;
139 parent_class = g_type_class_peek_parent (klass);
140 gobject_class->finalize = modest_mail_operation_finalize;
142 g_type_class_add_private (gobject_class, sizeof(ModestMailOperationPrivate));
145 * ModestMailOperation::progress-changed
146 * @self: the #MailOperation that emits the signal
147 * @user_data: user data set when the signal handler was connected
149 * Emitted when the progress of a mail operation changes
151 signals[PROGRESS_CHANGED_SIGNAL] =
152 g_signal_new ("progress-changed",
153 G_TYPE_FROM_CLASS (gobject_class),
155 G_STRUCT_OFFSET (ModestMailOperationClass, progress_changed),
157 g_cclosure_marshal_VOID__VOID,
162 modest_mail_operation_init (ModestMailOperation *obj)
164 ModestMailOperationPrivate *priv;
166 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(obj);
168 priv->status = MODEST_MAIL_OPERATION_STATUS_INVALID;
175 modest_mail_operation_finalize (GObject *obj)
177 ModestMailOperationPrivate *priv;
179 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(obj);
182 g_error_free (priv->error);
186 G_OBJECT_CLASS(parent_class)->finalize (obj);
190 modest_mail_operation_new (void)
192 return MODEST_MAIL_OPERATION(g_object_new(MODEST_TYPE_MAIL_OPERATION, NULL));
197 modest_mail_operation_send_mail (ModestMailOperation *self,
198 TnyTransportAccount *transport_account,
201 TnySendQueue *send_queue;
203 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
204 g_return_if_fail (TNY_IS_TRANSPORT_ACCOUNT (transport_account));
205 g_return_if_fail (TNY_IS_MSG (msg));
207 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
208 if (!TNY_IS_SEND_QUEUE(send_queue))
209 g_printerr ("modest: could not find send queue for account\n");
212 tny_send_queue_add (send_queue, msg, &err);
214 g_printerr ("modest: error adding msg to send queue: %s\n",
218 g_message ("modest: message added to send queue");
221 /* Notify the queue */
222 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
226 modest_mail_operation_send_new_mail (ModestMailOperation *self,
227 TnyTransportAccount *transport_account,
228 const gchar *from, const gchar *to,
229 const gchar *cc, const gchar *bcc,
230 const gchar *subject, const gchar *plain_body,
231 const gchar *html_body,
232 const GList *attachments_list,
233 TnyHeaderFlags priority_flags)
236 ModestMailOperationPrivate *priv = NULL;
237 /* GList *node = NULL; */
239 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
240 g_return_if_fail (TNY_IS_TRANSPORT_ACCOUNT (transport_account));
242 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
244 /* Check parametters */
246 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
247 MODEST_MAIL_OPERATION_ERROR_BAD_PARAMETER,
248 _("Error trying to send a mail. You need to set at least one recipient"));
252 if (html_body == NULL) {
253 new_msg = modest_tny_msg_new (to, from, cc, bcc, subject, plain_body, (GSList *) attachments_list); /* FIXME: attachments */
255 new_msg = modest_tny_msg_new_html_plain (to, from, cc, bcc, subject, html_body, plain_body, (GSList *) attachments_list);
258 g_printerr ("modest: failed to create a new msg\n");
262 /* TODO: add priority handling. It's received in the priority_flags operator, and
263 it should have effect in the sending operation */
265 /* Call mail operation */
266 modest_mail_operation_send_mail (self, transport_account, new_msg);
269 g_object_unref (G_OBJECT (new_msg));
273 recurse_folders (TnyFolderStore *store, TnyFolderStoreQuery *query, TnyList *all_folders)
276 TnyList *folders = tny_simple_list_new ();
278 tny_folder_store_get_folders (store, folders, query, NULL);
279 iter = tny_list_create_iterator (folders);
281 while (!tny_iterator_is_done (iter)) {
283 TnyFolderStore *folder = (TnyFolderStore*) tny_iterator_get_current (iter);
285 tny_list_prepend (all_folders, G_OBJECT (folder));
287 recurse_folders (folder, query, all_folders);
289 g_object_unref (G_OBJECT (folder));
291 tny_iterator_next (iter);
293 g_object_unref (G_OBJECT (iter));
294 g_object_unref (G_OBJECT (folders));
298 update_folders_cb (TnyFolderStore *folder_store, TnyList *list, GError **err, gpointer user_data)
300 ModestMailOperation *self;
301 ModestMailOperationPrivate *priv;
303 TnyList *all_folders;
305 self = MODEST_MAIL_OPERATION (user_data);
306 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
308 g_message (__FUNCTION__);
311 priv->error = g_error_copy (*err);
312 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
316 /* Get all the folders We can do it synchronously because
317 we're already running in a different thread than the UI */
318 all_folders = tny_list_copy (list);
319 iter = tny_list_create_iterator (all_folders);
320 while (!tny_iterator_is_done (iter)) {
321 TnyFolderStore *folder = TNY_FOLDER_STORE (tny_iterator_get_current (iter));
323 recurse_folders (folder, NULL, all_folders);
324 tny_iterator_next (iter);
326 g_object_unref (G_OBJECT (iter));
328 /* Refresh folders */
329 iter = tny_list_create_iterator (all_folders);
330 priv->total = tny_list_get_length (all_folders);
332 while (!tny_iterator_is_done (iter) && !priv->error) {
334 TnyFolderStore *folder = TNY_FOLDER_STORE (tny_iterator_get_current (iter));
336 /* Refresh the folder */
337 tny_folder_refresh (TNY_FOLDER (folder), &(priv->error));
340 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
342 /* Update status and notify */
344 g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
347 g_object_unref (G_OBJECT (folder));
349 tny_iterator_next (iter);
352 g_object_unref (G_OBJECT (iter));
354 g_object_unref (G_OBJECT (list));
356 /* Check if the operation was a success */
357 if (priv->done == priv->total && !priv->error)
358 priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
361 g_object_unref (G_OBJECT (folder_store));
363 /* Notify the queue */
364 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
368 modest_mail_operation_update_account (ModestMailOperation *self,
369 TnyStoreAccount *store_account)
371 ModestMailOperationPrivate *priv;
374 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), FALSE);
375 g_return_val_if_fail (TNY_IS_STORE_ACCOUNT(store_account), FALSE);
377 /* Pick async call reference */
378 g_object_ref (store_account);
380 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
384 priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
386 /* Get subscribed folders & refresh them */
387 folders = TNY_LIST (tny_simple_list_new ());
389 g_message ("tny_folder_store_get_folders_async");
390 tny_folder_store_get_folders_async (TNY_FOLDER_STORE (store_account),
391 folders, update_folders_cb, NULL, self);
396 ModestMailOperationStatus
397 modest_mail_operation_get_status (ModestMailOperation *self)
399 ModestMailOperationPrivate *priv;
401 g_return_val_if_fail (self, MODEST_MAIL_OPERATION_STATUS_INVALID);
402 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self),
403 MODEST_MAIL_OPERATION_STATUS_INVALID);
405 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
410 modest_mail_operation_get_error (ModestMailOperation *self)
412 ModestMailOperationPrivate *priv;
414 g_return_val_if_fail (self, NULL);
415 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), NULL);
417 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
422 modest_mail_operation_cancel (ModestMailOperation *self)
429 modest_mail_operation_get_task_done (ModestMailOperation *self)
431 ModestMailOperationPrivate *priv;
433 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), 0);
435 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
440 modest_mail_operation_get_task_total (ModestMailOperation *self)
442 ModestMailOperationPrivate *priv;
444 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), 0);
446 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
451 modest_mail_operation_is_finished (ModestMailOperation *self)
453 ModestMailOperationPrivate *priv;
454 gboolean retval = FALSE;
456 if (!MODEST_IS_MAIL_OPERATION (self)) {
457 g_warning ("%s: invalid parametter", G_GNUC_FUNCTION);
461 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
463 if (priv->status == MODEST_MAIL_OPERATION_STATUS_SUCCESS ||
464 priv->status == MODEST_MAIL_OPERATION_STATUS_FAILED ||
465 priv->status == MODEST_MAIL_OPERATION_STATUS_CANCELED ||
466 priv->status == MODEST_MAIL_OPERATION_STATUS_FINISHED_WITH_ERRORS) {
475 /* ******************************************************************* */
476 /* ************************** STORE ACTIONS ************************* */
477 /* ******************************************************************* */
481 modest_mail_operation_create_folder (ModestMailOperation *self,
482 TnyFolderStore *parent,
485 ModestTnyFolderRules rules;
486 ModestMailOperationPrivate *priv;
487 TnyFolder *new_folder = NULL;
488 gboolean can_create = FALSE;
490 g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent), NULL);
491 g_return_val_if_fail (name, NULL);
493 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
496 if (!TNY_IS_FOLDER (parent)) {
497 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
498 MODEST_MAIL_OPERATION_ERROR_BAD_PARAMETER,
499 _("mail_in_ui_folder_create_error"));
501 /* Check folder rules */
502 rules = modest_tny_folder_get_rules (TNY_FOLDER (parent));
503 if (rules | MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE)
504 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
505 MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
506 _("mail_in_ui_folder_create_error"));
512 /* Create the folder */
513 new_folder = tny_folder_store_create_folder (parent, name, &(priv->error));
514 CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED);
517 /* Notify the queue */
518 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
524 modest_mail_operation_remove_folder (ModestMailOperation *self,
526 gboolean remove_to_trash)
528 TnyFolderStore *parent;
530 ModestMailOperationPrivate *priv;
531 ModestTnyFolderRules rules;
533 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
534 g_return_if_fail (TNY_IS_FOLDER (folder));
536 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
538 /* Check folder rules */
539 rules = modest_tny_folder_get_rules (TNY_FOLDER (parent));
540 if (rules | MODEST_FOLDER_RULES_FOLDER_NON_DELETABLE) {
541 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
542 MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
543 _("mail_in_ui_folder_delete_error"));
547 /* Get the account */
548 account = tny_folder_get_account (folder);
550 /* Delete folder or move to trash */
551 if (remove_to_trash) {
552 TnyFolder *trash_folder, *new_folder;
553 trash_folder = modest_tny_account_get_special_folder (account,
554 TNY_FOLDER_TYPE_TRASH);
555 /* TODO: error_handling */
556 new_folder = modest_mail_operation_xfer_folder (self, folder,
557 TNY_FOLDER_STORE (trash_folder), TRUE);
558 g_object_unref (G_OBJECT (new_folder));
560 parent = tny_folder_get_folder_store (folder);
562 tny_folder_store_remove_folder (parent, folder, &(priv->error));
563 CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED);
566 g_object_unref (G_OBJECT (parent));
568 g_object_unref (G_OBJECT (account));
571 /* Notify the queue */
572 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
576 modest_mail_operation_rename_folder (ModestMailOperation *self,
580 ModestMailOperationPrivate *priv;
581 ModestTnyFolderRules rules;
583 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
584 g_return_if_fail (TNY_IS_FOLDER_STORE (folder));
585 g_return_if_fail (name);
587 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
589 /* Check folder rules */
590 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder));
591 if (rules | MODEST_FOLDER_RULES_FOLDER_NON_RENAMEABLE) {
592 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
593 MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
594 _("FIXME: unable to rename"));
596 /* Rename. Camel handles folder subscription/unsubscription */
597 tny_folder_set_name (folder, name, &(priv->error));
598 CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED);
601 /* Notify the queue */
602 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
606 modest_mail_operation_xfer_folder (ModestMailOperation *self,
608 TnyFolderStore *parent,
609 gboolean delete_original)
611 ModestMailOperationPrivate *priv;
612 TnyFolder *new_folder = NULL;
613 ModestTnyFolderRules rules;
615 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), NULL);
616 g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent), NULL);
617 g_return_val_if_fail (TNY_IS_FOLDER (folder), NULL);
619 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
621 /* The moveable restriction is applied also to copy operation */
622 rules = modest_tny_folder_get_rules (TNY_FOLDER (parent));
623 if (rules | MODEST_FOLDER_RULES_FOLDER_NON_MOVEABLE) {
624 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
625 MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
626 _("FIXME: unable to rename"));
628 /* Move/Copy folder */
629 new_folder = tny_folder_copy (folder,
631 tny_folder_get_name (folder),
636 /* Notify the queue */
637 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
643 /* ******************************************************************* */
644 /* ************************** MSG ACTIONS ************************* */
645 /* ******************************************************************* */
648 modest_mail_operation_remove_msg (ModestMailOperation *self,
650 gboolean remove_to_trash)
653 ModestMailOperationPrivate *priv;
655 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
656 g_return_if_fail (TNY_IS_HEADER (header));
658 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
659 folder = tny_header_get_folder (header);
661 priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
663 /* Delete or move to trash */
664 if (remove_to_trash) {
665 TnyFolder *trash_folder;
666 TnyStoreAccount *store_account;
668 store_account = TNY_STORE_ACCOUNT (tny_folder_get_account (folder));
669 trash_folder = modest_tny_account_get_special_folder (TNY_ACCOUNT(store_account),
670 TNY_FOLDER_TYPE_TRASH);
672 modest_mail_operation_xfer_msg (self, header, trash_folder, TRUE);
673 /* g_object_unref (trash_folder); */
675 ModestMailOperationPrivate *priv;
677 /* Set status failed and set an error */
678 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
679 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
680 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
681 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
682 _("Error trying to delete a message. Trash folder not found"));
685 g_object_unref (G_OBJECT (store_account));
687 tny_folder_remove_msg (folder, header, &(priv->error));
689 tny_folder_sync(folder, TRUE, &(priv->error));
694 priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
696 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
699 g_object_unref (G_OBJECT (folder));
701 /* Notify the queue */
702 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
706 transfer_msgs_cb (TnyFolder *folder, GError **err, gpointer user_data)
708 XFerMsgAsyncHelper *helper;
709 ModestMailOperation *self;
710 ModestMailOperationPrivate *priv;
712 helper = (XFerMsgAsyncHelper *) user_data;
713 self = helper->mail_op;
714 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
717 priv->error = g_error_copy (*err);
719 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
722 priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
726 g_object_unref (helper->headers);
727 g_object_unref (helper->dest_folder);
728 g_object_unref (folder);
731 /* Notify the queue */
732 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
736 modest_mail_operation_xfer_msg (ModestMailOperation *self,
739 gboolean delete_original)
741 ModestMailOperationPrivate *priv;
742 TnyFolder *src_folder;
744 XFerMsgAsyncHelper *helper;
746 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
747 g_return_if_fail (TNY_IS_HEADER (header));
748 g_return_if_fail (TNY_IS_FOLDER (folder));
750 /* Pick references for async calls */
751 g_object_ref (folder);
753 headers = tny_simple_list_new ();
754 tny_list_prepend (headers, G_OBJECT (header));
756 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
759 priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
761 /* Create the helper */
762 helper = g_malloc0 (sizeof (XFerMsgAsyncHelper));
763 helper->mail_op = self;
764 helper->dest_folder = folder;
765 helper->headers = headers;
767 src_folder = tny_header_get_folder (header);
768 tny_folder_transfer_msgs_async (src_folder,
777 on_refresh_folder (TnyFolder *folder,
782 ModestMailOperation *self;
783 ModestMailOperationPrivate *priv;
785 self = MODEST_MAIL_OPERATION (user_data);
786 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
789 priv->error = g_error_copy (*error);
790 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
795 priv->status = MODEST_MAIL_OPERATION_STATUS_CANCELED;
796 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
797 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
798 _("Error trying to refresh the contents of %s"),
799 tny_folder_get_name (folder));
803 priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
807 g_object_unref (folder);
809 /* Notify the queue */
810 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
814 /* on_refresh_folder_status_update (TnyFolder *folder, const gchar *msg, */
815 /* gint num, gint total, gpointer user_data) */
817 /* ModestMailOperation *self; */
818 /* ModestMailOperationPrivate *priv; */
820 /* self = MODEST_MAIL_OPERATION (user_data); */
821 /* priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self); */
823 /* priv->done = num; */
824 /* priv->total = total; */
826 /* if (num == 1 && total == 100) */
829 /* g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL); */
833 modest_mail_operation_refresh_folder (ModestMailOperation *self,
836 ModestMailOperationPrivate *priv;
838 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
840 /* Pick a reference */
841 g_object_ref (folder);
843 priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
845 /* Refresh the folder. TODO: tinymail could issue a status
846 updates before the callback call then this could happen. We
847 must review the design */
848 tny_folder_refresh_async (folder,
850 /* on_refresh_folder_status_update, */
856 _modest_mail_operation_notify_end (ModestMailOperation *self)
858 g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);