GError *err,
gpointer user_data);
+static gboolean _check_memory_low (ModestMailOperation *mail_op);
+
enum _ModestMailOperationSignals
{
PROGRESS_CHANGED_SIGNAL,
/* ************************** 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);
}
-
}
priv = MODEST_MAIL_OPERATION_GET_PRIVATE (info->mail_op);
mgr = modest_runtime_get_account_mgr ();
+ /* Set the last updated as the current time, do it even if the inbox refresh failed */
+ modest_account_mgr_set_last_updated (mgr, tny_account_get_id (priv->account), time (NULL));
+
if (canceled || err) {
priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
if (err)
g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
MODEST_MAIL_OPERATION_ERROR_OPERATION_CANCELED,
"canceled");
+
/* Notify the user about the error and then exit */
update_account_notify_user_and_free (info, NULL);
return;
g_object_unref (info->inbox_observer);
info->inbox_observer = NULL;
- /* Update the last updated key, even if we don't have to get new headers */
- modest_account_mgr_set_last_updated (mgr, tny_account_get_id (priv->account), time (NULL));
-
if (new_headers_array->len == 0)
goto send_mail;
g_return_if_fail (TNY_IS_HEADER (header));
priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
- folder = tny_header_get_folder (header);
-
priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
priv->total = 1;
priv->done = 0;
+ /* Check memory low */
+ if (_check_memory_low (self)) {
+ if (user_callback)
+ user_callback (self, header, FALSE, NULL, priv->error, user_data);
+ modest_mail_operation_notify_end (self);
+ return;
+ }
+
/* Get account and set it into mail_operation */
+ folder = tny_header_get_folder (header);
priv->account = modest_tny_folder_get_account (TNY_FOLDER(folder));
/* Check for cached messages */
state->total = 0;
g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL],
0, state, NULL);
+ g_slice_free (ModestMailOperationState, state);
tny_folder_get_msg_async (folder, header, get_msg_async_cb, get_msg_status_cb, helper);
priv->done = 0;
priv->total = tny_list_get_length(header_list);
+ /* Check memory low */
+ if (_check_memory_low (self)) {
+ if (user_callback) {
+ TnyHeader *header = NULL;
+ TnyIterator *iter;
+
+ if (tny_list_get_length (header_list) > 0) {
+ iter = tny_list_create_iterator (header_list);
+ header = (TnyHeader *) tny_iterator_get_current (iter);
+ g_object_unref (iter);
+ }
+ user_callback (self, header, FALSE, NULL, priv->error, user_data);
+ if (header)
+ g_object_unref (header);
+ }
+ if (notify)
+ notify (user_data);
+ /* Notify about operation end */
+ modest_mail_operation_notify_end (self);
+ return;
+ }
+
/* Check uncached messages */
for (iter = tny_list_create_iterator (header_list), has_uncached_messages = FALSE;
!has_uncached_messages && !tny_iterator_is_done (iter);
priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
- priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
+ /* Check memory low */
+ if (_check_memory_low (self)) {
+ if (user_callback)
+ user_callback (self, folder, user_data);
+ /* Notify about operation end */
+ modest_mail_operation_notify_end (self);
+ return;
+ }
/* Get account and set it into mail_operation */
+ priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
priv->account = modest_tny_folder_get_account (folder);
priv->op_type = MODEST_MAIL_OPERATION_TYPE_RECEIVE;
priv->done, priv->total,
priv->error && priv->error->message ? priv->error->message : "");
}
+
+/*
+ * Once the mail operations were objects this will be no longer
+ * needed. I don't like it, but we need it for the moment
+ */
+static gboolean
+_check_memory_low (ModestMailOperation *mail_op)
+{
+ if (modest_platform_check_memory_low (NULL, FALSE)) {
+ ModestMailOperationPrivate *priv;
+
+ priv = MODEST_MAIL_OPERATION_GET_PRIVATE (mail_op);
+ priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
+ g_set_error (&(priv->error),
+ MODEST_MAIL_OPERATION_ERROR,
+ MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY,
+ "Not enough memory to complete the operation");
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}