+ account_store = modest_runtime_get_account_store ();
+
+ /* We don't try to send messages while sending mails is blocked */
+ if (modest_tny_account_store_is_send_mail_blocked (account_store))
+ return;
+
+ /* Get the transport account */
+ transport_account = (TnyTransportAccount *)
+ modest_tny_account_store_get_server_account (account_store, info->account_name,
+ TNY_ACCOUNT_TYPE_TRANSPORT);
+
+ if (transport_account) {
+ ModestTnySendQueue *send_queue;
+ TnyFolder *outbox;
+ guint num_messages;
+
+ send_queue = modest_runtime_get_send_queue (transport_account, TRUE);
+ g_object_unref (transport_account);
+
+ if (TNY_IS_SEND_QUEUE (send_queue)) {
+ /* Get outbox folder */
+ outbox = tny_send_queue_get_outbox (TNY_SEND_QUEUE (send_queue));
+ if (outbox) { /* this could fail in some cases */
+ num_messages = tny_folder_get_all_count (outbox);
+ g_object_unref (outbox);
+ } else {
+ g_warning ("%s: could not get outbox", __FUNCTION__);
+ num_messages = 0;
+ }
+
+ if (num_messages != 0) {
+ ModestMailOperation *mail_op;
+ /* Reenable suspended items */
+ mail_op = modest_mail_operation_new (NULL);
+ modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
+ mail_op);
+ modest_mail_operation_queue_wakeup (mail_op, MODEST_TNY_SEND_QUEUE (send_queue));
+
+ /* Try to send */
+ modest_tny_send_queue_set_requested_send_receive (MODEST_TNY_SEND_QUEUE (send_queue),
+ info->interactive);
+ }
+ }
+ }
+}
+
+static void
+update_account_get_msg_async_cb (TnyFolder *folder,
+ gboolean canceled,
+ TnyMsg *msg,
+ GError *err,
+ gpointer user_data)
+{
+ GetMsgInfo *msg_info = (GetMsgInfo *) user_data;
+ ModestMailOperationPrivate *priv;
+
+ priv = MODEST_MAIL_OPERATION_GET_PRIVATE (msg_info->mail_op);
+ priv->done++;
+
+ 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);
+
+ /* Delete the helper */
+ if (msg_info->msg)
+ g_object_unref (msg_info->msg);
+ 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);