- g_object_unref (G_OBJECT (iter));
- g_source_remove (timeout);
-
- if (priv->status != MODEST_MAIL_OPERATION_STATUS_CANCELED &&
- priv->status != MODEST_MAIL_OPERATION_STATUS_FAILED &&
- new_headers_array->len > 0) {
- gint msg_num = 0;
-
- /* Order by date */
- g_ptr_array_sort (new_headers_array, (GCompareFunc) compare_headers_by_date);
-
- /* TODO: Ask the user, instead of just failing,
- * showing mail_nc_msg_count_limit_exceeded, with 'Get
- * all' and 'Newest only' buttons. */
- if (new_headers_array->len > info->retrieve_limit) {
- /* TODO */
- }
-
- /* Should be get only the headers or the message as well? */
- if (g_ascii_strcasecmp (info->retrieve_type,
- MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY) != 0) {
- priv->done = 0;
- priv->total = MIN (new_headers_array->len, info->retrieve_limit);
- while (msg_num < priv->total) {
-
- TnyHeader *header = TNY_HEADER (g_ptr_array_index (new_headers_array, msg_num));
- TnyFolder *folder = tny_header_get_folder (header);
- TnyMsg *msg = tny_folder_get_msg (folder, header, NULL);
- ModestMailOperationState *state;
- ModestPair* pair;
-
- priv->done++;
- /* We can not just use the mail operation because the
- values of done and total could change before the
- idle is called */
- 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);
-
- g_object_unref (msg);
- g_object_unref (folder);
-
- msg_num++;
- }
- }
- }
-
- if (priv->status == MODEST_MAIL_OPERATION_STATUS_CANCELED)
- goto out;
-
- /* Copy the headers to a list and free the array */
- new_headers = tny_simple_list_new ();
- for (i=0; i < new_headers_array->len; i++) {
- TnyHeader *header = TNY_HEADER (g_ptr_array_index (new_headers_array, i));
- tny_list_append (new_headers, G_OBJECT (header));
- }
- g_ptr_array_foreach (new_headers_array, (GFunc) g_object_unref, NULL);
- g_ptr_array_free (new_headers_array, FALSE);
-
-
- /* Perform send (if operation was not cancelled) */
- priv->done = 0;
- priv->total = 0;
- if (priv->account != NULL)
- g_object_unref (priv->account);
- priv->account = g_object_ref (info->transport_account);
-
- send_queue = modest_runtime_get_send_queue (info->transport_account);
- if (send_queue) {
- modest_tny_send_queue_try_to_send (send_queue);
- } else {
- g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
- MODEST_MAIL_OPERATION_ERROR_INSTANCE_CREATION_FAILED,
- "cannot create a send queue for %s\n",
- tny_account_get_name (TNY_ACCOUNT (info->transport_account)));
- priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
- }
-
- /* Check if the operation was a success */
- if (!priv->error) {
- priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
-
- /* Update the last updated key */
- g_idle_add_full (G_PRIORITY_HIGH_IDLE,
- set_last_updated_idle,
- g_strdup (tny_account_get_id (TNY_ACCOUNT (info->account))),
- (GDestroyNotify) g_free);
- }
-
- out:
-
- if (info->callback) {
- UpdateAccountInfo *idle_info;
-
- /* This thread is not in the main lock */
- idle_info = g_malloc0 (sizeof (UpdateAccountInfo));
- idle_info->mail_op = g_object_ref (info->mail_op);
- idle_info->new_headers = (new_headers) ? g_object_ref (new_headers) : NULL;
- idle_info->callback = info->callback;
- idle_info->user_data = info->user_data;
- g_idle_add (idle_update_account_cb, idle_info);
- }
-
- /* Notify about operation end. Note that the info could be
- freed before this idle happens, but the mail operation will
- be still alive */
- g_idle_add (idle_notify_queue, g_object_ref (info->mail_op));
-
- /* Frees */
- if (new_headers)
- g_object_unref (new_headers);
- if (all_folders)
- g_object_unref (all_folders);
- g_object_unref (info->account);
- g_object_unref (info->transport_account);
- g_free (info->retrieve_type);
- g_slice_free (UpdateAccountInfo, info);
-
- first_time = FALSE;
-
- return NULL;