-static void
-get_msg_status_cb (GObject *obj,
- TnyStatus *status,
- gpointer user_data)
-{
- GetMsgAsyncHelper *helper = NULL;
- ModestMailOperation *self;
- ModestMailOperationPrivate *priv;
- ModestMailOperationState *state;
-
- g_return_if_fail (status != NULL);
- g_return_if_fail (status->code == TNY_FOLDER_STATUS_CODE_GET_MSG);
-
- helper = (GetMsgAsyncHelper *) user_data;
- g_return_if_fail (helper != NULL);
-
- self = helper->mail_op;
- priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
-
- if(priv->status == MODEST_MAIL_OPERATION_STATUS_CANCELED) {
- TnyFolder *folder = tny_header_get_folder (helper->header);
- if (folder) {
- TnyAccount *account;
- account = tny_folder_get_account (folder);
- if (account) {
- tny_account_cancel (account);
- g_object_unref (account);
- }
- g_object_unref (folder);
- }
-
- return;
- }
-
- priv->done = 1;
- priv->total = 1;
-
- state = modest_mail_operation_clone_state (self);
- state->bytes_done = status->position;
- state->bytes_total = status->of_total;
- g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, state, NULL);
- g_slice_free (ModestMailOperationState, state);
-}
-
-/****************************************************/
-typedef struct {
- ModestMailOperation *mail_op;
- TnyList *headers;
- GetMsgAsyncUserCallback user_callback;
- gpointer user_data;
- GDestroyNotify notify;
-} GetFullMsgsInfo;
-
-typedef struct {
- GetMsgAsyncUserCallback user_callback;
- TnyHeader *header;
- TnyMsg *msg;
- gpointer user_data;
- ModestMailOperation *mail_op;
-} NotifyGetMsgsInfo;
-
-
-/*
- * Used by get_msgs_full_thread to call the user_callback for each
- * message that has been read
- */
-static gboolean
-notify_get_msgs_full (gpointer data)
-{
- NotifyGetMsgsInfo *info;
-
- info = (NotifyGetMsgsInfo *) data;
-
- /* Call the user callback. Idles are not in the main lock, so
- lock it */
- gdk_threads_enter ();
- info->user_callback (info->mail_op, info->header, info->msg, info->user_data);
- gdk_threads_leave ();
-
- g_slice_free (NotifyGetMsgsInfo, info);
-
- return FALSE;
-}
-
-/*
- * Used by get_msgs_full_thread to free al the thread resources and to
- * call the destroy function for the passed user_data
- */
-static gboolean
-get_msgs_full_destroyer (gpointer data)
-{
- GetFullMsgsInfo *info;
-
- info = (GetFullMsgsInfo *) data;
-
- if (info->notify) {
- gdk_threads_enter ();
- info->notify (info->user_data);
- gdk_threads_leave ();
- }
-
- /* free */
- g_object_unref (info->headers);
- g_slice_free (GetFullMsgsInfo, info);
-
- return FALSE;
-}
-
-static gpointer
-get_msgs_full_thread (gpointer thr_user_data)
-{
- GetFullMsgsInfo *info;
- ModestMailOperationPrivate *priv = NULL;
- TnyIterator *iter = NULL;
-
- info = (GetFullMsgsInfo *) thr_user_data;
- priv = MODEST_MAIL_OPERATION_GET_PRIVATE (info->mail_op);
-
- iter = tny_list_create_iterator (info->headers);
- while (!tny_iterator_is_done (iter)) {
- TnyHeader *header;
- TnyFolder *folder;
-
- header = TNY_HEADER (tny_iterator_get_current (iter));
- folder = tny_header_get_folder (header);
-
- /* Get message from folder */
- if (folder) {
- TnyMsg *msg;
- /* The callback will call it per each header */
- msg = tny_folder_get_msg (folder, header, &(priv->error));
-
- if (msg) {
- ModestMailOperationState *state;
- ModestPair *pair;
-
- priv->done++;
-
- /* notify progress */
- state = modest_mail_operation_clone_state (info->mail_op);
- pair = modest_pair_new (g_object_ref (info->mail_op), state, FALSE);
- g_idle_add_full (G_PRIORITY_HIGH_IDLE, idle_notify_progress_once,
- pair, (GDestroyNotify) modest_pair_free);
-
- /* The callback is the responsible for
- freeing the message */
- if (info->user_callback) {
- NotifyGetMsgsInfo *info_notify;
- info_notify = g_slice_new0 (NotifyGetMsgsInfo);
- info_notify->user_callback = info->user_callback;
- info_notify->mail_op = info->mail_op;
- info_notify->header = g_object_ref (header);
- info_notify->msg = g_object_ref (msg);
- info_notify->user_data = info->user_data;
- g_idle_add_full (G_PRIORITY_HIGH_IDLE,
- notify_get_msgs_full,
- info_notify, NULL);
- }
- g_object_unref (msg);
- }
- } else {
- /* Set status failed and set an error */
- priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
- g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
- MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
- "Error trying to get a message. No folder found for header");
- }
- g_object_unref (header);
- tny_iterator_next (iter);
- }
-
- /* Set operation status */
- if (priv->status == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
- priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
-
- /* Notify about operation end */
- g_idle_add (idle_notify_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);
-
- return NULL;
-}
-
-void
-modest_mail_operation_get_msgs_full (ModestMailOperation *self,
- TnyList *header_list,
- GetMsgAsyncUserCallback user_callback,
- gpointer user_data,
- GDestroyNotify notify)
-{
- TnyHeader *header = NULL;
- TnyFolder *folder = NULL;
- GThread *thread;
- ModestMailOperationPrivate *priv = NULL;
- GetFullMsgsInfo *info = NULL;
- gboolean size_ok = TRUE;
- gint max_size;
- TnyIterator *iter = NULL;
-
- g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
-
- /* Init mail operation */
- priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
- priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
- priv->done = 0;
- priv->total = tny_list_get_length(header_list);
-
- /* Get account and set it into mail_operation */
- if (tny_list_get_length (header_list) >= 1) {