+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;
+ } else {
+ priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
+ }
+
+ end:
+ if (helper->notify) {
+ TnyTransportAccount *trans_account;
+ ModestTnySendQueue *queue;
+
+ trans_account = (TnyTransportAccount *) modest_mail_operation_get_account (self);
+ queue = modest_runtime_get_send_queue (trans_account, TRUE);
+ if (queue) {
+ RunQueueHelper *helper;
+
+ /* Create the helper */
+ helper = g_slice_new0 (RunQueueHelper);
+ helper->queue = g_object_ref (queue);
+ helper->self = g_object_ref (self);
+
+ /* if sending is ongoing wait for the queue to
+ stop. Otherwise wait for the queue-start
+ signal. It could happen that the queue
+ could not start, then check also the error
+ happened signal */
+ if (modest_tny_send_queue_sending_in_progress (queue)) {
+ run_queue_start (TNY_SEND_QUEUE (queue), helper);
+ } else {
+ helper->start_handler = g_signal_connect (queue, "queue-start",
+ G_CALLBACK (run_queue_start),
+ helper);
+ helper->error_handler = g_signal_connect (queue, "error-happened",
+ G_CALLBACK (run_queue_error_happened),
+ helper);
+ }
+ } else {
+ /* Finalize this mail operation */
+ modest_mail_operation_notify_end (self);
+ }
+ g_object_unref (trans_account);
+ }
+
+ g_object_unref (helper->mail_op);
+ g_slice_free (SendNewMailHelper, helper);
+}