X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-mail-operation.c;h=6f7d2abd5050c8c30867f85735c6098e1dca53ff;hp=b441d2a4f73d888e42a8830b675d5b670c03ecb5;hb=5944929fea7239bff03a13ff76a663c3cbda0121;hpb=22df4a1b619ba37528d6b3e449bc752d7694900e diff --git a/src/modest-mail-operation.c b/src/modest-mail-operation.c index b441d2a..6f7d2ab 100644 --- a/src/modest-mail-operation.c +++ b/src/modest-mail-operation.c @@ -626,6 +626,7 @@ modest_mail_operation_send_mail (ModestMailOperation *self, 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); priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS; modest_mail_operation_notify_end (self); @@ -1180,6 +1181,7 @@ typedef struct gboolean poke_all; TnyFolderObserver *inbox_observer; RetrieveAllCallback retrieve_all_cb; + gboolean interactive; } UpdateAccountInfo; @@ -1222,7 +1224,7 @@ inbox_refreshed_cb (TnyFolder *inbox, ModestAccountMgr *mgr; ModestAccountRetrieveType retrieve_type; TnyList *new_headers = NULL; - gboolean headers_only, ignore_limit; + gboolean headers_only, ignore_limit, succeeded; TnyTransportAccount *transport_account = NULL; info = (UpdateAccountInfo *) user_data; @@ -1276,7 +1278,7 @@ inbox_refreshed_cb (TnyFolder *inbox, retrieve_limit = G_MAXINT; /* Get per-account retrieval type */ - retrieve_type = modest_account_mgr_get_retrieve_type (mgr, info->account_name); + retrieve_type = modest_account_mgr_get_retrieve_type (mgr, info->account_name); headers_only = (retrieve_type == MODEST_ACCOUNT_RETRIEVE_HEADERS_ONLY); /* Order by date */ @@ -1335,6 +1337,13 @@ inbox_refreshed_cb (TnyFolder *inbox, g_ptr_array_foreach (new_headers_array, (GFunc) g_object_unref, NULL); g_ptr_array_free (new_headers_array, FALSE); + if (priv->error) + succeeded = FALSE; + else + succeeded = TRUE; + modest_account_mgr_set_server_account_username_has_succeeded (modest_runtime_get_account_mgr (), + tny_account_get_name (priv->account), + succeeded); send_mail: /* Get the transport account */ transport_account = (TnyTransportAccount *) @@ -1360,14 +1369,13 @@ inbox_refreshed_cb (TnyFolder *inbox, } if (num_messages != 0) { - /* Send mails */ - g_object_unref (priv->account); - /* 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); } } @@ -1406,7 +1414,8 @@ recurse_folders_async_cb (TnyFolderStore *folder_store, if (err || canceled) { /* Try to continue anyway */ - } else { + } else if (info->poke_all) { + /* We're not getting INBOX children if we don't want to poke all */ TnyIterator *iter = tny_list_create_iterator (list); while (!tny_iterator_is_done (iter)) { TnyFolderStore *folder = (TnyFolderStore*) tny_iterator_get_current (iter); @@ -1486,6 +1495,7 @@ void modest_mail_operation_update_account (ModestMailOperation *self, const gchar *account_name, gboolean poke_all, + gboolean interactive, RetrieveAllCallback retrieve_all_cb, UpdateAccountCallback callback, gpointer user_data) @@ -1510,12 +1520,31 @@ modest_mail_operation_update_account (ModestMailOperation *self, account_name, TNY_ACCOUNT_TYPE_STORE); + /* The above function could return NULL */ + if (!priv->account) { + /* Check if the operation was a success */ + g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR, + MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND, + "no account"); + priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED; + + /* Call the user callback */ + if (callback) + callback (self, NULL, user_data); + + /* Notify about operation end */ + modest_mail_operation_notify_end (self); + + return; + } + /* Create the helper object */ info = g_slice_new0 (UpdateAccountInfo); info->pending_calls = 1; info->folders = tny_simple_list_new (); info->mail_op = g_object_ref (self); info->poke_all = poke_all; + info->interactive = interactive; info->account_name = g_strdup (account_name); info->callback = callback; info->user_data = user_data; @@ -2221,16 +2250,30 @@ modest_mail_operation_get_msgs_full (ModestMailOperation *self, ModestMailOperationPrivate *priv = NULL; gint msg_list_size; TnyIterator *iter = NULL; + gboolean has_uncached_messages; g_return_if_fail (MODEST_IS_MAIL_OPERATION (self)); /* Init mail operation */ priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self); priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS; - priv->op_type = MODEST_MAIL_OPERATION_TYPE_RECEIVE; priv->done = 0; priv->total = tny_list_get_length(header_list); + /* Check uncached messages */ + for (iter = tny_list_create_iterator (header_list), has_uncached_messages = FALSE; + !has_uncached_messages && !tny_iterator_is_done (iter); + tny_iterator_next (iter)) { + TnyHeader *header; + + header = (TnyHeader *) tny_iterator_get_current (iter); + if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED)) + has_uncached_messages = TRUE; + g_object_unref (header); + } + g_object_unref (iter); + priv->op_type = has_uncached_messages?MODEST_MAIL_OPERATION_TYPE_RECEIVE:MODEST_MAIL_OPERATION_TYPE_OPEN; + /* Get account and set it into mail_operation */ if (tny_list_get_length (header_list) >= 1) { TnyIterator *iterator = tny_list_create_iterator (header_list); @@ -2828,19 +2871,6 @@ on_refresh_folder (TnyFolder *folder, g_return_if_fail(priv!=NULL); - /* If the folder is remote, set the "Last updated" value */ - if (modest_tny_folder_is_remote_folder (folder)) { - TnyAccount *account = modest_tny_folder_get_account (folder); - ModestAccountMgr *mgr = modest_runtime_get_account_mgr (); - const gchar *name; - name = modest_tny_account_get_parent_modest_account_name_for_server_account (account); - modest_account_mgr_set_last_updated (mgr, tny_account_get_id (account), time (NULL)); - if (!cancelled && !error) - modest_account_mgr_set_server_account_username_has_succeeded (mgr, tny_account_get_id (account), TRUE); - modest_account_mgr_set_account_busy (mgr, name, FALSE); - g_object_unref (account); - } - if (error) { priv->error = g_error_copy (error); priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED; @@ -2930,15 +2960,6 @@ modest_mail_operation_refresh_folder (ModestMailOperation *self, helper->user_callback = user_callback; helper->user_data = user_data; - /* Refresh the folder. TODO: tinymail could issue a status - updates before the callback call then this could happen. We - must review the design */ - if (modest_tny_folder_is_remote_folder (folder)) { - /* If the folder is remote, mark its account as busy */ - const gchar *name; - name = modest_tny_account_get_parent_modest_account_name_for_server_account (priv->account); - modest_account_mgr_set_account_busy (modest_runtime_get_account_mgr (), name, TRUE); - } modest_mail_operation_notify_start (self); /* notify that the operation was started */