aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2012-08-15 06:20:48 +0800
committerMatthew Barnes <mbarnes@redhat.com>2012-08-15 23:44:29 +0800
commitcbf51737faf61d88c3b7c5349b5db635b892c2c1 (patch)
tree0bc436489470b182a045e34679dab07bdf97f08f
parent3aa74ebe41c3d30c0e22dabd2c27c215a90d0c73 (diff)
downloadgsoc2013-evolution-cbf51737faf61d88c3b7c5349b5db635b892c2c1.tar
gsoc2013-evolution-cbf51737faf61d88c3b7c5349b5db635b892c2c1.tar.gz
gsoc2013-evolution-cbf51737faf61d88c3b7c5349b5db635b892c2c1.tar.bz2
gsoc2013-evolution-cbf51737faf61d88c3b7c5349b5db635b892c2c1.tar.lz
gsoc2013-evolution-cbf51737faf61d88c3b7c5349b5db635b892c2c1.tar.xz
gsoc2013-evolution-cbf51737faf61d88c3b7c5349b5db635b892c2c1.tar.zst
gsoc2013-evolution-cbf51737faf61d88c3b7c5349b5db635b892c2c1.zip
Add e_mail_session_append_to_local_folder().
Asynchronous + synchronous convenience functions. Uses the EMailLocalFolder enumeration to specify a well-known folder.
-rw-r--r--libemail-engine/e-mail-session-utils.c120
-rw-r--r--libemail-engine/e-mail-session-utils.h22
-rw-r--r--mail/em-composer-utils.c20
-rw-r--r--modules/mdn/evolution-mdn.c31
-rw-r--r--plugins/templates/templates.c16
5 files changed, 172 insertions, 37 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,
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index b107745ee9..c01ec85913 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -874,7 +874,7 @@ em_utils_composer_save_to_drafts_cb (EMsgComposer *composer,
}
static void
-composer_save_to_outbox_completed (CamelFolder *outbox_folder,
+composer_save_to_outbox_completed (EMailSession *session,
GAsyncResult *result,
AsyncContext *context)
{
@@ -883,8 +883,8 @@ composer_save_to_outbox_completed (CamelFolder *outbox_folder,
alert_sink = e_activity_get_alert_sink (context->activity);
- e_mail_folder_append_message_finish (
- outbox_folder, result, NULL, &error);
+ e_mail_session_append_to_local_folder_finish (
+ session, result, NULL, &error);
if (e_activity_handle_cancellation (context->activity, error)) {
g_error_free (error);
@@ -901,7 +901,7 @@ composer_save_to_outbox_completed (CamelFolder *outbox_folder,
/* special processing for Outbox folder */
manage_x_evolution_replace_outbox (
- context->composer, context->session, context->message,
+ context->composer, session, context->message,
e_activity_get_cancellable (context->activity));
e_activity_set_state (context->activity, E_ACTIVITY_COMPLETED);
@@ -923,28 +923,22 @@ em_utils_composer_save_to_outbox_cb (EMsgComposer *composer,
EMailSession *session)
{
AsyncContext *context;
- CamelFolder *outbox_folder;
CamelMessageInfo *info;
GCancellable *cancellable;
context = g_slice_new0 (AsyncContext);
context->message = g_object_ref (message);
- context->session = g_object_ref (session);
context->composer = g_object_ref (composer);
context->activity = g_object_ref (activity);
cancellable = e_activity_get_cancellable (activity);
- outbox_folder =
- e_mail_session_get_local_folder (
- session, E_MAIL_LOCAL_FOLDER_OUTBOX);
-
info = camel_message_info_new (NULL);
camel_message_info_set_flags (info, CAMEL_MESSAGE_SEEN, ~0);
- e_mail_folder_append_message (
- outbox_folder, message, info,
- G_PRIORITY_DEFAULT, cancellable,
+ e_mail_session_append_to_local_folder (
+ session, E_MAIL_LOCAL_FOLDER_OUTBOX,
+ message, info, G_PRIORITY_DEFAULT, cancellable,
(GAsyncReadyCallback) composer_save_to_outbox_completed,
context);
diff --git a/modules/mdn/evolution-mdn.c b/modules/mdn/evolution-mdn.c
index cd6d3edac7..03abc00d24 100644
--- a/modules/mdn/evolution-mdn.c
+++ b/modules/mdn/evolution-mdn.c
@@ -24,8 +24,7 @@
#include <libevolution-utils/e-alert-dialog.h>
-#include <libemail-engine/e-mail-folder-utils.h>
-#include <libemail-engine/e-mail-session.h>
+#include <libemail-engine/e-mail-session-utils.h>
#include <mail/em-utils.h>
#include <mail/e-mail-reader.h>
@@ -187,15 +186,22 @@ mdn_get_disposition (MdnActionMode action_mode,
}
static void
-mdn_receipt_done (CamelFolder *folder,
+mdn_receipt_done (EMailSession *session,
GAsyncResult *result,
- EMailSession *session)
+ gpointer user_data)
{
- /* FIXME Poor error handling. */
- if (e_mail_folder_append_message_finish (folder, result, NULL, NULL))
- mail_send (session);
+ GError *error = NULL;
+
+ e_mail_session_append_to_local_folder_finish (
+ session, result, NULL, &error);
- g_object_unref (session);
+ if (error == NULL) {
+ mail_send (session);
+ } else {
+ /* FIXME Poor error handling. */
+ g_warning ("%s: %s", G_STRFUNC, error->message);
+ g_error_free (error);
+ }
}
static void
@@ -218,7 +224,6 @@ mdn_notify_sender (ESource *source,
CamelContentType *type;
CamelInternetAddress *address;
CamelStream *stream;
- CamelFolder *out_folder;
CamelMessageInfo *receipt_info;
EMailBackend *backend;
EMailSession *session;
@@ -420,15 +425,13 @@ mdn_notify_sender (ESource *source,
/* Send the receipt. */
receipt_info = camel_message_info_new (NULL);
- out_folder =
- e_mail_session_get_local_folder (
- session, E_MAIL_LOCAL_FOLDER_OUTBOX);
camel_message_info_set_flags (
receipt_info, CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN);
/* FIXME Pass a GCancellable. */
- e_mail_folder_append_message (
- out_folder, receipt, receipt_info, G_PRIORITY_DEFAULT,
+ e_mail_session_append_to_local_folder (
+ session, E_MAIL_LOCAL_FOLDER_OUTBOX,
+ receipt, receipt_info, G_PRIORITY_DEFAULT,
NULL, (GAsyncReadyCallback) mdn_receipt_done,
g_object_ref (session));
diff --git a/plugins/templates/templates.c b/plugins/templates/templates.c
index 4359af01b9..f218bce9a4 100644
--- a/plugins/templates/templates.c
+++ b/plugins/templates/templates.c
@@ -37,8 +37,7 @@
#include <shell/e-shell-view.h>
-#include <libemail-engine/e-mail-folder-utils.h>
-#include <libemail-engine/e-mail-session.h>
+#include <libemail-engine/e-mail-session-utils.h>
#include <libemail-engine/mail-ops.h>
#include <mail/e-mail-reader.h>
@@ -1157,7 +1156,6 @@ got_message_draft_cb (EMsgComposer *composer,
EMailSession *session;
CamelMimeMessage *message;
CamelMessageInfo *info;
- CamelFolder *folder;
GError *error = NULL;
message = e_msg_composer_get_message_draft_finish (
@@ -1188,10 +1186,6 @@ got_message_draft_cb (EMsgComposer *composer,
backend = E_MAIL_BACKEND (shell_backend);
session = e_mail_backend_get_session (backend);
- /* Get the templates folder and all UIDs of the messages there. */
- folder = e_mail_session_get_local_folder (
- session, E_MAIL_LOCAL_FOLDER_TEMPLATES);
-
info = camel_message_info_new (NULL);
/* The last argument is a bit mask which tells the function
@@ -1200,9 +1194,11 @@ got_message_draft_cb (EMsgComposer *composer,
camel_message_info_set_flags (
info, CAMEL_MESSAGE_SEEN | CAMEL_MESSAGE_DRAFT, ~0);
- /* FIXME No async callback, so... hope for the best? */
- e_mail_folder_append_message (
- folder, message, info, G_PRIORITY_DEFAULT,
+ /* FIXME Should submit an EActivity for this
+ * operation, same as saving to Outbox. */
+ e_mail_session_append_to_local_folder (
+ session, E_MAIL_LOCAL_FOLDER_TEMPLATES,
+ message, info, G_PRIORITY_DEFAULT,
NULL, (GAsyncReadyCallback) NULL, NULL);
g_object_unref (message);