aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2010-10-31 02:23:01 +0800
committerMatthew Barnes <mbarnes@redhat.com>2010-10-31 09:01:11 +0800
commit831d6dca44ecaa272b4ef5e1cfc29578e7ba5435 (patch)
treecbb127fed5476107f8808bf08328ca095b2fc2de
parentc2fccbbb626c04ec2dbaa80dd5224280041d8703 (diff)
downloadgsoc2013-evolution-831d6dca44ecaa272b4ef5e1cfc29578e7ba5435.tar
gsoc2013-evolution-831d6dca44ecaa272b4ef5e1cfc29578e7ba5435.tar.gz
gsoc2013-evolution-831d6dca44ecaa272b4ef5e1cfc29578e7ba5435.tar.bz2
gsoc2013-evolution-831d6dca44ecaa272b4ef5e1cfc29578e7ba5435.tar.lz
gsoc2013-evolution-831d6dca44ecaa272b4ef5e1cfc29578e7ba5435.tar.xz
gsoc2013-evolution-831d6dca44ecaa272b4ef5e1cfc29578e7ba5435.tar.zst
gsoc2013-evolution-831d6dca44ecaa272b4ef5e1cfc29578e7ba5435.zip
Kill mail_append_mail().
Use e_mail_folder_append_message() instead.
-rw-r--r--mail/e-mail-folder-utils.c87
-rw-r--r--mail/e-mail-folder-utils.h7
-rw-r--r--mail/e-mail-session.c24
-rw-r--r--mail/em-composer-utils.c21
-rw-r--r--mail/mail-ops.c86
-rw-r--r--mail/mail-ops.h5
-rw-r--r--plugins/templates/templates.c6
7 files changed, 92 insertions, 144 deletions
diff --git a/mail/e-mail-folder-utils.c b/mail/e-mail-folder-utils.c
index 7186589849..f2ba207e01 100644
--- a/mail/e-mail-folder-utils.c
+++ b/mail/e-mail-folder-utils.c
@@ -27,15 +27,19 @@
typedef struct _AsyncContext AsyncContext;
struct _AsyncContext {
- GCancellable *cancellable;
+ CamelMimeMessage *message;
+ CamelMessageInfo *info;
gchar *message_uid;
};
static void
async_context_free (AsyncContext *context)
{
- if (context->cancellable != NULL)
- g_object_unref (context->cancellable);
+ if (context->message != NULL)
+ g_object_unref (context->message);
+
+ if (context->info != NULL)
+ camel_message_info_free (context->info);
g_free (context->message_uid);
@@ -43,28 +47,58 @@ async_context_free (AsyncContext *context)
}
static void
-mail_folder_append_message_ready (CamelFolder *folder,
- GAsyncResult *result,
- GSimpleAsyncResult *simple)
+mail_folder_append_message_thread (GSimpleAsyncResult *simple,
+ GObject *object,
+ GCancellable *cancellable)
{
AsyncContext *context;
GError *error = NULL;
context = g_simple_async_result_get_op_res_gpointer (simple);
- camel_folder_append_message_finish (
- folder, result, &context->message_uid, &error);
+ e_mail_folder_append_message_sync (
+ CAMEL_FOLDER (object), context->message,
+ context->info, &context->message_uid,
+ cancellable, &error);
if (error != NULL) {
g_simple_async_result_set_from_error (simple, error);
g_error_free (error);
}
+}
+
+gboolean
+e_mail_folder_append_message_sync (CamelFolder *folder,
+ CamelMimeMessage *message,
+ CamelMessageInfo *info,
+ gchar **appended_uid,
+ GCancellable *cancellable,
+ GError **error)
+{
+ CamelMedium *medium;
+ gboolean success;
- camel_operation_pop_message (context->cancellable);
+ g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
+ g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), FALSE);
- g_simple_async_result_complete (simple);
+ medium = CAMEL_MEDIUM (message);
- g_object_unref (simple);
+ camel_operation_push_message (
+ cancellable,
+ _("Saving message to folder '%s'"),
+ camel_folder_get_full_name (folder));
+
+ if (camel_medium_get_header (medium, "X-Mailer") == NULL)
+ camel_medium_set_header (medium, "X-Mailer", X_MAILER);
+
+ camel_mime_message_set_date (message, CAMEL_MESSAGE_DATE_CURRENT, 0);
+
+ success = camel_folder_append_message_sync (
+ folder, message, info, appended_uid, cancellable, error);
+
+ camel_operation_pop_message (cancellable);
+
+ return success;
}
void
@@ -78,17 +112,15 @@ e_mail_folder_append_message (CamelFolder *folder,
{
GSimpleAsyncResult *simple;
AsyncContext *context;
- CamelMedium *medium;
g_return_if_fail (CAMEL_IS_FOLDER (folder));
g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message));
- medium = CAMEL_MEDIUM (message);
-
context = g_slice_new0 (AsyncContext);
+ context->message = g_object_ref (message);
- if (G_IS_CANCELLABLE (cancellable))
- context->cancellable = g_object_ref (cancellable);
+ if (info != NULL)
+ context->info = camel_message_info_ref (info);
simple = g_simple_async_result_new (
G_OBJECT (folder), callback, user_data,
@@ -97,20 +129,11 @@ e_mail_folder_append_message (CamelFolder *folder,
g_simple_async_result_set_op_res_gpointer (
simple, context, (GDestroyNotify) async_context_free);
- camel_operation_push_message (
- context->cancellable,
- _("Saving message to folder '%s'"),
- camel_folder_get_full_name (folder));
-
- if (camel_medium_get_header (medium, "X-Mailer") == NULL)
- camel_medium_set_header (medium, "X-Mailer", X_MAILER);
-
- camel_mime_message_set_date (message, CAMEL_MESSAGE_DATE_CURRENT, 0);
+ g_simple_async_result_run_in_thread (
+ simple, mail_folder_append_message_thread,
+ io_priority, cancellable);
- camel_folder_append_message (
- folder, message, info, io_priority,
- context->cancellable, (GAsyncReadyCallback)
- mail_folder_append_message_ready, simple);
+ g_object_unref (simple);
}
gboolean
@@ -130,13 +153,11 @@ e_mail_folder_append_message_finish (CamelFolder *folder,
simple = G_SIMPLE_ASYNC_RESULT (result);
context = g_simple_async_result_get_op_res_gpointer (simple);
- if (g_simple_async_result_propagate_error (simple, error))
- return FALSE;
-
if (appended_uid != NULL) {
*appended_uid = context->message_uid;
context->message_uid = NULL;
}
- return TRUE;
+ /* Assume success unless a GError is set. */
+ return !g_simple_async_result_propagate_error (simple, error);
}
diff --git a/mail/e-mail-folder-utils.h b/mail/e-mail-folder-utils.h
index c5d3fefe13..7872f3e146 100644
--- a/mail/e-mail-folder-utils.h
+++ b/mail/e-mail-folder-utils.h
@@ -25,6 +25,13 @@
G_BEGIN_DECLS
+gboolean e_mail_folder_append_message_sync
+ (CamelFolder *folder,
+ CamelMimeMessage *message,
+ CamelMessageInfo *info,
+ gchar **appended_uid,
+ GCancellable *cancellable,
+ GError **error);
void e_mail_folder_append_message (CamelFolder *folder,
CamelMimeMessage *message,
CamelMessageInfo *info,
diff --git a/mail/e-mail-session.c b/mail/e-mail-session.c
index 7b726cfec5..debaf28cea 100644
--- a/mail/e-mail-session.c
+++ b/mail/e-mail-session.c
@@ -51,6 +51,7 @@
#include "e-util/e-alert-dialog.h"
#include "e-util/e-util-private.h"
+#include "e-mail-folder-utils.h"
#include "e-mail-local.h"
#include "e-mail-session.h"
#include "em-composer-utils.h"
@@ -386,18 +387,16 @@ forward_to_flush_outbox_cb (EMailSession *session)
static void
ms_forward_to_cb (CamelFolder *folder,
- CamelMimeMessage *msg,
- CamelMessageInfo *info,
- gint queued,
- const gchar *appended_uid,
- gpointer data)
+ GAsyncResult *result,
+ EMailSession *session)
{
- EMailSession *session = E_MAIL_SESSION (data);
GConfClient *client;
- client = gconf_client_get_default ();
+ /* FIXME Poor error handling. */
+ if (!e_mail_folder_append_message_finish (folder, result, NULL, NULL))
+ return;
- camel_message_info_free (info);
+ client = gconf_client_get_default ();
/* do not call mail send immediately, just pile them all in the outbox */
if (preparing_flush ||
@@ -926,8 +925,13 @@ mail_session_forward_to (CamelSession *session,
out_folder = e_mail_local_get_folder (E_MAIL_LOCAL_FOLDER_OUTBOX);
camel_message_info_set_flags (
info, CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN);
- mail_append_mail (
- out_folder, forward, info, ms_forward_to_cb, session);
+
+ /* FIXME Pass a GCancellable. */
+ e_mail_folder_append_message (
+ out_folder, forward, info, G_PRIORITY_DEFAULT, NULL,
+ (GAsyncReadyCallback) ms_forward_to_cb, session);
+
+ camel_message_info_free (info);
return TRUE;
}
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index f084155362..02eb039916 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -1665,15 +1665,13 @@ em_utils_handle_receipt (EMailSession *session,
static void
em_utils_receipt_done (CamelFolder *folder,
- CamelMimeMessage *msg,
- CamelMessageInfo *info,
- gint queued,
- const gchar *appended_uid,
- gpointer data)
+ GAsyncResult *result,
+ EMailSession *session)
{
- EMailSession *session = E_MAIL_SESSION (data);
+ /* FIXME Poor error handling. */
+ if (!e_mail_folder_append_message_finish (folder, result, NULL, NULL))
+ return;
- camel_message_info_free (info);
mail_send (session);
}
@@ -1812,8 +1810,13 @@ em_utils_send_receipt (EMailSession *session,
out_folder = e_mail_local_get_folder (E_MAIL_LOCAL_FOLDER_OUTBOX);
camel_message_info_set_flags (
info, CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN);
- mail_append_mail (
- out_folder, receipt, info, em_utils_receipt_done, session);
+
+ /* FIXME Pass a GCancellable. */
+ e_mail_folder_append_message (
+ out_folder, receipt, info, G_PRIORITY_DEFAULT, NULL,
+ (GAsyncReadyCallback) em_utils_receipt_done, session);
+
+ camel_message_info_free (info);
}
/* Replying to messages... */
diff --git a/mail/mail-ops.c b/mail/mail-ops.c
index ffaa7e41af..ccbd934fe7 100644
--- a/mail/mail-ops.c
+++ b/mail/mail-ops.c
@@ -919,92 +919,6 @@ mail_send_queue (EMailSession *session,
mail_msg_unordered_push (m);
}
-/* ** APPEND MESSAGE TO FOLDER ******************************************** */
-
-struct _append_msg {
- MailMsg base;
-
- CamelFolder *folder;
- CamelMimeMessage *message;
- CamelMessageInfo *info;
- gchar *appended_uid;
-
- void (*done)(CamelFolder *folder, CamelMimeMessage *msg, CamelMessageInfo *info, gint ok, const gchar *appended_uid, gpointer data);
- gpointer data;
-};
-
-static gchar *
-append_mail_desc (struct _append_msg *m)
-{
- return g_strdup_printf (_("Saving message to folder '%s'"), camel_folder_get_full_name (m->folder));
-}
-
-static void
-append_mail_exec (struct _append_msg *m,
- GCancellable *cancellable,
- GError **error)
-{
- camel_mime_message_set_date (
- m->message, CAMEL_MESSAGE_DATE_CURRENT, 0);
-
- camel_folder_append_message_sync (
- m->folder, m->message,
- m->info, &m->appended_uid,
- cancellable, error);
-}
-
-static void
-append_mail_done (struct _append_msg *m)
-{
- if (m->done)
- m->done (
- m->folder, m->message,
- m->info, m->base.error == NULL,
- m->appended_uid, m->data);
-}
-
-static void
-append_mail_free (struct _append_msg *m)
-{
- g_object_unref (m->message);
- g_object_unref (m->folder);
- g_free (m->appended_uid);
-}
-
-static MailMsgInfo append_mail_info = {
- sizeof (struct _append_msg),
- (MailMsgDescFunc) append_mail_desc,
- (MailMsgExecFunc) append_mail_exec,
- (MailMsgDoneFunc) append_mail_done,
- (MailMsgFreeFunc) append_mail_free
-};
-
-void
-mail_append_mail (CamelFolder *folder, CamelMimeMessage *message, CamelMessageInfo *info,
- void (*done)(CamelFolder *folder, CamelMimeMessage *msg, CamelMessageInfo *info, gint ok, const gchar *appended_uid, gpointer data),
- gpointer data)
-{
- struct _append_msg *m;
-
- g_return_if_fail (CAMEL_IS_FOLDER (folder));
- g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message));
-
- if (!camel_medium_get_header (CAMEL_MEDIUM (message), "X-Mailer"))
- camel_medium_set_header (CAMEL_MEDIUM (message), "X-Mailer", x_mailer);
-
- m = mail_msg_new (&append_mail_info);
- m->folder = folder;
- g_object_ref (folder);
- m->message = message;
- g_object_ref (message);
- m->info = info;
-
- m->done = done;
- m->data = data;
-
- mail_msg_unordered_push (m);
-}
-
/* ** TRANSFER MESSAGES **************************************************** */
struct _transfer_msg {
diff --git a/mail/mail-ops.h b/mail/mail-ops.h
index fbcf6bf826..583c18e34f 100644
--- a/mail/mail-ops.h
+++ b/mail/mail-ops.h
@@ -32,11 +32,6 @@ G_BEGIN_DECLS
#include <mail/mail-mt.h>
#include <mail/e-mail-session.h>
-void mail_append_mail (CamelFolder *folder, CamelMimeMessage *message, CamelMessageInfo *info,
- void (*done)(CamelFolder *folder, CamelMimeMessage *msg, CamelMessageInfo *info, gint ok,
- const gchar *appended_uid, gpointer data),
- gpointer data);
-
void mail_transfer_messages (EMailSession *session,
CamelFolder *source,
GPtrArray *uids,
diff --git a/plugins/templates/templates.c b/plugins/templates/templates.c
index 815ee69882..bca45f040f 100644
--- a/plugins/templates/templates.c
+++ b/plugins/templates/templates.c
@@ -31,6 +31,7 @@
#include <e-util/e-config.h>
+#include <mail/e-mail-folder-utils.h>
#include <mail/e-mail-local.h>
#include <mail/e-mail-reader.h>
#include <mail/e-mail-session.h>
@@ -710,7 +711,10 @@ got_message_draft_cb (EMsgComposer *composer,
camel_message_info_set_flags (
info, CAMEL_MESSAGE_SEEN | CAMEL_MESSAGE_DRAFT, ~0);
- mail_append_mail (folder, message, info, NULL, composer);
+ /* FIXME No async callback, so... hope for the best? */
+ e_mail_folder_append_message (
+ folder, message, info, G_PRIORITY_DEFAULT,
+ NULL, (GAsyncReadyCallback) NULL, NULL);
g_object_unref (message);
}