aboutsummaryrefslogtreecommitdiffstats
path: root/mail/e-mail-reader-utils.c
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2011-05-13 06:18:59 +0800
committerMatthew Barnes <mbarnes@redhat.com>2011-05-13 06:24:42 +0800
commit8ff0684fa2e371a80cca60e8df167cc104c473c2 (patch)
treee5cca6b5e8c46feff19eb8e12ab26b4803ebdd3b /mail/e-mail-reader-utils.c
parent6ae1b3fe3c4dfd391de92bfca42e44ff7cc8fe19 (diff)
downloadgsoc2013-evolution-8ff0684fa2e371a80cca60e8df167cc104c473c2.tar.gz
gsoc2013-evolution-8ff0684fa2e371a80cca60e8df167cc104c473c2.tar.zst
gsoc2013-evolution-8ff0684fa2e371a80cca60e8df167cc104c473c2.zip
em_format_html_print_message(): Require a CamelMimeMessage.
Let EMailReader fetch the CamelMimeMessage itself, handle errors, and then pass it off to EMFormatHTMLPrint. This also eliminates the need for em_format_html_print_raw_message().
Diffstat (limited to 'mail/e-mail-reader-utils.c')
-rw-r--r--mail/e-mail-reader-utils.c88
1 files changed, 77 insertions, 11 deletions
diff --git a/mail/e-mail-reader-utils.c b/mail/e-mail-reader-utils.c
index 6ed50b1742..194758489e 100644
--- a/mail/e-mail-reader-utils.c
+++ b/mail/e-mail-reader-utils.c
@@ -50,6 +50,9 @@ struct _AsyncContext {
EActivity *activity;
CamelFolder *folder;
EMailReader *reader;
+ gchar *message_uid;
+
+ GtkPrintOperationAction print_action;
const gchar *filter_source;
gint filter_type;
};
@@ -66,6 +69,8 @@ async_context_free (AsyncContext *context)
if (context->reader != NULL)
g_object_unref (context->reader);
+ g_free (context->message_uid);
+
g_slice_free (AsyncContext, context);
}
@@ -327,12 +332,61 @@ e_mail_reader_open_selected (EMailReader *reader)
return ii;
}
+/* Helper for e_mail_reader_print() */
+static void
+mail_reader_print_cb (CamelFolder *folder,
+ GAsyncResult *result,
+ AsyncContext *context)
+{
+ EAlertSink *alert_sink;
+ CamelMimeMessage *message;
+ EMFormatHTML *formatter;
+ EMFormatHTMLPrint *html_print;
+ GError *error = NULL;
+
+ alert_sink = e_activity_get_alert_sink (context->activity);
+
+ message = camel_folder_get_message_finish (folder, result, &error);
+
+ if (e_activity_handle_cancellation (context->activity, error)) {
+ g_warn_if_fail (message == NULL);
+ async_context_free (context);
+ g_error_free (error);
+ return;
+
+ } else if (error != NULL) {
+ g_warn_if_fail (message == NULL);
+ e_alert_submit (
+ alert_sink, "no-retrieve-message",
+ error->message, NULL);
+ async_context_free (context);
+ g_error_free (error);
+ return;
+ }
+
+ g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message));
+
+ formatter = e_mail_reader_get_formatter (context->reader);
+
+ html_print = em_format_html_print_new (
+ formatter, context->print_action);
+ em_format_merge_handler (
+ EM_FORMAT (html_print), EM_FORMAT (formatter));
+ em_format_html_print_message (
+ html_print, message, folder, context->message_uid);
+ g_object_unref (html_print);
+
+ g_object_unref (message);
+
+ e_activity_set_state (context->activity, E_ACTIVITY_COMPLETED);
+
+ async_context_free (context);
+}
+
void
e_mail_reader_print (EMailReader *reader,
GtkPrintOperationAction action)
{
- EMFormatHTML *formatter;
- EMFormatHTMLPrint *html_print;
CamelFolder *folder;
GPtrArray *uids;
@@ -343,18 +397,30 @@ e_mail_reader_print (EMailReader *reader,
/* XXX Learn to handle len > 1. */
uids = e_mail_reader_get_selected_uids (reader);
- if (uids->len != 1)
- goto exit;
+ g_return_if_fail (uids != NULL);
- formatter = e_mail_reader_get_formatter (reader);
+ if (uids->len == 1) {
+ EActivity *activity;
+ AsyncContext *context;
+ GCancellable *cancellable;
+ const gchar *message_uid;
- html_print = em_format_html_print_new (formatter, action);
- em_format_merge_handler (
- EM_FORMAT (html_print), EM_FORMAT (formatter));
- em_format_html_print_message (html_print, folder, uids->pdata[0]);
- g_object_unref (html_print);
+ activity = e_mail_reader_new_activity (reader);
+ cancellable = e_activity_get_cancellable (activity);
+ message_uid = uids->pdata[0];
+
+ context = g_slice_new0 (AsyncContext);
+ context->activity = activity;
+ context->reader = g_object_ref (reader);
+ context->message_uid = g_strdup (message_uid);
+ context->print_action = action;
+
+ camel_folder_get_message (
+ folder, message_uid, G_PRIORITY_DEFAULT,
+ cancellable, (GAsyncReadyCallback)
+ mail_reader_print_cb, context);
+ }
-exit:
em_utils_uids_free (uids);
}