diff options
Diffstat (limited to 'libemail-engine')
-rw-r--r-- | libemail-engine/e-mail-session-utils.c | 120 | ||||
-rw-r--r-- | libemail-engine/e-mail-session-utils.h | 22 |
2 files changed, 142 insertions, 0 deletions
diff --git a/libemail-engine/e-mail-session-utils.c b/libemail-engine/e-mail-session-utils.c index 0694ea60a5..f9ddcb2564 100644 --- a/libemail-engine/e-mail-session-utils.c +++ b/libemail-engine/e-mail-session-utils.c @@ -56,6 +56,8 @@ struct _AsyncContext { GPtrArray *post_to_uris; + EMailLocalFolder local_id; + gchar *folder_uri; gchar *message_uid; gchar *transport_uid; @@ -119,6 +121,124 @@ e_mail_error_quark (void) } static void +mail_session_append_to_local_folder_thread (GSimpleAsyncResult *simple, + GObject *object, + GCancellable *cancellable) +{ + AsyncContext *context; + GError *error = NULL; + + context = g_simple_async_result_get_op_res_gpointer (simple); + + e_mail_session_append_to_local_folder_sync ( + E_MAIL_SESSION (object), + context->local_id, context->message, + context->info, &context->message_uid, + cancellable, &error); + + if (error != NULL) + g_simple_async_result_take_error (simple, error); +} + +gboolean +e_mail_session_append_to_local_folder_sync (EMailSession *session, + EMailLocalFolder local_id, + CamelMimeMessage *message, + CamelMessageInfo *info, + gchar **appended_uid, + GCancellable *cancellable, + GError **error) +{ + CamelFolder *folder; + const gchar *folder_uri; + gboolean success = FALSE; + + g_return_val_if_fail (E_IS_MAIL_SESSION (session), FALSE); + g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), FALSE); + + folder_uri = e_mail_session_get_local_folder_uri (session, local_id); + g_return_val_if_fail (folder_uri != NULL, FALSE); + + folder = e_mail_session_uri_to_folder_sync ( + session, folder_uri, CAMEL_STORE_FOLDER_CREATE, + cancellable, error); + + if (folder != NULL) { + success = e_mail_folder_append_message_sync ( + folder, message, info, appended_uid, + cancellable, error); + g_object_unref (folder); + } + + return success; +} + +void +e_mail_session_append_to_local_folder (EMailSession *session, + EMailLocalFolder local_id, + CamelMimeMessage *message, + CamelMessageInfo *info, + gint io_priority, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *simple; + AsyncContext *context; + + g_return_if_fail (E_IS_MAIL_SESSION (session)); + g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message)); + + context = g_slice_new0 (AsyncContext); + context->local_id = local_id; + context->message = g_object_ref (message); + + if (info != NULL) + context->info = camel_message_info_ref (info); + + simple = g_simple_async_result_new ( + G_OBJECT (session), callback, user_data, + e_mail_session_append_to_local_folder); + + g_simple_async_result_set_check_cancellable (simple, cancellable); + + g_simple_async_result_set_op_res_gpointer ( + simple, context, (GDestroyNotify) async_context_free); + + g_simple_async_result_run_in_thread ( + simple, mail_session_append_to_local_folder_thread, + io_priority, cancellable); + + g_object_unref (simple); +} + +gboolean +e_mail_session_append_to_local_folder_finish (EMailSession *session, + GAsyncResult *result, + gchar **appended_uid, + GError **error) +{ + GSimpleAsyncResult *simple; + AsyncContext *context; + + g_return_val_if_fail ( + g_simple_async_result_is_valid ( + result, G_OBJECT (session), + e_mail_session_append_to_local_folder), FALSE); + + simple = G_SIMPLE_ASYNC_RESULT (result); + context = g_simple_async_result_get_op_res_gpointer (simple); + + if (appended_uid != NULL) { + *appended_uid = context->message_uid; + context->message_uid = NULL; + } + + /* Assume success unless a GError is set. */ + return !g_simple_async_result_propagate_error (simple, error); +} + +static void mail_session_handle_draft_headers_thread (GSimpleAsyncResult *simple, EMailSession *session, GCancellable *cancellable) diff --git a/libemail-engine/e-mail-session-utils.h b/libemail-engine/e-mail-session-utils.h index aec6a500e6..0c7cff3f97 100644 --- a/libemail-engine/e-mail-session-utils.h +++ b/libemail-engine/e-mail-session-utils.h @@ -32,6 +32,28 @@ typedef enum { } EMailError; GQuark e_mail_error_quark (void) G_GNUC_CONST; +gboolean e_mail_session_append_to_local_folder_sync + (EMailSession *session, + EMailLocalFolder local_id, + CamelMimeMessage *message, + CamelMessageInfo *info, + gchar **appended_uid, + GCancellable *cancellable, + GError **error); +void e_mail_session_append_to_local_folder + (EMailSession *session, + EMailLocalFolder local_id, + CamelMimeMessage *message, + CamelMessageInfo *info, + gint io_priority, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean e_mail_session_append_to_local_folder_finish + (EMailSession *session, + GAsyncResult *result, + gchar **appended_uid, + GError **error); gboolean e_mail_session_handle_draft_headers_sync (EMailSession *session, CamelMimeMessage *message, |