From: Sergio Villar Senin Date: Wed, 30 Apr 2008 11:29:23 +0000 (+0000) Subject: * Fixes NB#85108, wait until messages sent from external tools are added to the... X-Git-Tag: git_migration_finished~1403 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=8af03039f26e6320208576d998cb387d4d5d13d0 * Fixes NB#85108, wait until messages sent from external tools are added to the outbox pmo-trunk-r4491 --- diff --git a/src/modest-error.h b/src/modest-error.h index f78a9f1..2e2d2ae 100644 --- a/src/modest-error.h +++ b/src/modest-error.h @@ -48,6 +48,7 @@ typedef enum _ModestErrorCode { MODEST_MAIL_OPERATION_ERROR_RETRIEVAL_NUMBER_LIMIT, /* There were too many messages to retrieve. */ MODEST_MAIL_OPERATION_ERROR_INSTANCE_CREATION_FAILED, MODEST_MAIL_OPERATION_ERROR_FILE_IO, /* couldn't retrieve a file to construct a mail */ + MODEST_MAIL_OPERATION_ERROR_SEND_QUEUE_ADD_ERROR, } ModestErrorCode; G_END_DECLS diff --git a/src/modest-mail-operation.c b/src/modest-mail-operation.c index ffa5c29..3c1bda9 100644 --- a/src/modest-mail-operation.c +++ b/src/modest-mail-operation.c @@ -600,6 +600,35 @@ modest_mail_operation_clone_state (ModestMailOperation *self) /* ************************** 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, @@ -631,22 +660,15 @@ modest_mail_operation_send_mail (ModestMailOperation *self, "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); } - } diff --git a/src/modest-tny-send-queue.c b/src/modest-tny-send-queue.c index 526dd76..3b27216 100644 --- a/src/modest-tny-send-queue.c +++ b/src/modest-tny-send-queue.c @@ -192,6 +192,11 @@ modest_tny_send_queue_to_string (ModestTnySendQueue *self) return str; } +typedef struct { + TnySendQueueAddCallback callback; + gpointer user_data; +} AddAsyncHelper; + static void _on_added_to_outbox (TnySendQueue *self, gboolean cancelled, @@ -204,6 +209,7 @@ _on_added_to_outbox (TnySendQueue *self, 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)); @@ -231,6 +237,12 @@ _on_added_to_outbox (TnySendQueue *self, 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 @@ -288,8 +300,15 @@ modest_tny_send_queue_add_async (TnySendQueue *self, 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); }