aboutsummaryrefslogtreecommitdiffstats
path: root/mail/e-mail-reader-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'mail/e-mail-reader-utils.c')
-rw-r--r--mail/e-mail-reader-utils.c119
1 files changed, 117 insertions, 2 deletions
diff --git a/mail/e-mail-reader-utils.c b/mail/e-mail-reader-utils.c
index 0a7dc8d421..81efa8fac2 100644
--- a/mail/e-mail-reader-utils.c
+++ b/mail/e-mail-reader-utils.c
@@ -73,6 +73,8 @@ struct _AsyncContext {
GtkPrintOperationAction print_action;
const gchar *filter_source;
gint filter_type;
+ gboolean replace;
+ gboolean keep_signature;
};
static void
@@ -817,7 +819,7 @@ e_mail_reader_open_selected (EMailReader *reader)
if (em_utils_folder_is_drafts (registry, folder) ||
em_utils_folder_is_outbox (registry, folder) ||
em_utils_folder_is_templates (registry, folder)) {
- em_utils_edit_messages (reader, folder, uids, TRUE, TRUE);
+ e_mail_reader_edit_messages (reader, folder, uids, TRUE, TRUE);
return uids->len;
}
@@ -849,7 +851,7 @@ e_mail_reader_open_selected (EMailReader *reader)
edits = g_ptr_array_new ();
g_ptr_array_add (edits, real_uid);
- em_utils_edit_messages (
+ e_mail_reader_edit_messages (
reader, real_folder, edits, TRUE, TRUE);
} else {
g_free (real_uid);
@@ -1270,6 +1272,119 @@ e_mail_reader_remove_duplicates (EMailReader *reader)
g_ptr_array_unref (uids);
}
+static void
+mail_reader_edit_messages_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ CamelFolder *folder;
+ EShell *shell;
+ EMailBackend *backend;
+ EActivity *activity;
+ EAlertSink *alert_sink;
+ GHashTable *hash_table;
+ GHashTableIter iter;
+ gpointer key, value;
+ AsyncContext *async_context;
+ GError *local_error = NULL;
+
+ folder = CAMEL_FOLDER (source_object);
+ async_context = (AsyncContext *) user_data;
+
+ activity = async_context->activity;
+ alert_sink = e_activity_get_alert_sink (activity);
+
+ hash_table = e_mail_folder_get_multiple_messages_finish (
+ folder, result, &local_error);
+
+ /* Sanity check. */
+ g_return_if_fail (
+ ((hash_table != NULL) && (local_error == NULL)) ||
+ ((hash_table == NULL) && (local_error != NULL)));
+
+ if (e_activity_handle_cancellation (activity, local_error)) {
+ g_error_free (local_error);
+ goto exit;
+
+ } else if (local_error != NULL) {
+ e_alert_submit (
+ alert_sink,
+ "mail:get-multiple-messages",
+ local_error->message, NULL);
+ g_error_free (local_error);
+ goto exit;
+ }
+
+ backend = e_mail_reader_get_backend (async_context->reader);
+ shell = e_shell_backend_get_shell (E_SHELL_BACKEND (backend));
+
+ /* Open each message in its own composer window. */
+
+ g_hash_table_iter_init (&iter, hash_table);
+
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ EMsgComposer *composer;
+ CamelMimeMessage *message;
+ const gchar *message_uid = NULL;
+
+ if (async_context->replace)
+ message_uid = (const gchar *) key;
+
+ message = CAMEL_MIME_MESSAGE (value);
+
+ camel_medium_remove_header (
+ CAMEL_MEDIUM (message), "X-Mailer");
+
+ composer = em_utils_edit_message (
+ shell, folder, message, message_uid,
+ async_context->keep_signature);
+
+ e_mail_reader_composer_created (
+ async_context->reader, composer, message);
+ }
+
+ g_hash_table_unref (hash_table);
+
+ e_activity_set_state (activity, E_ACTIVITY_COMPLETED);
+
+exit:
+ async_context_free (async_context);
+}
+
+void
+e_mail_reader_edit_messages (EMailReader *reader,
+ CamelFolder *folder,
+ GPtrArray *uids,
+ gboolean replace,
+ gboolean keep_signature)
+{
+ EActivity *activity;
+ GCancellable *cancellable;
+ AsyncContext *async_context;
+
+ g_return_if_fail (E_IS_MAIL_READER (reader));
+ g_return_if_fail (CAMEL_IS_FOLDER (folder));
+ g_return_if_fail (uids != NULL);
+
+ activity = e_mail_reader_new_activity (reader);
+ cancellable = e_activity_get_cancellable (activity);
+
+ async_context = g_slice_new0 (AsyncContext);
+ async_context->activity = g_object_ref (activity);
+ async_context->reader = g_object_ref (reader);
+ async_context->replace = replace;
+ async_context->keep_signature = keep_signature;
+
+ e_mail_folder_get_multiple_messages (
+ folder, uids,
+ G_PRIORITY_DEFAULT,
+ cancellable,
+ mail_reader_edit_messages_cb,
+ async_context);
+
+ g_object_unref (activity);
+}
+
/* Helper for e_mail_reader_reply_to_message()
* XXX This function belongs in e-html-utils.c */
static gboolean