From: Sergio Villar Senin Date: Thu, 29 May 2008 09:23:58 +0000 (+0000) Subject: * Fixes NB#85964, do not crash when opening Drafts in memory full condition X-Git-Tag: git_migration_finished~1339 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=f541209a85cb6c71c79da1df81afbe10c448690a;hp=97e73afb9a2ed65af4802ff47739694224b95cec * Fixes NB#85964, do not crash when opening Drafts in memory full condition * Added a lot of checks TNY_IS_SEND_QUEUE because modest_runtime_get_send_queue could return NULL when there is no available space on disk in order to create the outbox folders pmo-trunk-r4583 --- diff --git a/src/dbus_api/modest-dbus-callbacks.c b/src/dbus_api/modest-dbus-callbacks.c index c515c6b..d2f0313 100644 --- a/src/dbus_api/modest-dbus-callbacks.c +++ b/src/dbus_api/modest-dbus-callbacks.c @@ -932,18 +932,21 @@ on_dbus_method_dump_send_queues (DBusConnection *con, DBusMessage *message) modest_runtime_get_account_store(), accname, TNY_ACCOUNT_TYPE_TRANSPORT); if (TNY_IS_ACCOUNT(acc)) { - gchar *tmp, *url = tny_account_get_url_string (acc); + gchar *tmp = NULL, *url = tny_account_get_url_string (acc); ModestTnySendQueue *sendqueue = modest_runtime_get_send_queue (TNY_TRANSPORT_ACCOUNT(acc), TRUE); - gchar *queue_str = modest_tny_send_queue_to_string (sendqueue); + + if (TNY_IS_SEND_QUEUE (sendqueue)) { + gchar *queue_str = modest_tny_send_queue_to_string (sendqueue); - tmp = g_strdup_printf ("%s[%s]: '%s': %s\n%s", - str, accname, tny_account_get_id (acc), url, - queue_str); - g_free(queue_str); + tmp = g_strdup_printf ("%s[%s]: '%s': %s\n%s", + str, accname, tny_account_get_id (acc), url, + queue_str); + g_free(queue_str); + g_free (str); + str = tmp; + } g_free (url); - g_free (str); - str = tmp; g_object_unref (acc); } diff --git a/src/maemo/modest-account-view-window.c b/src/maemo/modest-account-view-window.c index 48b2554..6698fc3 100644 --- a/src/maemo/modest-account-view-window.c +++ b/src/maemo/modest-account-view-window.c @@ -188,7 +188,7 @@ check_for_active_account (ModestAccountViewWindow *self, const gchar* account_na /* If the transport account was not used yet, then the send queue could not exist (it's created on demand) */ send_queue = modest_runtime_get_send_queue (TNY_TRANSPORT_ACCOUNT (transport_account), FALSE); - if (send_queue) + if (TNY_IS_SEND_QUEUE (send_queue)) sending = modest_tny_send_queue_sending_in_progress (send_queue); store_conn_status = tny_account_get_connection_status (store_account); diff --git a/src/modest-mail-operation.c b/src/modest-mail-operation.c index 64afda8..8b38cd6 100644 --- a/src/modest-mail-operation.c +++ b/src/modest-mail-operation.c @@ -510,7 +510,8 @@ modest_mail_operation_cancel (ModestMailOperation *self) TRUE); /* Cancel the sending of the following next messages */ - tny_send_queue_cancel (TNY_SEND_QUEUE (queue), TNY_SEND_QUEUE_CANCEL_ACTION_SUSPEND, NULL); + if (TNY_IS_SEND_QUEUE (queue)) + tny_send_queue_cancel (TNY_SEND_QUEUE (queue), TNY_SEND_QUEUE_CANCEL_ACTION_SUSPEND, NULL); } return canceled; @@ -1440,24 +1441,26 @@ inbox_refreshed_cb (TnyFolder *inbox, send_queue = modest_runtime_get_send_queue (transport_account, TRUE); g_object_unref (transport_account); - /* 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 (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) { - /* Reenable suspended items */ - modest_tny_send_queue_wakeup (MODEST_TNY_SEND_QUEUE (send_queue)); - - /* Try to send */ - tny_camel_send_queue_flush (TNY_CAMEL_SEND_QUEUE (send_queue)); - modest_tny_send_queue_set_requested_send_receive (MODEST_TNY_SEND_QUEUE (send_queue), - info->interactive); + if (num_messages != 0) { + /* Reenable suspended items */ + modest_tny_send_queue_wakeup (MODEST_TNY_SEND_QUEUE (send_queue)); + + /* Try to send */ + tny_camel_send_queue_flush (TNY_CAMEL_SEND_QUEUE (send_queue)); + modest_tny_send_queue_set_requested_send_receive (MODEST_TNY_SEND_QUEUE (send_queue), + info->interactive); + } } } @@ -2607,22 +2610,25 @@ modest_mail_operation_remove_msgs (ModestMailOperation *self, if (traccount) { ModestTnySendQueueStatus status; ModestTnySendQueue *send_queue = modest_runtime_get_send_queue(traccount, TRUE); - TnyIterator *iter = tny_list_create_iterator(headers); - g_object_unref(remove_headers); - remove_headers = TNY_LIST(tny_simple_list_new()); - while (!tny_iterator_is_done(iter)) { - char *msg_id; - TnyHeader *hdr = TNY_HEADER(tny_iterator_get_current(iter)); - msg_id = modest_tny_send_queue_get_msg_id (hdr); - status = modest_tny_send_queue_get_msg_status(send_queue, msg_id); - if (status != MODEST_TNY_SEND_QUEUE_SENDING) { - tny_list_append(remove_headers, G_OBJECT(hdr)); + + if (TNY_IS_SEND_QUEUE (send_queue)) { + TnyIterator *iter = tny_list_create_iterator(headers); + g_object_unref(remove_headers); + remove_headers = TNY_LIST(tny_simple_list_new()); + while (!tny_iterator_is_done(iter)) { + char *msg_id; + TnyHeader *hdr = TNY_HEADER(tny_iterator_get_current(iter)); + msg_id = modest_tny_send_queue_get_msg_id (hdr); + status = modest_tny_send_queue_get_msg_status(send_queue, msg_id); + if (status != MODEST_TNY_SEND_QUEUE_SENDING) { + tny_list_append(remove_headers, G_OBJECT(hdr)); + } + g_object_unref(hdr); + g_free(msg_id); + tny_iterator_next(iter); } - g_object_unref(hdr); - g_free(msg_id); - tny_iterator_next(iter); + g_object_unref(iter); } - g_object_unref(iter); g_object_unref(traccount); } } diff --git a/src/modest-runtime.c b/src/modest-runtime.c index b7fa5e7..8eda572 100644 --- a/src/modest-runtime.c +++ b/src/modest-runtime.c @@ -211,26 +211,27 @@ modest_runtime_get_send_queue (TnyTransportAccount *account, create) { /* Note that this send queue will start sending messages from its outbox * as soon as it is instantiated: */ - send_queue = (gpointer)modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(account)); - - _sig_handlers = - modest_signal_mgr_connect (_sig_handlers, - send_queue, - "error_happened", - G_CALLBACK (modest_ui_actions_on_send_queue_error_happened), - NULL); - - _sig_handlers = - modest_signal_mgr_connect (_sig_handlers, - send_queue, - "status_changed", - G_CALLBACK (modest_ui_actions_on_send_queue_status_changed), - NULL); - - - g_hash_table_insert (send_queue_cache, - g_object_ref (account), - g_object_ref (send_queue)); + send_queue = modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(account)); + + if (send_queue) { + _sig_handlers = + modest_signal_mgr_connect (_sig_handlers, + send_queue, + "error_happened", + G_CALLBACK (modest_ui_actions_on_send_queue_error_happened), + NULL); + + _sig_handlers = + modest_signal_mgr_connect (_sig_handlers, + send_queue, + "status_changed", + G_CALLBACK (modest_ui_actions_on_send_queue_status_changed), + NULL); + + g_hash_table_insert (send_queue_cache, + g_object_ref (account), + g_object_ref (send_queue)); + } } return (send_queue) ? MODEST_TNY_SEND_QUEUE(send_queue) : NULL; diff --git a/src/modest-tny-account-store.c b/src/modest-tny-account-store.c index 730f3c7..eb1f357 100644 --- a/src/modest-tny-account-store.c +++ b/src/modest-tny-account-store.c @@ -1613,9 +1613,13 @@ add_outbox_from_transport_account_to_global_outbox_get_folders_cb (TnyFolderStor self = MODEST_TNY_ACCOUNT_STORE (info->account_store); priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self); + /* Note that this could happen if there is not enough space + available on disk, then the outbox folder could not be + created */ if (tny_list_get_length (list) != 1) { - g_warning ("%s: > 1 outbox found (%d)?!", __FUNCTION__, + g_warning ("%s: could not create outbox folder (%d folders found)", __FUNCTION__, tny_list_get_length (list)); + goto frees; } iter_folders = tny_list_create_iterator (list); @@ -1636,10 +1640,11 @@ add_outbox_from_transport_account_to_global_outbox_get_folders_cb (TnyFolderStor /* Notify that the local account changed */ g_signal_emit (G_OBJECT (self), signals [ACCOUNT_CHANGED_SIGNAL], 0, local_account); - - g_object_unref (info->transport_account); g_object_unref (local_account); g_object_unref (per_account_outbox); + + frees: + g_object_unref (info->transport_account); g_slice_free (AddOutboxInfo, info); } @@ -1807,7 +1812,7 @@ on_account_disconnect_when_removing (TnyCamelAccount *account, } else if (TNY_IS_TRANSPORT_ACCOUNT (account)) { ModestTnySendQueue* send_queue; send_queue = modest_runtime_get_send_queue (TNY_TRANSPORT_ACCOUNT (account), FALSE); - if (send_queue) { + if (TNY_IS_SEND_QUEUE (send_queue)) { if (modest_tny_send_queue_sending_in_progress (send_queue)) tny_send_queue_cancel (TNY_SEND_QUEUE (send_queue), TNY_SEND_QUEUE_CANCEL_ACTION_REMOVE, @@ -2107,7 +2112,6 @@ modest_tny_account_store_get_transport_account_from_outbox_header(ModestTnyAccou g_return_val_if_fail (MODEST_IS_TNY_ACCOUNT_STORE (self), NULL); g_return_val_if_fail (TNY_IS_HEADER (header), NULL); priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE (self); - msg_id = modest_tny_send_queue_get_msg_id (header); acc_iter = tny_list_create_iterator (priv->transport_accounts); while (!header_acc && !tny_iterator_is_done (acc_iter)) { @@ -2115,9 +2119,10 @@ modest_tny_account_store_get_transport_account_from_outbox_header(ModestTnyAccou ModestTnySendQueue *send_queue; ModestTnySendQueueStatus status; send_queue = modest_runtime_get_send_queue(TNY_TRANSPORT_ACCOUNT(account), TRUE); - status = modest_tny_send_queue_get_msg_status(send_queue, msg_id); - if (status != MODEST_TNY_SEND_QUEUE_UNKNOWN) { - header_acc = g_object_ref(account); + if (TNY_IS_SEND_QUEUE (send_queue)) { + status = modest_tny_send_queue_get_msg_status(send_queue, msg_id); + if (status != MODEST_TNY_SEND_QUEUE_UNKNOWN) + header_acc = g_object_ref(account); } g_object_unref (account); tny_iterator_next (acc_iter); diff --git a/src/modest-tny-send-queue.c b/src/modest-tny-send-queue.c index ae2d3d1..bb103ab 100644 --- a/src/modest-tny-send-queue.c +++ b/src/modest-tny-send-queue.c @@ -480,7 +480,21 @@ modest_tny_send_queue_new (TnyCamelTransportAccount *account) g_return_val_if_fail (TNY_IS_CAMEL_TRANSPORT_ACCOUNT(account), NULL); self = MODEST_TNY_SEND_QUEUE(g_object_new(MODEST_TYPE_TNY_SEND_QUEUE, NULL)); - + + /* Set outbox and sentbox */ + priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self); + priv->outbox = modest_tny_account_get_special_folder (TNY_ACCOUNT(account), + TNY_FOLDER_TYPE_OUTBOX); + priv->sentbox = modest_tny_account_get_special_folder (TNY_ACCOUNT(account), + TNY_FOLDER_TYPE_SENT); + + /* NOTE that this could happen if there was not enough disk + space when the account was created */ + if (!priv->outbox || !priv->sentbox) { + g_object_unref (self); + return NULL; + } + /* Connect signals to control when a msg is being or has been sent */ g_signal_connect (G_OBJECT(self), "msg-sending", G_CALLBACK(_on_msg_start_sending), @@ -495,12 +509,7 @@ modest_tny_send_queue_new (TnyCamelTransportAccount *account) G_CALLBACK (_on_queue_start), NULL); - /* Set outbox and sentbox */ - priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self); - priv->outbox = modest_tny_account_get_special_folder (TNY_ACCOUNT(account), - TNY_FOLDER_TYPE_OUTBOX); - priv->sentbox = modest_tny_account_get_special_folder (TNY_ACCOUNT(account), - TNY_FOLDER_TYPE_SENT); + priv->requested_send_receive = FALSE; headers = tny_simple_list_new (); @@ -769,11 +778,12 @@ modest_tny_all_send_queues_get_msg_status (TnyHeader *header) account = TNY_TRANSPORT_ACCOUNT(tny_iterator_get_current (iter)); send_queue = modest_runtime_get_send_queue(TNY_TRANSPORT_ACCOUNT(account), TRUE); g_object_unref(account); - - queue_status = modest_tny_send_queue_get_msg_status (send_queue, msg_uid); - if (queue_status != MODEST_TNY_SEND_QUEUE_UNKNOWN) { - status = queue_status; - break; + if (TNY_IS_SEND_QUEUE (send_queue)) { + queue_status = modest_tny_send_queue_get_msg_status (send_queue, msg_uid); + if (queue_status != MODEST_TNY_SEND_QUEUE_UNKNOWN) { + status = queue_status; + break; + } } tny_iterator_next (iter); } diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 6c9824e..f460812 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -902,13 +902,15 @@ open_msg_cb (ModestMailOperation *mail_op, account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account( TNY_ACCOUNT(traccount))); send_queue = modest_runtime_get_send_queue(traccount, TRUE); - msg_id = modest_tny_send_queue_get_msg_id (header); - status = modest_tny_send_queue_get_msg_status(send_queue, msg_id); - /* Only open messages in outbox with the editor if they are in Failed state */ - if (status == MODEST_TNY_SEND_QUEUE_FAILED) { - open_in_editor = TRUE; + if (TNY_IS_SEND_QUEUE (send_queue)) { + msg_id = modest_tny_send_queue_get_msg_id (header); + status = modest_tny_send_queue_get_msg_status(send_queue, msg_id); + /* Only open messages in outbox with the editor if they are in Failed state */ + if (status == MODEST_TNY_SEND_QUEUE_FAILED) { + open_in_editor = TRUE; + } + g_free(msg_id); } - g_free(msg_id); g_object_unref(traccount); } else { g_warning("Cannot get transport account for message in outbox!!");