+ if (TNY_IS_MSG (msg)) {
+ TnyHeader *header = tny_msg_get_header (msg);
+
+ if (header) {
+ ModestMailOperationState *state;
+ state = modest_mail_operation_clone_state (msg_info->mail_op);
+ msg_info->sum_total_bytes += tny_header_get_message_size (header);
+ state->bytes_done = msg_info->sum_total_bytes;
+ state->bytes_total = msg_info->total_bytes;
+
+ /* Notify the status change. Only notify about changes
+ referred to bytes */
+ g_signal_emit (G_OBJECT (msg_info->mail_op),
+ signals[PROGRESS_CHANGED_SIGNAL],
+ 0, state, NULL);
+
+ g_object_unref (header);
+ g_slice_free (ModestMailOperationState, state);
+ }
+ }
+
+ 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);