aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mail/e-mail-reader-utils.c206
-rw-r--r--mail/e-mail-reader-utils.h4
-rw-r--r--mail/e-mail-reader.c8
-rw-r--r--mail/em-composer-utils.c279
-rw-r--r--mail/em-composer-utils.h9
5 files changed, 256 insertions, 250 deletions
diff --git a/mail/e-mail-reader-utils.c b/mail/e-mail-reader-utils.c
index 81efa8fac2..d1b8d88e8a 100644
--- a/mail/e-mail-reader-utils.c
+++ b/mail/e-mail-reader-utils.c
@@ -65,11 +65,13 @@ struct _AsyncContext {
EMailPartList *part_list;
EMailReader *reader;
CamelInternetAddress *address;
+ GPtrArray *uids;
gchar *folder_name;
gchar *message_uid;
EMailReplyType reply_type;
EMailReplyStyle reply_style;
+ EMailForwardStyle forward_style;
GtkPrintOperationAction print_action;
const gchar *filter_source;
gint filter_type;
@@ -87,6 +89,9 @@ async_context_free (AsyncContext *async_context)
g_clear_object (&async_context->reader);
g_clear_object (&async_context->address);
+ if (async_context->uids != NULL)
+ g_ptr_array_unref (async_context->uids);
+
g_free (async_context->folder_name);
g_free (async_context->message_uid);
@@ -1385,6 +1390,207 @@ e_mail_reader_edit_messages (EMailReader *reader,
g_object_unref (activity);
}
+static void
+mail_reader_forward_attachment_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ CamelFolder *folder;
+ EMailBackend *backend;
+ EActivity *activity;
+ EAlertSink *alert_sink;
+ CamelMimePart *part;
+ CamelDataWrapper *content;
+ EMsgComposer *composer;
+ gchar *subject = NULL;
+ 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);
+
+ part = e_mail_folder_build_attachment_finish (
+ folder, result, &subject, &local_error);
+
+ /* Sanity check. */
+ g_return_if_fail (
+ ((part != NULL) && (local_error == NULL)) ||
+ ((part == NULL) && (local_error != NULL)));
+
+ if (e_activity_handle_cancellation (activity, local_error)) {
+ g_warn_if_fail (subject == NULL);
+ g_error_free (local_error);
+ goto exit;
+
+ } else if (local_error != NULL) {
+ g_warn_if_fail (subject == 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);
+
+ composer = em_utils_forward_attachment (
+ backend, part, subject, folder, async_context->uids);
+
+ content = camel_medium_get_content (CAMEL_MEDIUM (part));
+ if (CAMEL_IS_MIME_MESSAGE (content)) {
+ e_mail_reader_composer_created (
+ async_context->reader, composer,
+ CAMEL_MIME_MESSAGE (content));
+ } else {
+ /* XXX What to do for the multipart/digest case?
+ * Extract the first message from the digest, or
+ * change the argument type to CamelMimePart and
+ * just pass the whole digest through?
+ *
+ * This signal is primarily serving EMailBrowser,
+ * which can only forward one message at a time.
+ * So for the moment it doesn't matter, but still
+ * something to consider. */
+ e_mail_reader_composer_created (
+ async_context->reader, composer, NULL);
+ }
+
+ e_activity_set_state (activity, E_ACTIVITY_COMPLETED);
+
+ g_object_unref (part);
+ g_free (subject);
+
+exit:
+ async_context_free (async_context);
+}
+
+static void
+mail_reader_forward_messages_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ CamelFolder *folder;
+ 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);
+
+ backend = e_mail_reader_get_backend (async_context->reader);
+
+ 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;
+ }
+
+ /* Create a new composer window for each message. */
+
+ 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;
+
+ message_uid = (const gchar *) key;
+ message = CAMEL_MIME_MESSAGE (value);
+
+ composer = em_utils_forward_message (
+ backend, message,
+ async_context->forward_style,
+ folder, message_uid);
+
+ 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_forward_messages (EMailReader *reader,
+ CamelFolder *folder,
+ GPtrArray *uids,
+ EMailForwardStyle style)
+{
+ 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->uids = g_ptr_array_ref (uids);
+ async_context->forward_style = style;
+
+ switch (style) {
+ case E_MAIL_FORWARD_STYLE_ATTACHED:
+ e_mail_folder_build_attachment (
+ folder, uids,
+ G_PRIORITY_DEFAULT,
+ cancellable,
+ mail_reader_forward_attachment_cb,
+ async_context);
+ break;
+
+ case E_MAIL_FORWARD_STYLE_INLINE:
+ case E_MAIL_FORWARD_STYLE_QUOTED:
+ e_mail_folder_get_multiple_messages (
+ folder, uids,
+ G_PRIORITY_DEFAULT,
+ cancellable,
+ mail_reader_forward_messages_cb,
+ async_context);
+ break;
+
+ default:
+ g_warn_if_reached ();
+ }
+
+ g_object_unref (activity);
+}
+
/* Helper for e_mail_reader_reply_to_message()
* XXX This function belongs in e-html-utils.c */
static gboolean
diff --git a/mail/e-mail-reader-utils.h b/mail/e-mail-reader-utils.h
index 1b91a8f1fc..692622c134 100644
--- a/mail/e-mail-reader-utils.h
+++ b/mail/e-mail-reader-utils.h
@@ -73,6 +73,10 @@ void e_mail_reader_edit_messages (EMailReader *reader,
GPtrArray *uids,
gboolean replace,
gboolean keep_signature);
+void e_mail_reader_forward_messages (EMailReader *reader,
+ CamelFolder *folder,
+ GPtrArray *uids,
+ EMailForwardStyle style);
void e_mail_reader_reply_to_message (EMailReader *reader,
CamelMimeMessage *message,
EMailReplyType reply_type);
diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c
index 4730ac5b3b..f63908cd54 100644
--- a/mail/e-mail-reader.c
+++ b/mail/e-mail-reader.c
@@ -656,7 +656,7 @@ action_mail_forward_cb (GtkAction *action,
g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free);
if (em_utils_ask_open_many (window, uids->len))
- em_utils_forward_messages (
+ e_mail_reader_forward_messages (
reader, folder, uids,
e_mail_reader_get_forward_style (reader));
@@ -681,7 +681,7 @@ action_mail_forward_attached_cb (GtkAction *action,
g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free);
if (em_utils_ask_open_many (window, uids->len))
- em_utils_forward_messages (
+ e_mail_reader_forward_messages (
reader, folder, uids,
E_MAIL_FORWARD_STYLE_ATTACHED);
@@ -706,7 +706,7 @@ action_mail_forward_inline_cb (GtkAction *action,
g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free);
if (em_utils_ask_open_many (window, uids->len))
- em_utils_forward_messages (
+ e_mail_reader_forward_messages (
reader, folder, uids,
E_MAIL_FORWARD_STYLE_INLINE);
@@ -731,7 +731,7 @@ action_mail_forward_quoted_cb (GtkAction *action,
g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free);
if (em_utils_ask_open_many (window, uids->len))
- em_utils_forward_messages (
+ e_mail_reader_forward_messages (
reader, folder, uids,
E_MAIL_FORWARD_STYLE_QUOTED);
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index d6c85f3968..b061c85dd0 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -75,9 +75,6 @@ struct _AsyncContext {
EMailSession *session;
EMsgComposer *composer;
EActivity *activity;
- EMailReader *reader;
- GPtrArray *ptr_array;
- EMailForwardStyle style;
gchar *folder_uri;
gchar *message_uid;
};
@@ -96,10 +93,6 @@ async_context_free (AsyncContext *async_context)
g_clear_object (&async_context->session);
g_clear_object (&async_context->composer);
g_clear_object (&async_context->activity);
- g_clear_object (&async_context->reader);
-
- if (async_context->ptr_array != NULL)
- g_ptr_array_unref (async_context->ptr_array);
g_free (async_context->folder_uri);
g_free (async_context->message_uid);
@@ -1619,110 +1612,6 @@ setup_forward_attached_callbacks (EMsgComposer *composer,
}
static EMsgComposer *
-forward_attached (EMailBackend *backend,
- CamelFolder *folder,
- GPtrArray *uids,
- CamelMimePart *part,
- gchar *subject)
-{
- EShell *shell;
- EMsgComposer *composer;
-
- shell = e_shell_backend_get_shell (E_SHELL_BACKEND (backend));
-
- composer = create_new_composer (shell, subject, folder);
-
- e_msg_composer_attach (composer, part);
-
- if (uids)
- setup_forward_attached_callbacks (composer, folder, uids);
-
- composer_set_no_change (composer);
-
- gtk_widget_show (GTK_WIDGET (composer));
-
- return composer;
-}
-
-static void
-forward_attached_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
-{
- CamelFolder *folder;
- EMailBackend *backend;
- EActivity *activity;
- EAlertSink *alert_sink;
- CamelMimePart *part;
- CamelDataWrapper *content;
- EMsgComposer *composer;
- gchar *subject = NULL;
- 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);
-
- part = e_mail_folder_build_attachment_finish (
- folder, result, &subject, &local_error);
-
- /* Sanity check. */
- g_return_if_fail (
- ((part != NULL) && (local_error == NULL)) ||
- ((part == NULL) && (local_error != NULL)));
-
- if (e_activity_handle_cancellation (activity, local_error)) {
- g_warn_if_fail (subject == NULL);
- g_error_free (local_error);
- goto exit;
-
- } else if (local_error != NULL) {
- g_warn_if_fail (subject == 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);
-
- composer = forward_attached (
- backend, folder, async_context->ptr_array, part, subject);
-
- content = camel_medium_get_content (CAMEL_MEDIUM (part));
- if (CAMEL_IS_MIME_MESSAGE (content)) {
- e_mail_reader_composer_created (
- async_context->reader, composer,
- CAMEL_MIME_MESSAGE (content));
- } else {
- /* XXX What to do for the multipart/digest case?
- * Extract the first message from the digest, or
- * change the argument type to CamelMimePart and
- * just pass the whole digest through?
- *
- * This signal is primarily serving EMailBrowser,
- * which can only forward one message at a time.
- * So for the moment it doesn't matter, but still
- * something to consider. */
- e_mail_reader_composer_created (
- async_context->reader, composer, NULL);
- }
-
- e_activity_set_state (activity, E_ACTIVITY_COMPLETED);
-
- g_object_unref (part);
- g_free (subject);
-
-exit:
- async_context_free (async_context);
-}
-
-static EMsgComposer *
forward_non_attached (EMailBackend *backend,
CamelFolder *folder,
const gchar *uid,
@@ -1800,8 +1689,21 @@ forward_non_attached (EMailBackend *backend,
* @folder: a #CamelFolder, or %NULL
* @uid: the UID of %message, or %NULL
*
- * Forwards a message in the given style. See em_utils_forward_messages()
- * for more details about forwarding styles.
+ * Forwards @message in the given @style.
+ *
+ * If @style is #E_MAIL_FORWARD_STYLE_ATTACHED, the new message is
+ * created as follows. If there is more than a single message in @uids,
+ * a multipart/digest will be constructed and attached to a new composer
+ * window preset with the appropriate header defaults for forwarding the
+ * first message in the list. If only one message is to be forwarded,
+ * it is forwarded as a simple message/rfc822 attachment.
+ *
+ * If @style is #E_MAIL_FORWARD_STYLE_INLINE, each message is forwarded
+ * in its own composer window in 'inline' form.
+ *
+ * If @style is #E_MAIL_FORWARD_STYLE_QUOTED, each message is forwarded
+ * in its own composer window in 'quoted' form (each line starting with
+ * a "> ").
**/
EMsgComposer *
em_utils_forward_message (EMailBackend *backend,
@@ -1823,8 +1725,8 @@ em_utils_forward_message (EMailBackend *backend,
part = mail_tool_make_message_attachment (message);
subject = mail_tool_generate_forward_subject (message);
- composer = forward_attached (
- backend, NULL, NULL, part, subject);
+ composer = em_utils_forward_attachment (
+ backend, part, subject, NULL, NULL);
g_object_unref (part);
g_free (subject);
@@ -1840,143 +1742,36 @@ em_utils_forward_message (EMailBackend *backend,
return composer;
}
-static void
-forward_got_messages_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+EMsgComposer *
+em_utils_forward_attachment (EMailBackend *backend,
+ CamelMimePart *part,
+ const gchar *subject,
+ CamelFolder *folder,
+ GPtrArray *uids)
{
- CamelFolder *folder;
- 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);
-
- backend = e_mail_reader_get_backend (async_context->reader);
-
- 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;
- }
-
- /* Create a new composer window for each message. */
-
- 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;
-
- message_uid = (const gchar *) key;
- message = CAMEL_MIME_MESSAGE (value);
-
- composer = em_utils_forward_message (
- backend, message, async_context->style,
- folder, message_uid);
-
- e_mail_reader_composer_created (
- async_context->reader, composer, message);
- }
-
- g_hash_table_unref (hash_table);
+ EShell *shell;
+ EMsgComposer *composer;
- e_activity_set_state (activity, E_ACTIVITY_COMPLETED);
+ g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), NULL);
+ g_return_val_if_fail (CAMEL_IS_MIME_PART (part), NULL);
-exit:
- async_context_free (async_context);
-}
+ if (folder != NULL)
+ g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
-/**
- * em_utils_forward_messages:
- * @shell: an #EShell
- * @folder: folder containing messages to forward
- * @uids: uids of messages to forward
- * @style: the forward style to use
- *
- * Forwards a group of messages in the given style.
- *
- * If @style is #E_MAIL_FORWARD_STYLE_ATTACHED, the new message is
- * created as follows. If there is more than a single message in @uids,
- * a multipart/digest will be constructed and attached to a new composer
- * window preset with the appropriate header defaults for forwarding the
- * first message in the list. If only one message is to be forwarded,
- * it is forwarded as a simple message/rfc822 attachment.
- *
- * If @style is #E_MAIL_FORWARD_STYLE_INLINE, each message is forwarded
- * in its own composer window in 'inline' form.
- *
- * If @style is #E_MAIL_FORWARD_STYLE_QUOTED, each message is forwarded
- * in its own composer window in 'quoted' form (each line starting with
- * a "> ").
- **/
-void
-em_utils_forward_messages (EMailReader *reader,
- CamelFolder *folder,
- GPtrArray *uids,
- EMailForwardStyle style)
-{
- EActivity *activity;
- AsyncContext *async_context;
- GCancellable *cancellable;
+ shell = e_shell_backend_get_shell (E_SHELL_BACKEND (backend));
- g_return_if_fail (E_IS_MAIL_READER (reader));
- g_return_if_fail (CAMEL_IS_FOLDER (folder));
- g_return_if_fail (uids != NULL);
+ composer = create_new_composer (shell, subject, folder);
- activity = e_mail_reader_new_activity (reader);
- cancellable = e_activity_get_cancellable (activity);
+ e_msg_composer_attach (composer, part);
- async_context = g_slice_new0 (AsyncContext);
- async_context->activity = activity;
- async_context->reader = g_object_ref (reader);
- async_context->ptr_array = g_ptr_array_ref (uids);
- async_context->style = style;
+ if (uids != NULL)
+ setup_forward_attached_callbacks (composer, folder, uids);
- switch (style) {
- case E_MAIL_FORWARD_STYLE_ATTACHED:
- e_mail_folder_build_attachment (
- folder, uids, G_PRIORITY_DEFAULT,
- cancellable, forward_attached_cb,
- async_context);
- break;
+ composer_set_no_change (composer);
- case E_MAIL_FORWARD_STYLE_INLINE:
- case E_MAIL_FORWARD_STYLE_QUOTED:
- e_mail_folder_get_multiple_messages (
- folder, uids, G_PRIORITY_DEFAULT,
- cancellable, forward_got_messages_cb,
- async_context);
- break;
+ gtk_widget_show (GTK_WIDGET (composer));
- default:
- g_warn_if_reached ();
- }
+ return composer;
}
static gint
diff --git a/mail/em-composer-utils.h b/mail/em-composer-utils.h
index 3cca98334c..a99c3c8af2 100644
--- a/mail/em-composer-utils.h
+++ b/mail/em-composer-utils.h
@@ -26,8 +26,8 @@
#include <em-format/e-mail-part.h>
#include <mail/e-mail-backend.h>
-#include <mail/e-mail-reader.h>
#include <composer/e-msg-composer.h>
+#include <em-format/e-mail-part-list.h>
#include <libemail-engine/e-mail-enums.h>
G_BEGIN_DECLS
@@ -48,10 +48,11 @@ EMsgComposer * em_utils_forward_message (EMailBackend *backend,
EMailForwardStyle style,
CamelFolder *folder,
const gchar *uid);
-void em_utils_forward_messages (EMailReader *reader,
+EMsgComposer * em_utils_forward_attachment (EMailBackend *backend,
+ CamelMimePart *part,
+ const gchar *subject,
CamelFolder *folder,
- GPtrArray *uids,
- EMailForwardStyle style);
+ GPtrArray *uids);
EMsgComposer * em_utils_redirect_message (EShell *shell,
CamelMimeMessage *message);
gchar * em_utils_construct_composer_text