+ g_object_unref (helper->mail_op);
+ g_slice_free (SendNewMailHelper, helper);
+}
+
+static void
+run_queue_start (TnySendQueue *self,
+ gpointer user_data)
+{
+ RunQueueHelper *helper = (RunQueueHelper *) user_data;
+ ModestMailOperation *mail_op;
+
+ g_debug ("%s sending queue successfully started", __FUNCTION__);
+
+ /* Wait for the message to be sent */
+ mail_op = modest_mail_operation_new (NULL);
+ modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
+ mail_op);
+ modest_mail_operation_run_queue (mail_op, helper->queue);
+ g_object_unref (mail_op);
+
+ /* Free the helper and end operation */
+ run_queue_notify_and_destroy (helper, MODEST_MAIL_OPERATION_STATUS_SUCCESS);
+}
+
+static void
+run_queue_error_happened (TnySendQueue *queue,
+ TnyHeader *header,
+ TnyMsg *msg,
+ GError *error,
+ gpointer user_data)
+{
+ RunQueueHelper *helper = (RunQueueHelper *) user_data;
+ ModestMailOperationPrivate *priv;
+
+ /* If we are here this means that the send queue could not
+ start to send emails. Shouldn't happen as this means that
+ we could not create the thread */
+ g_debug ("%s sending queue failed to create the thread", __FUNCTION__);
+
+ priv = MODEST_MAIL_OPERATION_GET_PRIVATE (helper->self);
+ priv->error = g_error_copy ((const GError *) error);
+
+ if (error->code != TNY_SYSTEM_ERROR_UNKNOWN) {
+ /* This code is here for safety reasons. It should
+ never be called, because that would mean that we
+ are not controlling some error case */
+ g_warning ("%s Error %s should not happen",
+ __FUNCTION__, error->message);
+ }
+
+ /* Free helper and end operation */
+ run_queue_notify_and_destroy (helper, MODEST_MAIL_OPERATION_STATUS_FAILED);
+}
+
+static void
+send_mail_on_added_to_outbox (TnySendQueue *send_queue,
+ gboolean cancelled,
+ TnyMsg *msg,
+ GError *err,
+ gpointer user_data)
+{
+ ModestMailOperationPrivate *priv;
+ ModestMailOperation *self;
+ SendNewMailHelper *helper;
+
+ helper = (SendNewMailHelper *) user_data;
+ self = helper->mail_op;
+ priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
+
+ if (cancelled || err)
+ goto end;
+
+ if (err) {
+ g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
+ MODEST_MAIL_OPERATION_ERROR_SEND_QUEUE_ADD_ERROR,
+ "Error adding a msg to the send queue\n");
+ priv->status = MODEST_MAIL_OPERATION_STATUS_FINISHED_WITH_ERRORS;