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 */
}
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));
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;
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);
+ }
+ 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);