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 <tny-status.h>
42 #include <camel/camel-stream-mem.h>
43 #include <glib/gi18n.h>
44 #include "modest-platform.h"
45 #include <modest-tny-account.h>
46 #include <modest-tny-send-queue.h>
47 #include <modest-runtime.h>
48 #include "modest-text-utils.h"
49 #include "modest-tny-msg.h"
50 #include "modest-tny-folder.h"
51 #include "modest-tny-platform-factory.h"
52 #include "modest-marshal.h"
53 #include "modest-error.h"
55 /* 'private'/'protected' functions */
56 static void modest_mail_operation_class_init (ModestMailOperationClass *klass);
57 static void modest_mail_operation_init (ModestMailOperation *obj);
58 static void modest_mail_operation_finalize (GObject *obj);
60 /* static void update_process_msg_status_cb (GObject *obj, */
61 /* TnyStatus *status, */
62 /* gpointer user_data); */
63 static void get_msg_cb (TnyFolder *folder,
69 static void get_msg_status_cb (GObject *obj,
74 enum _ModestMailOperationSignals
76 PROGRESS_CHANGED_SIGNAL,
81 typedef struct _ModestMailOperationPrivate ModestMailOperationPrivate;
82 struct _ModestMailOperationPrivate {
85 ModestMailOperationStatus status;
86 ModestMailOperationId id;
88 ErrorCheckingUserCallback error_checking;
92 #define MODEST_MAIL_OPERATION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
93 MODEST_TYPE_MAIL_OPERATION, \
94 ModestMailOperationPrivate))
96 #define CHECK_EXCEPTION(priv, new_status) if (priv->error) {\
97 priv->status = new_status;\
100 typedef struct _GetMsgAsyncHelper {
101 ModestMailOperation *mail_op;
102 GetMsgAsynUserCallback user_callback;
107 typedef struct _XFerMsgAsyncHelper
109 ModestMailOperation *mail_op;
111 TnyFolder *dest_folder;
112 XferMsgsAsynUserCallback user_callback;
114 } XFerMsgAsyncHelper;
116 typedef struct _XFerFolderAsyncHelper
118 ModestMailOperation *mail_op;
120 } XFerFolderAsyncHelper;
123 static GObjectClass *parent_class = NULL;
125 static guint signals[NUM_SIGNALS] = {0};
128 modest_mail_operation_get_type (void)
130 static GType my_type = 0;
132 static const GTypeInfo my_info = {
133 sizeof(ModestMailOperationClass),
134 NULL, /* base init */
135 NULL, /* base finalize */
136 (GClassInitFunc) modest_mail_operation_class_init,
137 NULL, /* class finalize */
138 NULL, /* class data */
139 sizeof(ModestMailOperation),
141 (GInstanceInitFunc) modest_mail_operation_init,
144 my_type = g_type_register_static (G_TYPE_OBJECT,
145 "ModestMailOperation",
152 modest_mail_operation_class_init (ModestMailOperationClass *klass)
154 GObjectClass *gobject_class;
155 gobject_class = (GObjectClass*) klass;
157 parent_class = g_type_class_peek_parent (klass);
158 gobject_class->finalize = modest_mail_operation_finalize;
160 g_type_class_add_private (gobject_class, sizeof(ModestMailOperationPrivate));
163 * ModestMailOperation::progress-changed
164 * @self: the #MailOperation that emits the signal
165 * @user_data: user data set when the signal handler was connected
167 * Emitted when the progress of a mail operation changes
169 signals[PROGRESS_CHANGED_SIGNAL] =
170 g_signal_new ("progress-changed",
171 G_TYPE_FROM_CLASS (gobject_class),
173 G_STRUCT_OFFSET (ModestMailOperationClass, progress_changed),
175 g_cclosure_marshal_VOID__VOID,
180 modest_mail_operation_init (ModestMailOperation *obj)
182 ModestMailOperationPrivate *priv;
184 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(obj);
186 priv->status = MODEST_MAIL_OPERATION_STATUS_INVALID;
187 priv->id = MODEST_MAIL_OPERATION_ID_UNKNOWN;
195 modest_mail_operation_finalize (GObject *obj)
197 ModestMailOperationPrivate *priv;
199 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(obj);
202 g_error_free (priv->error);
206 g_object_unref (priv->source);
210 G_OBJECT_CLASS(parent_class)->finalize (obj);
214 modest_mail_operation_new (ModestMailOperationId id,
217 ModestMailOperation *obj;
218 ModestMailOperationPrivate *priv;
220 obj = MODEST_MAIL_OPERATION(g_object_new(MODEST_TYPE_MAIL_OPERATION, NULL));
221 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(obj);
225 priv->source = g_object_ref(source);
231 modest_mail_operation_new_with_error_handling (ModestMailOperationId id,
233 ErrorCheckingUserCallback error_handler)
235 ModestMailOperation *obj;
236 ModestMailOperationPrivate *priv;
238 obj = modest_mail_operation_new (id, source);
239 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(obj);
241 g_return_val_if_fail (error_handler != NULL, obj);
242 priv->error_checking = error_handler;
248 modest_mail_operation_execute_error_handler (ModestMailOperation *self)
250 ModestMailOperationPrivate *priv;
252 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
253 g_return_if_fail(priv->status != MODEST_MAIL_OPERATION_STATUS_SUCCESS);
255 if (priv->error_checking == NULL) return;
256 priv->error_checking (priv->source, self);
260 ModestMailOperationId
261 modest_mail_operation_get_id (ModestMailOperation *self)
263 ModestMailOperationPrivate *priv;
265 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
271 modest_mail_operation_is_mine (ModestMailOperation *self,
274 ModestMailOperationPrivate *priv;
276 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
277 if (priv->source == NULL) return FALSE;
279 return priv->source == me;
284 modest_mail_operation_send_mail (ModestMailOperation *self,
285 TnyTransportAccount *transport_account,
288 TnySendQueue *send_queue;
290 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
291 g_return_if_fail (TNY_IS_TRANSPORT_ACCOUNT (transport_account));
292 g_return_if_fail (TNY_IS_MSG (msg));
294 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
295 if (!TNY_IS_SEND_QUEUE(send_queue))
296 g_printerr ("modest: could not find send queue for account\n");
299 tny_send_queue_add (send_queue, msg, &err);
301 g_printerr ("modest: error adding msg to send queue: %s\n",
305 /* g_message ("modest: message added to send queue"); */
309 /* Notify the queue */
310 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
314 modest_mail_operation_send_new_mail (ModestMailOperation *self,
315 TnyTransportAccount *transport_account,
316 const gchar *from, const gchar *to,
317 const gchar *cc, const gchar *bcc,
318 const gchar *subject, const gchar *plain_body,
319 const gchar *html_body,
320 const GList *attachments_list,
321 TnyHeaderFlags priority_flags)
324 ModestMailOperationPrivate *priv = NULL;
325 /* GList *node = NULL; */
327 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
328 g_return_if_fail (TNY_IS_TRANSPORT_ACCOUNT (transport_account));
330 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
332 /* Check parametters */
334 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
335 MODEST_MAIL_OPERATION_ERROR_BAD_PARAMETER,
336 _("Error trying to send a mail. You need to set at least one recipient"));
340 if (html_body == NULL) {
341 new_msg = modest_tny_msg_new (to, from, cc, bcc, subject, plain_body, (GSList *) attachments_list); /* FIXME: attachments */
343 new_msg = modest_tny_msg_new_html_plain (to, from, cc, bcc, subject, html_body, plain_body, (GSList *) attachments_list);
346 g_printerr ("modest: failed to create a new msg\n");
350 /* TODO: add priority handling. It's received in the priority_flags operator, and
351 it should have effect in the sending operation */
353 /* Call mail operation */
354 modest_mail_operation_send_mail (self, transport_account, new_msg);
357 g_object_unref (G_OBJECT (new_msg));
361 modest_mail_operation_save_to_drafts (ModestMailOperation *self,
362 TnyTransportAccount *transport_account,
363 const gchar *from, const gchar *to,
364 const gchar *cc, const gchar *bcc,
365 const gchar *subject, const gchar *plain_body,
366 const gchar *html_body,
367 const GList *attachments_list,
368 TnyHeaderFlags priority_flags)
371 TnyFolder *folder = NULL;
372 ModestMailOperationPrivate *priv = NULL;
375 /* GList *node = NULL; */
377 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
378 g_return_if_fail (TNY_IS_TRANSPORT_ACCOUNT (transport_account));
380 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
382 if (html_body == NULL) {
383 msg = modest_tny_msg_new (to, from, cc, bcc, subject, plain_body, (GSList *) attachments_list); /* FIXME: attachments */
385 msg = modest_tny_msg_new_html_plain (to, from, cc, bcc, subject, html_body, plain_body, (GSList *) attachments_list);
388 g_printerr ("modest: failed to create a new msg\n");
392 folder = modest_tny_account_get_special_folder (TNY_ACCOUNT (transport_account), TNY_FOLDER_TYPE_DRAFTS);
394 g_printerr ("modest: failed to find Drafts folder\n");
398 tny_folder_add_msg (folder, msg, &err);
400 g_printerr ("modest: error adding msg to Drafts folder: %s",
406 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
411 g_object_unref (G_OBJECT(msg));
413 g_object_unref (G_OBJECT(folder));
418 ModestMailOperation *mail_op;
419 TnyStoreAccount *account;
420 TnyTransportAccount *transport_account;
424 recurse_folders (TnyFolderStore *store, TnyFolderStoreQuery *query, TnyList *all_folders)
427 TnyList *folders = tny_simple_list_new ();
429 tny_folder_store_get_folders (store, folders, query, NULL);
430 iter = tny_list_create_iterator (folders);
432 while (!tny_iterator_is_done (iter)) {
434 TnyFolderStore *folder = (TnyFolderStore*) tny_iterator_get_current (iter);
436 tny_list_prepend (all_folders, G_OBJECT (folder));
437 recurse_folders (folder, query, all_folders);
438 g_object_unref (G_OBJECT (folder));
440 tny_iterator_next (iter);
442 g_object_unref (G_OBJECT (iter));
443 g_object_unref (G_OBJECT (folders));
447 * Used by update_account_thread to emit the "progress-changed" signal
448 * from the main loop. We call it inside an idle call to achieve that
451 notify_update_account_observers (gpointer data)
453 ModestMailOperation *mail_op = MODEST_MAIL_OPERATION (data);
455 g_signal_emit (G_OBJECT (mail_op), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
461 * Used by update_account_thread to notify the queue from the main
462 * loop. We call it inside an idle call to achieve that
465 notify_update_account_queue (gpointer data)
467 ModestMailOperation *mail_op = MODEST_MAIL_OPERATION (data);
469 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (),
471 g_object_unref (mail_op);
477 update_account_thread (gpointer thr_user_data)
479 UpdateAccountInfo *info;
480 TnyList *all_folders = NULL;
481 TnyIterator *iter = NULL;
482 TnyFolderStoreQuery *query = NULL;
483 ModestMailOperationPrivate *priv;
484 ModestTnySendQueue *send_queue;
487 info = (UpdateAccountInfo *) thr_user_data;
488 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(info->mail_op);
490 /* Get all the folders We can do it synchronously because
491 we're already running in a different thread than the UI */
492 all_folders = tny_simple_list_new ();
493 query = tny_folder_store_query_new ();
494 tny_folder_store_query_add_item (query, NULL, TNY_FOLDER_STORE_QUERY_OPTION_SUBSCRIBED);
495 tny_folder_store_get_folders (TNY_FOLDER_STORE (info->account),
500 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
504 iter = tny_list_create_iterator (all_folders);
505 while (!tny_iterator_is_done (iter)) {
506 TnyFolderStore *folder = TNY_FOLDER_STORE (tny_iterator_get_current (iter));
508 recurse_folders (folder, query, all_folders);
509 tny_iterator_next (iter);
511 g_object_unref (G_OBJECT (iter));
513 /* Update status and notify. We need to call the notification
514 with a source functopm in order to call it from the main
515 loop. We need that in order not to get into trouble with
516 Gtk+. We use a timeout in order to provide more status
517 information, because the sync tinymail call does not
518 provide it for the moment */
519 timeout = g_timeout_add (250, notify_update_account_observers, info->mail_op);
521 /* Refresh folders */
522 iter = tny_list_create_iterator (all_folders);
523 while (!tny_iterator_is_done (iter) && !priv->error) {
525 TnyFolderStore *folder = TNY_FOLDER_STORE (tny_iterator_get_current (iter));
527 /* Refresh the folder */
528 tny_folder_refresh (TNY_FOLDER (folder), &(priv->error));
530 /* TODO: Apply retrieval types */
532 /* TODO: apply per-message size limits */
534 /* TODO: apply message count limit */
537 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
540 g_object_unref (G_OBJECT (folder));
541 tny_iterator_next (iter);
543 g_object_unref (G_OBJECT (iter));
544 g_source_remove (timeout);
547 priv->id = MODEST_MAIL_OPERATION_ID_SEND;
549 send_queue = modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(info->transport_account));
551 timeout = g_timeout_add (250, notify_update_account_observers, info->mail_op);
552 modest_tny_send_queue_flush (send_queue);
553 g_source_remove (timeout);
555 g_object_unref (G_OBJECT(send_queue));
557 /* Check if the operation was a success */
559 priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
561 /* Update the last updated key */
562 modest_account_mgr_set_int (modest_runtime_get_account_mgr (),
563 tny_account_get_id (TNY_ACCOUNT (info->account)),
564 MODEST_ACCOUNT_LAST_UPDATED,
570 /* Notify the queue. Note that the info could be freed before
571 this idle happens, but the mail operation will be still
573 g_idle_add (notify_update_account_queue, info->mail_op);
576 g_object_unref (query);
577 g_object_unref (all_folders);
578 g_object_unref (info->account);
579 g_object_unref (info->transport_account);
580 g_slice_free (UpdateAccountInfo, info);
586 modest_mail_operation_update_account (ModestMailOperation *self,
587 const gchar *account_name)
590 UpdateAccountInfo *info;
591 ModestMailOperationPrivate *priv;
592 TnyStoreAccount *modest_account;
593 TnyTransportAccount *transport_account;
595 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), FALSE);
596 g_return_val_if_fail (account_name, FALSE);
598 /* Init mail operation. Set total and done to 0, and do not
599 update them, this way the progress objects will know that
600 we have no clue about the number of the objects */
601 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
604 priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
606 /* Get the Modest account */
607 modest_account = (TnyStoreAccount *)
608 modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store (),
610 TNY_ACCOUNT_TYPE_STORE);
612 if (!modest_account) {
613 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
614 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
615 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
616 "cannot get tny store account for %s\n", account_name);
617 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (),
622 /* Get the transport account, we can not do it in the thread
623 due to some problems with dbus */
624 transport_account = (TnyTransportAccount *)
625 modest_tny_account_store_get_transport_account_for_open_connection (modest_runtime_get_account_store(),
627 if (!transport_account) {
628 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
629 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
630 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
631 "cannot get tny transport account for %s\n", account_name);
632 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (),
637 /* Create the helper object */
638 info = g_slice_new (UpdateAccountInfo);
639 info->mail_op = self;
640 info->account = modest_account;
641 info->transport_account = transport_account;
643 thread = g_thread_create (update_account_thread, info, FALSE, NULL);
648 ModestMailOperationStatus
649 modest_mail_operation_get_status (ModestMailOperation *self)
651 ModestMailOperationPrivate *priv;
653 g_return_val_if_fail (self, MODEST_MAIL_OPERATION_STATUS_INVALID);
654 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self),
655 MODEST_MAIL_OPERATION_STATUS_INVALID);
657 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
662 modest_mail_operation_get_error (ModestMailOperation *self)
664 ModestMailOperationPrivate *priv;
666 g_return_val_if_fail (self, NULL);
667 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), NULL);
669 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
674 modest_mail_operation_cancel (ModestMailOperation *self)
676 ModestMailOperationPrivate *priv;
678 if (!MODEST_IS_MAIL_OPERATION (self)) {
679 g_warning ("%s: invalid parametter", G_GNUC_FUNCTION);
683 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
685 /* TODO: Tinymail does not support cancel operation */
688 priv->status = MODEST_MAIL_OPERATION_STATUS_CANCELED;
690 /* Notify the queue */
691 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
697 modest_mail_operation_get_task_done (ModestMailOperation *self)
699 ModestMailOperationPrivate *priv;
701 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), 0);
703 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
708 modest_mail_operation_get_task_total (ModestMailOperation *self)
710 ModestMailOperationPrivate *priv;
712 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), 0);
714 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
719 modest_mail_operation_is_finished (ModestMailOperation *self)
721 ModestMailOperationPrivate *priv;
722 gboolean retval = FALSE;
724 if (!MODEST_IS_MAIL_OPERATION (self)) {
725 g_warning ("%s: invalid parametter", G_GNUC_FUNCTION);
729 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
731 if (priv->status == MODEST_MAIL_OPERATION_STATUS_SUCCESS ||
732 priv->status == MODEST_MAIL_OPERATION_STATUS_FAILED ||
733 priv->status == MODEST_MAIL_OPERATION_STATUS_CANCELED ||
734 priv->status == MODEST_MAIL_OPERATION_STATUS_FINISHED_WITH_ERRORS) {
743 /* ******************************************************************* */
744 /* ************************** STORE ACTIONS ************************* */
745 /* ******************************************************************* */
749 modest_mail_operation_create_folder (ModestMailOperation *self,
750 TnyFolderStore *parent,
753 ModestTnyFolderRules rules;
754 ModestMailOperationPrivate *priv;
755 TnyFolder *new_folder = NULL;
756 gboolean can_create = FALSE;
758 g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent), NULL);
759 g_return_val_if_fail (name, NULL);
761 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
764 if (!TNY_IS_FOLDER (parent)) {
765 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
766 MODEST_MAIL_OPERATION_ERROR_BAD_PARAMETER,
767 _("mail_in_ui_folder_create_error"));
769 /* Check folder rules */
770 rules = modest_tny_folder_get_rules (TNY_FOLDER (parent));
771 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE)
772 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
773 MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
774 _("mail_in_ui_folder_create_error"));
780 /* Create the folder */
781 new_folder = tny_folder_store_create_folder (parent, name, &(priv->error));
782 CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED);
785 /* Notify the queue */
786 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
792 modest_mail_operation_remove_folder (ModestMailOperation *self,
794 gboolean remove_to_trash)
797 ModestMailOperationPrivate *priv;
798 ModestTnyFolderRules rules;
800 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
801 g_return_if_fail (TNY_IS_FOLDER (folder));
803 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
805 /* Check folder rules */
806 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder));
807 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_DELETABLE) {
808 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
809 MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
810 _("mail_in_ui_folder_delete_error"));
814 /* Get the account */
815 account = tny_folder_get_account (folder);
817 /* Delete folder or move to trash */
818 if (remove_to_trash) {
819 TnyFolder *trash_folder = NULL;
820 /* TnyFolder *trash_folder, *new_folder; */
821 trash_folder = modest_tny_account_get_special_folder (account,
822 TNY_FOLDER_TYPE_TRASH);
823 /* TODO: error_handling */
824 modest_mail_operation_xfer_folder (self, folder,
825 TNY_FOLDER_STORE (trash_folder), TRUE);
826 /* new_folder = modest_mail_operation_xfer_folder (self, folder, */
827 /* TNY_FOLDER_STORE (trash_folder), TRUE); */
828 /* g_object_unref (G_OBJECT (new_folder)); */
830 TnyFolderStore *parent = tny_folder_get_folder_store (folder);
832 tny_folder_store_remove_folder (parent, folder, &(priv->error));
833 CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED);
836 g_object_unref (G_OBJECT (parent));
838 g_object_unref (G_OBJECT (account));
841 /* Notify the queue */
842 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
846 modest_mail_operation_rename_folder (ModestMailOperation *self,
850 ModestMailOperationPrivate *priv;
851 ModestTnyFolderRules rules;
853 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
854 g_return_if_fail (TNY_IS_FOLDER_STORE (folder));
855 g_return_if_fail (name);
857 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
859 /* Check folder rules */
860 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder));
861 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_RENAMEABLE) {
862 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
863 MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
864 _("FIXME: unable to rename"));
866 /* Rename. Camel handles folder subscription/unsubscription */
867 TnyFolderStore *into;
870 into = tny_folder_get_folder_store (folder);
871 nfol = tny_folder_copy (folder, into, name, TRUE, &(priv->error));
873 g_object_unref (into);
875 g_object_unref (nfol);
877 CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED);
881 /* Notify the queue */
882 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
886 transfer_folder_status_cb (GObject *obj,
890 XFerMsgAsyncHelper *helper = NULL;
891 ModestMailOperation *self;
892 ModestMailOperationPrivate *priv;
894 g_return_if_fail (status != NULL);
895 g_return_if_fail (status->code == TNY_FOLDER_STATUS_CODE_COPY_FOLDER);
897 helper = (XFerMsgAsyncHelper *) user_data;
898 g_return_if_fail (helper != NULL);
900 /* Temporary FIX: useful when tinymail send us status
901 information *after* calling the function callback */
902 if (!MODEST_IS_MAIL_OPERATION (helper->mail_op))
905 self = helper->mail_op;
906 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
908 if ((status->position == 1) && (status->of_total == 100))
911 priv->done = status->position;
912 priv->total = status->of_total;
915 g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
920 transfer_folder_cb (TnyFolder *folder, TnyFolderStore *into, gboolean cancelled, TnyFolder *new_folder, GError **err, gpointer user_data)
922 XFerFolderAsyncHelper *helper = NULL;
923 ModestMailOperation *self = NULL;
924 ModestMailOperationPrivate *priv = NULL;
926 helper = (XFerFolderAsyncHelper *) user_data;
927 self = helper->mail_op;
929 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
932 priv->error = g_error_copy (*err);
934 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
935 } else if (cancelled) {
936 priv->status = MODEST_MAIL_OPERATION_STATUS_CANCELED;
937 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
938 MODEST_MAIL_OPERATION_ERROR_OPERATION_CANCELED,
939 _("Transference of %s was cancelled."),
940 tny_folder_get_name (folder));
943 priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
947 g_slice_free (XFerFolderAsyncHelper, helper);
948 g_object_unref (folder);
949 g_object_unref (into);
950 if (new_folder != NULL)
951 g_object_unref (new_folder);
953 /* Notify the queue */
954 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
958 modest_mail_operation_xfer_folder (ModestMailOperation *self,
960 TnyFolderStore *parent,
961 gboolean delete_original)
963 ModestMailOperationPrivate *priv;
964 TnyFolder *new_folder = NULL;
965 ModestTnyFolderRules rules;
967 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), NULL);
968 g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent), NULL);
969 g_return_val_if_fail (TNY_IS_FOLDER (folder), NULL);
971 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
973 /* The moveable restriction is applied also to copy operation */
974 rules = modest_tny_folder_get_rules (TNY_FOLDER (parent));
975 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_MOVEABLE) {
976 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
977 MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
978 _("FIXME: unable to rename"));
980 /* Move/Copy folder */
981 new_folder = tny_folder_copy (folder,
983 tny_folder_get_name (folder),
988 /* Notify the queue */
989 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
995 modest_mail_operation_xfer_folder_async (ModestMailOperation *self,
997 TnyFolderStore *parent,
998 gboolean delete_original)
1000 XFerFolderAsyncHelper *helper = NULL;
1001 ModestMailOperationPrivate *priv = NULL;
1002 ModestTnyFolderRules rules;
1004 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
1005 g_return_if_fail (TNY_IS_FOLDER_STORE (parent));
1006 g_return_if_fail (TNY_IS_FOLDER (folder));
1008 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
1010 /* Pick references for async calls */
1011 g_object_ref (folder);
1012 g_object_ref (parent);
1014 /* The moveable restriction is applied also to copy operation */
1015 rules = modest_tny_folder_get_rules (TNY_FOLDER (parent));
1016 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_MOVEABLE) {
1017 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
1018 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
1019 MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES,
1020 _("FIXME: unable to rename"));
1022 helper = g_slice_new0 (XFerFolderAsyncHelper);
1023 helper->mail_op = self;
1025 /* Move/Copy folder */
1026 tny_folder_copy_async (folder,
1028 tny_folder_get_name (folder),
1031 transfer_folder_status_cb,
1037 /* ******************************************************************* */
1038 /* ************************** MSG ACTIONS ************************* */
1039 /* ******************************************************************* */
1041 void modest_mail_operation_get_msg (ModestMailOperation *self,
1043 GetMsgAsynUserCallback user_callback,
1046 GetMsgAsyncHelper *helper = NULL;
1048 ModestMailOperationPrivate *priv;
1050 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
1051 g_return_if_fail (TNY_IS_HEADER (header));
1053 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
1054 folder = tny_header_get_folder (header);
1056 priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
1058 /* Get message from folder */
1060 helper = g_slice_new0 (GetMsgAsyncHelper);
1061 helper->mail_op = self;
1062 helper->user_callback = user_callback;
1063 helper->pending_ops = 1;
1064 helper->user_data = user_data;
1066 tny_folder_get_msg_async (folder, header, get_msg_cb, get_msg_status_cb, helper);
1068 g_object_unref (G_OBJECT (folder));
1070 /* Set status failed and set an error */
1071 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
1072 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
1073 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
1074 _("Error trying to get a message. No folder found for header"));
1079 get_msg_cb (TnyFolder *folder,
1085 GetMsgAsyncHelper *helper = NULL;
1086 ModestMailOperation *self = NULL;
1087 ModestMailOperationPrivate *priv = NULL;
1089 helper = (GetMsgAsyncHelper *) user_data;
1090 g_return_if_fail (helper != NULL);
1091 self = helper->mail_op;
1092 g_return_if_fail (MODEST_IS_MAIL_OPERATION(self));
1093 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
1095 helper->pending_ops--;
1097 /* Check errors and cancel */
1099 priv->error = g_error_copy (*error);
1100 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
1104 priv->status = MODEST_MAIL_OPERATION_STATUS_CANCELED;
1105 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
1106 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
1107 _("Error trying to refresh the contents of %s"),
1108 tny_folder_get_name (folder));
1112 priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
1114 /* If user defined callback function was defined, call it */
1115 if (helper->user_callback) {
1116 helper->user_callback (priv->source, msg, helper->user_data);
1121 if (helper->pending_ops == 0) {
1122 g_slice_free (GetMsgAsyncHelper, helper);
1124 /* Notify the queue */
1125 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
1130 get_msg_status_cb (GObject *obj,
1134 GetMsgAsyncHelper *helper = NULL;
1135 ModestMailOperation *self;
1136 ModestMailOperationPrivate *priv;
1138 g_return_if_fail (status != NULL);
1139 g_return_if_fail (status->code == TNY_FOLDER_STATUS_CODE_GET_MSG);
1141 helper = (GetMsgAsyncHelper *) user_data;
1142 g_return_if_fail (helper != NULL);
1144 /* Temporary FIX: useful when tinymail send us status
1145 information *after* calling the function callback */
1146 if (!MODEST_IS_MAIL_OPERATION (helper->mail_op))
1149 self = helper->mail_op;
1150 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
1152 if ((status->position == 1) && (status->of_total == 100))
1158 g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
1161 /****************************************************/
1163 ModestMailOperation *mail_op;
1165 GetMsgAsynUserCallback user_callback;
1167 GDestroyNotify notify;
1171 * Used by get_msgs_full_thread to emit the "progress-changed" signal
1172 * from the main loop. We call it inside an idle call to achieve that
1175 notify_get_msgs_full_observers (gpointer data)
1177 ModestMailOperation *mail_op = MODEST_MAIL_OPERATION (data);
1179 g_signal_emit (G_OBJECT (mail_op), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
1181 g_object_unref (mail_op);
1187 GetMsgAsynUserCallback user_callback;
1191 } NotifyGetMsgsInfo;
1195 * Used by get_msgs_full_thread to call the user_callback for each
1196 * message that has been read
1199 notify_get_msgs_full (gpointer data)
1201 NotifyGetMsgsInfo *info;
1203 info = (NotifyGetMsgsInfo *) data;
1205 /* Call the user callback */
1206 info->user_callback (info->source, info->msg, info->user_data);
1208 g_slice_free (NotifyGetMsgsInfo, info);
1214 * Used by get_msgs_full_thread to free al the thread resources and to
1215 * call the destroy function for the passed user_data
1218 get_msgs_full_destroyer (gpointer data)
1220 GetFullMsgsInfo *info;
1222 info = (GetFullMsgsInfo *) data;
1225 info->notify (info->user_data);
1228 g_object_unref (info->headers);
1229 g_slice_free (GetFullMsgsInfo, info);
1235 get_msgs_full_thread (gpointer thr_user_data)
1237 GetFullMsgsInfo *info;
1238 ModestMailOperationPrivate *priv = NULL;
1239 TnyIterator *iter = NULL;
1241 info = (GetFullMsgsInfo *) thr_user_data;
1242 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (info->mail_op);
1244 iter = tny_list_create_iterator (info->headers);
1245 while (!tny_iterator_is_done (iter)) {
1249 header = TNY_HEADER (tny_iterator_get_current (iter));
1250 folder = tny_header_get_folder (header);
1252 /* Get message from folder */
1255 /* The callback will call it per each header */
1256 msg = tny_folder_get_msg (folder, header, &(priv->error));
1261 /* notify progress */
1262 g_idle_add_full (G_PRIORITY_HIGH_IDLE,
1263 notify_get_msgs_full_observers,
1264 g_object_ref (info->mail_op), NULL);
1266 /* The callback is the responsible for
1267 freeing the message */
1268 if (info->user_callback) {
1269 NotifyGetMsgsInfo *info_notify;
1270 info_notify = g_slice_new0 (NotifyGetMsgsInfo);
1271 info_notify->user_callback = info->user_callback;
1272 info_notify->source = priv->source;
1273 info_notify->msg = msg;
1274 info_notify->user_data = info->user_data;
1275 g_idle_add_full (G_PRIORITY_HIGH_IDLE,
1276 notify_get_msgs_full,
1279 g_object_unref (msg);
1283 /* Set status failed and set an error */
1284 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
1285 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
1286 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
1287 "Error trying to get a message. No folder found for header");
1289 g_object_unref (header);
1290 tny_iterator_next (iter);
1293 /* Notify the queue */
1294 g_idle_add (notify_update_account_queue, info->mail_op);
1296 /* Free thread resources. Will be called after all previous idles */
1297 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE + 1, get_msgs_full_destroyer, info, NULL);
1303 modest_mail_operation_get_msgs_full (ModestMailOperation *self,
1304 TnyList *header_list,
1305 GetMsgAsynUserCallback user_callback,
1307 GDestroyNotify notify)
1310 ModestMailOperationPrivate *priv = NULL;
1311 GetFullMsgsInfo *info = NULL;
1312 gboolean size_ok = TRUE;
1314 GError *error = NULL;
1315 const gint KB = 1024;
1317 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
1319 /* Init mail operation */
1320 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
1321 priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
1323 priv->total = tny_list_get_length(header_list);
1325 /* Get msg size limit */
1326 max_size = modest_conf_get_int (modest_runtime_get_conf (),
1327 MODEST_CONF_MSG_SIZE_LIMIT,
1330 g_clear_error (&error);
1331 max_size = G_MAXINT;
1333 max_size = max_size * KB;
1336 /* Check message size limits. If there is only one message
1337 always retrieve it */
1338 if (tny_list_get_length (header_list) > 1) {
1341 iter = tny_list_create_iterator (header_list);
1342 while (!tny_iterator_is_done (iter) && size_ok) {
1343 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1344 if (tny_header_get_message_size (header) >= max_size)
1346 g_object_unref (header);
1347 tny_iterator_next (iter);
1349 g_object_unref (iter);
1353 /* Create the info */
1354 info = g_slice_new0 (GetFullMsgsInfo);
1355 info->mail_op = self;
1356 info->user_callback = user_callback;
1357 info->user_data = user_data;
1358 info->headers = g_object_ref (header_list);
1359 info->notify = notify;
1361 thread = g_thread_create (get_msgs_full_thread, info, FALSE, NULL);
1363 /* FIXME: the error msg is different for pop */
1364 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
1365 MODEST_MAIL_OPERATION_ERROR_BAD_PARAMETER,
1366 _("emev_ni_ui_imap_msg_sizelimit_error"));
1367 /* Remove from queue and free resources */
1368 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
1376 modest_mail_operation_remove_msg (ModestMailOperation *self,
1378 gboolean remove_to_trash)
1381 ModestMailOperationPrivate *priv;
1383 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
1384 g_return_if_fail (TNY_IS_HEADER (header));
1386 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
1387 folder = tny_header_get_folder (header);
1389 priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
1391 /* Delete or move to trash */
1392 if (remove_to_trash) {
1393 TnyFolder *trash_folder;
1394 TnyStoreAccount *store_account;
1396 store_account = TNY_STORE_ACCOUNT (tny_folder_get_account (folder));
1397 trash_folder = modest_tny_account_get_special_folder (TNY_ACCOUNT(store_account),
1398 TNY_FOLDER_TYPE_TRASH);
1403 headers = tny_simple_list_new ();
1404 tny_list_append (headers, G_OBJECT (header));
1405 g_object_unref (header);
1408 modest_mail_operation_xfer_msgs (self, headers, trash_folder, TRUE, NULL, NULL);
1409 g_object_unref (headers);
1410 /* g_object_unref (trash_folder); */
1412 ModestMailOperationPrivate *priv;
1414 /* Set status failed and set an error */
1415 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
1416 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
1417 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
1418 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
1419 _("Error trying to delete a message. Trash folder not found"));
1422 g_object_unref (G_OBJECT (store_account));
1424 tny_folder_remove_msg (folder, header, &(priv->error));
1426 tny_folder_sync(folder, TRUE, &(priv->error));
1431 priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
1433 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
1436 g_object_unref (G_OBJECT (folder));
1438 /* Notify the queue */
1439 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
1443 transfer_msgs_status_cb (GObject *obj,
1447 XFerMsgAsyncHelper *helper = NULL;
1448 ModestMailOperation *self;
1449 ModestMailOperationPrivate *priv;
1451 g_return_if_fail (status != NULL);
1452 g_return_if_fail (status->code == TNY_FOLDER_STATUS_CODE_XFER_MSGS);
1454 helper = (XFerMsgAsyncHelper *) user_data;
1455 g_return_if_fail (helper != NULL);
1457 /* Temporary FIX: useful when tinymail send us status
1458 information *after* calling the function callback */
1459 if (!MODEST_IS_MAIL_OPERATION (helper->mail_op))
1462 self = helper->mail_op;
1463 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
1465 if ((status->position == 1) && (status->of_total == 100))
1468 priv->done = status->position;
1469 priv->total = status->of_total;
1471 g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
1476 transfer_msgs_cb (TnyFolder *folder, gboolean cancelled, GError **err, gpointer user_data)
1478 XFerMsgAsyncHelper *helper;
1479 ModestMailOperation *self;
1480 ModestMailOperationPrivate *priv;
1482 helper = (XFerMsgAsyncHelper *) user_data;
1483 self = helper->mail_op;
1485 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
1488 priv->error = g_error_copy (*err);
1490 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
1491 } else if (cancelled) {
1492 priv->status = MODEST_MAIL_OPERATION_STATUS_CANCELED;
1493 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
1494 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
1495 _("Error trying to refresh the contents of %s"),
1496 tny_folder_get_name (folder));
1499 priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
1502 /* If user defined callback function was defined, call it */
1503 if (helper->user_callback) {
1504 helper->user_callback (priv->source, helper->user_data);
1508 g_object_unref (helper->headers);
1509 g_object_unref (helper->dest_folder);
1510 g_object_unref (helper->mail_op);
1511 g_slice_free (XFerMsgAsyncHelper, helper);
1512 g_object_unref (folder);
1514 /* Notify the queue */
1515 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
1519 modest_mail_operation_xfer_msgs (ModestMailOperation *self,
1522 gboolean delete_original,
1523 XferMsgsAsynUserCallback user_callback,
1526 ModestMailOperationPrivate *priv;
1528 TnyFolder *src_folder;
1529 XFerMsgAsyncHelper *helper;
1532 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
1533 g_return_if_fail (TNY_IS_LIST (headers));
1534 g_return_if_fail (TNY_IS_FOLDER (folder));
1536 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
1539 priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
1541 /* Create the helper */
1542 helper = g_slice_new0 (XFerMsgAsyncHelper);
1543 helper->mail_op = g_object_ref(self);
1544 helper->dest_folder = g_object_ref(folder);
1545 helper->headers = g_object_ref(headers);
1546 helper->user_callback = user_callback;
1547 helper->user_data = user_data;
1549 /* Get source folder */
1550 iter = tny_list_create_iterator (headers);
1551 header = TNY_HEADER (tny_iterator_get_current (iter));
1552 src_folder = tny_header_get_folder (header);
1553 g_object_unref (header);
1554 g_object_unref (iter);
1556 /* Transfer messages */
1557 tny_folder_transfer_msgs_async (src_folder,
1562 transfer_msgs_status_cb,
1568 on_refresh_folder (TnyFolder *folder,
1573 ModestMailOperation *self;
1574 ModestMailOperationPrivate *priv;
1576 self = MODEST_MAIL_OPERATION (user_data);
1577 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
1580 priv->error = g_error_copy (*error);
1581 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
1586 priv->status = MODEST_MAIL_OPERATION_STATUS_CANCELED;
1587 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
1588 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
1589 _("Error trying to refresh the contents of %s"),
1590 tny_folder_get_name (folder));
1594 priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
1598 g_object_unref (folder);
1600 /* Notify the queue */
1601 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);
1605 on_refresh_folder_status_update (GObject *obj,
1609 ModestMailOperation *self;
1610 ModestMailOperationPrivate *priv;
1612 g_return_if_fail (status != NULL);
1613 g_return_if_fail (status->code == TNY_FOLDER_STATUS_CODE_REFRESH);
1615 /* Temporary FIX: useful when tinymail send us status
1616 information *after* calling the function callback */
1617 if (!MODEST_IS_MAIL_OPERATION (user_data))
1620 self = MODEST_MAIL_OPERATION (user_data);
1621 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
1623 priv->done = status->position;
1624 priv->total = status->of_total;
1626 g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
1630 modest_mail_operation_refresh_folder (ModestMailOperation *self,
1633 ModestMailOperationPrivate *priv;
1635 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
1637 /* Pick a reference */
1638 g_object_ref (folder);
1640 priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
1642 /* Refresh the folder. TODO: tinymail could issue a status
1643 updates before the callback call then this could happen. We
1644 must review the design */
1645 tny_folder_refresh_async (folder,
1647 on_refresh_folder_status_update,
1652 _modest_mail_operation_notify_end (ModestMailOperation *self)
1654 g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);