/* ************************** SEND ACTIONS ************************* */
/* ******************************************************************* */
+static void
+send_mail_on_added_to_outbox (TnySendQueue *send_queue,
+ gboolean cancelled,
+ TnyMsg *msg,
+ GError *err,
+ gpointer user_data)
+{
+ ModestMailOperationPrivate *priv;
+ ModestMailOperation *self;
+
+ self = MODEST_MAIL_OPERATION (user_data);
+ 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:
+ modest_mail_operation_notify_end (self);
+ g_object_unref (self);
+}
+
void
modest_mail_operation_send_mail (ModestMailOperation *self,
TnyTransportAccount *transport_account,
"modest: could not find send queue for account\n");
priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
modest_mail_operation_notify_end (self);
-
} else {
- /* Add the msg to the queue */
modest_mail_operation_notify_start (self);
-
- tny_send_queue_add_async (send_queue, msg, NULL, NULL, NULL);
- modest_tny_send_queue_set_requested_send_receive (MODEST_TNY_SEND_QUEUE (send_queue), FALSE);
-
- if (priv->error) {
- priv->status = MODEST_MAIL_OPERATION_STATUS_FINISHED_WITH_ERRORS;
- } else {
- priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
- }
- modest_mail_operation_notify_end (self);
+ /* Add the msg to the queue. The callback will
+ finalize the mail operation */
+ tny_send_queue_add_async (send_queue, msg, send_mail_on_added_to_outbox,
+ NULL, g_object_ref (self));
+ modest_tny_send_queue_set_requested_send_receive (MODEST_TNY_SEND_QUEUE (send_queue),
+ FALSE);
}
-
}
return str;
}
+typedef struct {
+ TnySendQueueAddCallback callback;
+ gpointer user_data;
+} AddAsyncHelper;
+
static void
_on_added_to_outbox (TnySendQueue *self,
gboolean cancelled,
SendInfo *info = NULL;
GList* existing = NULL;
gchar* msg_id = NULL;
+ AddAsyncHelper *helper;
g_return_if_fail (TNY_IS_SEND_QUEUE(self));
g_return_if_fail (TNY_IS_CAMEL_MSG(msg));
end:
g_object_unref (G_OBJECT(header));
+
+ /* Call the user callback */
+ helper = (AddAsyncHelper *) user_data;
+ if (helper->callback)
+ helper->callback (self, cancelled, msg, err, helper->user_data);
+ g_slice_free (AddAsyncHelper, helper);
}
static void
TnyStatusCallback status_callback,
gpointer user_data)
{
+ AddAsyncHelper *helper = g_slice_new0 (AddAsyncHelper);
+ helper->callback = callback;
+ helper->user_data = user_data;
+
/* Call the superclass passing our own callback */
- TNY_CAMEL_SEND_QUEUE_CLASS(parent_class)->add_async (self, msg, _on_added_to_outbox, NULL, NULL);
+ TNY_CAMEL_SEND_QUEUE_CLASS(parent_class)->add_async (self, msg,
+ _on_added_to_outbox,
+ status_callback,
+ helper);
}