- /* Just delete the helper. Don't do anything with the new
- msg. There is also no need to check for errors */
- g_object_unref (msg_info->mail_op);
- g_object_unref (msg_info->header);
- g_slice_free (GetMsgInfo, msg_info);
+ if (priv->done == priv->total) {
+ TnyList *new_headers;
+ UpdateAccountInfo *info;
+
+ /* After getting all the messages send the ones in the
+ outboxes */
+ info = (UpdateAccountInfo *) msg_info->user_data;
+ update_account_send_mail (info);
+
+ /* Check if the operation was a success */
+ if (!priv->error)
+ priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
+
+ /* Call the user callback and free */
+ new_headers = tny_iterator_get_list (msg_info->more_msgs);
+ update_account_notify_user_and_free (info, new_headers);
+ g_object_unref (new_headers);
+
+ /* Delete the helper */
+ g_object_unref (msg_info->more_msgs);
+ g_object_unref (msg_info->mail_op);
+ g_slice_free (GetMsgInfo, msg_info);
+ }
+}
+
+static void
+update_account_notify_user_and_free (UpdateAccountInfo *info,
+ TnyList *new_headers)
+{
+ /* Set the account back to not busy */
+ modest_account_mgr_set_account_busy (modest_runtime_get_account_mgr (),
+ info->account_name, FALSE);
+
+ /* User callback */
+ if (info->callback)
+ info->callback (info->mail_op, new_headers, info->user_data);
+
+ /* Mail operation end */
+ modest_mail_operation_notify_end (info->mail_op);
+
+ /* Frees */
+ if (new_headers)
+ g_object_unref (new_headers);
+ destroy_update_account_info (info);