+ 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);
+
+ /* 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);
+}
+
+static void
+inbox_refreshed_cb (TnyFolder *inbox,
+ gboolean canceled,
+ GError *err,
+ gpointer user_data)
+{
+ UpdateAccountInfo *info;
+ ModestMailOperationPrivate *priv;
+ TnyIterator *new_headers_iter;
+ GPtrArray *new_headers_array = NULL;
+ gint max_size, retrieve_limit, i;
+ ModestAccountMgr *mgr;
+ ModestAccountRetrieveType retrieve_type;
+ TnyList *new_headers = NULL;
+ gboolean headers_only;
+ time_t time_to_store;
+
+ info = (UpdateAccountInfo *) user_data;
+ priv = MODEST_MAIL_OPERATION_GET_PRIVATE (info->mail_op);
+ mgr = modest_runtime_get_account_mgr ();
+
+ if (canceled || err) {
+ priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
+ if (err)
+ priv->error = g_error_copy (err);
+ else
+ g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
+ MODEST_MAIL_OPERATION_ERROR_OPERATION_CANCELED,
+ "canceled");
+
+ if (inbox)
+ tny_folder_remove_observer (inbox, info->inbox_observer);
+ g_object_unref (info->inbox_observer);
+ info->inbox_observer = NULL;
+
+ /* Notify the user about the error and then exit */
+ update_account_notify_user_and_free (info, NULL);
+ return;
+ }
+
+ if (!inbox) {
+ /* Try to send anyway */
+ goto send_mail;
+ }
+
+ /* Set the last updated as the current time */
+#ifdef MODEST_USE_LIBTIME
+ struct tm utc_tm;
+ time_get_utc (&utc_tm);
+ time_to_store = time_mktime (&utc_tm, "GMT");
+#else
+ time_to_store = time (NULL);
+#endif
+ modest_account_mgr_set_last_updated (mgr, tny_account_get_id (priv->account), time_to_store);
+
+ /* Get the message max size */
+ max_size = modest_conf_get_int (modest_runtime_get_conf (),
+ MODEST_CONF_MSG_SIZE_LIMIT, NULL);
+ if (max_size == 0)
+ max_size = G_MAXINT;