return FALSE;
}
- /* Notify about operation end */
- modest_mail_operation_notify_end (self);
-
did_a_cancel = TRUE;
/* Set new status */
priv->status = MODEST_MAIL_OPERATION_STATUS_CANCELED;
-
- modest_mail_operation_queue_cancel_all (modest_runtime_get_mail_operation_queue());
+ /* This emits progress-changed on which the mail operation queue is
+ * listening, so the mail operation is correctly removed from the
+ * queue without further explicit calls. */
+ modest_mail_operation_notify_end (self);
return TRUE;
}
msg = modest_tny_msg_new_html_plain (to, from, cc, bcc, subject, html_body, plain_body, (GSList *) attachments_list);
}
if (!msg) {
+ priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
MODEST_MAIL_OPERATION_ERROR_INSTANCE_CREATION_FAILED,
"modest: failed to create a new msg\n");
folder = modest_tny_account_get_special_folder (TNY_ACCOUNT (transport_account), TNY_FOLDER_TYPE_DRAFTS);
if (!folder) {
+ priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
"modest: failed to create a new msg\n");
}
tny_folder_add_msg (folder, msg, &(priv->error));
- if (priv->error)
- goto end;
+ if (!priv->error)
+ priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
end:
if (msg)
gint retrieve_limit;
gchar *retrieve_type;
gchar *account_name;
+ UpdateAccountCallback callback;
+ gpointer user_data;
} UpdateAccountInfo;
/***** I N T E R N A L F O L D E R O B S E R V E R *****/
static gboolean first_time = TRUE;
UpdateAccountInfo *info;
TnyList *all_folders = NULL;
- GPtrArray *new_headers;
+ GPtrArray *new_headers = NULL;
TnyIterator *iter = NULL;
TnyFolderStoreQuery *query = NULL;
- ModestMailOperationPrivate *priv;
- ModestTnySendQueue *send_queue;
+ ModestMailOperationPrivate *priv = NULL;
+ ModestTnySendQueue *send_queue = NULL;
info = (UpdateAccountInfo *) thr_user_data;
priv = MODEST_MAIL_OPERATION_GET_PRIVATE(info->mail_op);
/* Refresh the folder */
/* Our observer receives notification of new emails during folder refreshes,
* so we can use observer->new_headers.
- * TODO: This does not seem to be providing accurate numbers.
- * Possibly the observer is notified asynchronously.
*/
observer = g_object_new (internal_folder_observer_get_type (), NULL);
tny_folder_add_observer (TNY_FOLDER (folder), TNY_FOLDER_OBSERVER (observer));
}
tny_folder_remove_observer (TNY_FOLDER (folder), TNY_FOLDER_OBSERVER (observer));
g_object_unref (observer);
- observer = NULL;
+ observer = NULL;
+ g_object_unref (G_OBJECT (folder));
if (priv->error)
+ {
priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
-
- g_object_unref (G_OBJECT (folder));
+ goto out;
+ }
+
tny_iterator_next (iter);
}
* user to download them all,
* as per the UI spec "Retrieval Limits" section in 4.4:
*/
- printf ("************************** DEBUG: %s: account=%s, len=%d, retrieve_limit = %d\n", __FUNCTION__,
- tny_account_get_id (priv->account), new_headers->len, info->retrieve_limit);
if (new_headers->len > info->retrieve_limit) {
- /* TODO: Ask the user, instead of just failing, showing mail_nc_msg_count_limit_exceeded,
- * with 'Get all' and 'Newest only' buttons. */
+ /* TODO: Ask the user, instead of just
+ * failing, showing
+ * mail_nc_msg_count_limit_exceeded, with 'Get
+ * all' and 'Newest only' buttons. */
g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
MODEST_MAIL_OPERATION_ERROR_RETRIEVAL_NUMBER_LIMIT,
"The number of messages to retrieve exceeds the chosen limit for account %s\n",
g_ptr_array_foreach (new_headers, (GFunc) g_object_unref, NULL);
g_ptr_array_free (new_headers, FALSE);
}
-
+
/* Perform send */
priv->op_type = MODEST_MAIL_OPERATION_TYPE_SEND;
priv->done = 0;
freed before this idle happens, but the mail operation will
be still alive */
g_idle_add (notify_update_account_queue, g_object_ref (info->mail_op));
+
+ if (info->callback) {
+ /* This thread is not in the main lock */
+ gdk_threads_enter ();
+ info->callback (info->mail_op,
+ (new_headers) ? new_headers->len : 0,
+ info->user_data);
+ gdk_threads_leave ();
+ }
/* Frees */
g_object_unref (query);
gboolean
modest_mail_operation_update_account (ModestMailOperation *self,
- const gchar *account_name)
+ const gchar *account_name,
+ UpdateAccountCallback callback,
+ gpointer user_data)
{
GThread *thread;
UpdateAccountInfo *info;
g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), FALSE);
g_return_val_if_fail (account_name, FALSE);
- /* Make sure that we have a connection, and request one
- * if necessary:
- * TODO: Is there some way to trigger this for every attempt to
- * use the network? */
- if (!modest_platform_connect_and_wait(NULL))
- return FALSE;
-
/* Init mail operation. Set total and done to 0, and do not
update them, this way the progress objects will know that
we have no clue about the number of the objects */
priv->total = 0;
priv->done = 0;
priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
-
+
+ /* Make sure that we have a connection, and request one
+ * if necessary:
+ * TODO: Is there some way to trigger this for every attempt to
+ * use the network? */
+ if (!modest_platform_connect_and_wait(NULL))
+ goto error;
+
/* Get the Modest account */
modest_account = (TnyStoreAccount *)
modest_tny_account_store_get_server_account (modest_runtime_get_account_store (),
TNY_ACCOUNT_TYPE_STORE);
if (!modest_account) {
- priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
"cannot get tny store account for %s\n", account_name);
- modest_mail_operation_notify_end (self);
-
- return FALSE;
+ goto error;
}
modest_tny_account_store_get_transport_account_for_open_connection (modest_runtime_get_account_store(),
account_name);
if (!transport_account) {
- priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
"cannot get tny transport account for %s\n", account_name);
- modest_mail_operation_notify_end (self);
-
- return FALSE;
+ goto error;
}
/* Create the helper object */
info->mail_op = self;
info->account = modest_account;
info->transport_account = transport_account;
+ info->callback = callback;
+ info->user_data = user_data;
/* Get the message size limit */
info->max_size = modest_conf_get_int (modest_runtime_get_conf (),
thread = g_thread_create (update_account_thread, info, FALSE, NULL);
return TRUE;
+
+ error:
+ priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
+ if (callback)
+ callback (self, 0, user_data);
+ modest_mail_operation_notify_end (self);
+ return FALSE;
}
/* ******************************************************************* */
/* If user defined callback function was defined, call it */
if (helper->user_callback) {
+ /* This callback is called into an iddle by tinymail,
+ and idles are not in the main lock */
+ gdk_threads_enter ();
helper->user_callback (self, helper->header, msg, helper->user_data);
+ gdk_threads_leave ();
}
out:
info = (NotifyGetMsgsInfo *) data;
- /* Call the user callback */
+ /* Call the user callback. Idles are not in the main lock, so
+ lock it */
+ gdk_threads_enter ();
info->user_callback (info->mail_op, info->header, info->msg, info->user_data);
+ gdk_threads_leave ();
g_slice_free (NotifyGetMsgsInfo, info);
/* If user defined callback function was defined, call it */
if (helper->user_callback) {
+ gdk_threads_enter ();
helper->user_callback (priv->source, helper->user_data);
+ gdk_threads_leave ();
}
/* Free */
/* Apply folder rules */
rules = modest_tny_folder_get_rules (TNY_FOLDER (folder));
-
if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
/* Set status failed and set an error */
priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
out:
/* Call user defined callback, if it exists */
- if (helper->user_callback)
+ if (helper->user_callback) {
+/* gdk_threads_enter (); */
helper->user_callback (priv->source, folder, helper->user_data);
+/* gdk_threads_leave (); */
+ }
/* Free */
g_object_unref (helper->mail_op);