- ModestMailOperationPrivate *priv;
-
- g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
- g_return_if_fail (TNY_IS_HEADER (header));
-
- priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
- folder = tny_header_get_folder (header);
-
- priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
-
- /* Get message from folder */
- if (folder) {
- /* Get account and set it into mail_operation */
- priv->account = modest_tny_folder_get_account (TNY_FOLDER(folder));
-
- /* Check for cached messages */
- if (tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED)
- priv->op_type = MODEST_MAIL_OPERATION_TYPE_OPEN;
- else
- priv->op_type = MODEST_MAIL_OPERATION_TYPE_RECEIVE;
-
- helper = g_slice_new0 (GetMsgAsyncHelper);
- helper->mail_op = self;
- helper->user_callback = user_callback;
- helper->user_data = user_data;
- helper->header = g_object_ref (header);
-
- // The callback's reference so that the mail op is not
- // finalized until the async operation is completed even if
- // the user canceled the request meanwhile.
- g_object_ref (G_OBJECT (helper->mail_op));
-
- tny_folder_get_msg_async (folder, header, get_msg_cb, get_msg_status_cb, helper);
-
- g_object_unref (G_OBJECT (folder));
- } 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"));
-
- /* Notify the queue */
- modest_mail_operation_notify_end (self);
- }
-}
-
-static void
-get_msg_cb (TnyFolder *folder,
- gboolean cancelled,
- TnyMsg *msg,
- GError *error,
- gpointer user_data)
-{
- GetMsgAsyncHelper *helper = NULL;
- ModestMailOperation *self = NULL;
- ModestMailOperationPrivate *priv = NULL;
-
- helper = (GetMsgAsyncHelper *) user_data;
- g_return_if_fail (helper != NULL);
- self = helper->mail_op;
- g_return_if_fail (MODEST_IS_MAIL_OPERATION(self));
- priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
-
- /* Check errors and cancel */
- if (error) {
- priv->error = g_error_copy (error);
- priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
- } else if (cancelled) {
- priv->status = MODEST_MAIL_OPERATION_STATUS_CANCELED;
- g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
- MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
- _("Error trying to refresh the contents of %s"),
- tny_folder_get_name (folder));
- } else {
- priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
- }
-
- /* If user defined callback function was defined, call it even
- if the operation failed*/
- if (helper->user_callback) {
- /* This is not a GDK lock because we are a Tinymail callback
- * which is already GDK locked by Tinymail */
-
- /* no gdk_threads_enter (), CHECKED */
- helper->user_callback (self, helper->header, msg, helper->user_data);
- /* no gdk_threads_leave (), CHECKED */
- }
-
- /* Notify about operation end */
- modest_mail_operation_notify_end (self);
- /* Free */
- g_object_unref (helper->mail_op);
- g_object_unref (helper->header);
- g_slice_free (GetMsgAsyncHelper, helper);
-
-}
-
-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);
-
- priv->done = 1;
- priv->total = 1;
-
- state = modest_mail_operation_clone_state (self);
- state->bytes_done = status->position;
- state->bytes_total = status->of_total;
-
- /* This is not a GDK lock because we are a Tinymail callback
- * which is already GDK locked by Tinymail */
-
- /* no gdk_threads_enter (), CHECKED */
- g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, state, NULL);
- /* no gdk_threads_leave (), CHECKED */
-
- 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;