[evolution/webkit: 26/96] Add custom EMFormatHandler for message headers.



commit 3616dec734271506fbe2f512c082c6b459c0b104
Author: Dan VrÃtil <dvratil redhat com>
Date:   Thu Sep 15 16:15:40 2011 +0200

    Add custom EMFormatHandler for message headers.

 em-format/em-format.c         |  115 ++++++++++++++++++++++++++--------------
 em-format/em-format.h         |    1 +
 mail/e-mail-display.c         |   40 +++++---------
 mail/e-mail-request.c         |   72 ++++++--------------------
 mail/em-format-html-display.c |   27 +++++-----
 mail/em-format-html.c         |   59 ++++++++++++++++-----
 6 files changed, 164 insertions(+), 150 deletions(-)
---
diff --git a/em-format/em-format.c b/em-format/em-format.c
index 6d20237..6215813 100644
--- a/em-format/em-format.c
+++ b/em-format/em-format.c
@@ -73,6 +73,9 @@ static void emf_parse_multipart_digest		(EMFormat *emf, CamelMimePart *part, GSt
 static void emf_parse_message_deliverystatus	(EMFormat *emf, CamelMimePart *part, GString *part_id, EMFormatParserInfo *info, GCancellable *cancellable);
 static void emf_parse_inlinepgp_signed		(EMFormat *emf, CamelMimePart *part, GString *part_id, EMFormatParserInfo *info, GCancellable *cancellable);
 static void emf_parse_inlinepgp_encrypted	(EMFormat *emf, CamelMimePart *part, GString *part_id, EMFormatParserInfo *info, GCancellable *cancellable);
+static void emf_parse_message			(EMFormat *emf, CamelMimePart *part, GString *part_id, EMFormatParserInfo *info, GCancellable *cancellable);
+static void emf_parse_headers			(EMFormat *emf, CamelMimePart *part, GString *part_id, EMFormatParserInfo *info, GCancellable *cancellable);
+static void emf_parse_post_headers		(EMFormat *emf, CamelMimePart *part, GString *part_id, EMFormatParserInfo *info, GCancellable *cancellable);
 static void emf_parse_source			(EMFormat *emf, CamelMimePart *part, GString *part_id, EMFormatParserInfo *info, GCancellable *cancellable);
 static void emf_parse_attachment		(EMFormat *emf, CamelMimePart *part, GString *part_id, EMFormatParserInfo *info, GCancellable *cancellable);
 
@@ -669,7 +672,7 @@ emf_parse_multipart_digest (EMFormat *emf,
 		CamelMimePart *subpart;
 		CamelContentType *ct;
 		gchar *cts;
-		EMFormatHandler *handler;
+		const EMFormatHandler *handler;
 
 		subpart = camel_multipart_get_part (mp, i);
 
@@ -688,7 +691,7 @@ emf_parse_multipart_digest (EMFormat *emf,
 			continue;
 		}
 
-		handler = em_format_find_handler (emf, "x-evolution/message/attachment");
+		handler = em_format_find_handler (emf, "message/rfc822");
 		handler->parse_func (emf, subpart, part_id, info, cancellable);
 
 		g_string_truncate (part_id, len);
@@ -763,6 +766,7 @@ emf_parse_message_deliverystatus (EMFormat *emf,
 
 	puri = em_format_puri_new (emf, sizeof (EMFormatPURI), part, part_id->str);
 	puri->write_func = emf_write_text;
+	puri->mime_type = g_strdup ("text/html");
 
 	g_string_truncate (part_id, len);
 
@@ -945,6 +949,58 @@ emf_parse_inlinepgp_encrypted (EMFormat *emf,
 }
 
 static void
+emf_parse_message (EMFormat *emf,
+		   CamelMimePart *part,
+		   GString *part_id,
+		   EMFormatParserInfo *info,
+		   GCancellable *cancellable)
+{
+	/* Headers */
+	em_format_parse_part_as (emf, part, part_id, info,
+			"x-evolution/message/headers", cancellable);
+
+	/* Anything that comes between headers and message body */
+	em_format_parse_part_as (emf, part, part_id, info,
+			"x-evolution/message/post-headers", cancellable);
+
+	/* Begin parsing the message */
+	em_format_parse_part (emf, part, part_id, info, cancellable);
+}
+
+static void
+emf_parse_headers (EMFormat *emf,
+		   CamelMimePart *part,
+		   GString *part_id,
+		   EMFormatParserInfo *info,
+		   GCancellable *cancellable)
+{
+	EMFormatPURI *puri;
+	gint len;
+
+	len = part_id->len;
+	g_string_append (part_id, ".headers");
+
+	puri = em_format_puri_new (emf, sizeof (EMFormatPURI), part, part_id->str);
+	puri->write_func = info->handler->write_func;
+	puri->mime_type = g_strdup ("text/html");
+	em_format_add_puri (emf, puri);
+
+	g_string_truncate (part_id, len);
+}
+
+static void
+emf_parse_post_headers (EMFormat *emf,
+		        CamelMimePart *part,
+		        GString *part_id,
+		        EMFormatParserInfo *info,
+		        GCancellable *cancellable)
+{
+	/* Add attachment bar */
+	em_format_parse_part_as (emf, part, part_id, info,
+		"x-evolution/message/attachment-bar", cancellable);
+}
+
+static void
 emf_parse_source (EMFormat *emf,
 		  CamelMimePart *part,
 		  GString *part_id,
@@ -962,6 +1018,7 @@ emf_parse_source (EMFormat *emf,
 
 	puri = em_format_puri_new (emf, sizeof (EMFormatPURI), part, part_id->str);
 	puri->write_func = emf_write_source;
+	puri->mime_type = g_strdup ("text/html");
 	g_string_truncate (part_id, len);
 
 	em_format_add_puri (emf, puri);
@@ -1047,15 +1104,10 @@ emf_parse (EMFormat *emf,
 	g_return_if_fail (emf->message);
 	g_return_if_fail (emf->folder);
 
-
 	part_id = g_string_new ("");
-	/* Begun parsing the message */
-	em_format_parse_part (emf, CAMEL_MIME_PART (message), part_id, &info, cancellable);
 
-	/* Now call some internal handlers */
 	em_format_parse_part_as (emf, CAMEL_MIME_PART (message), part_id, &info,
-			"x-evolution/message/post-header", cancellable);
-
+			"x-evolution/message", cancellable);
 
 	g_string_free (part_id, TRUE);
 }
@@ -1115,6 +1167,9 @@ static EMFormatHandler type_handlers[] = {
 		/* internal types */
 		{ (gchar *) "application/x-inlinepgp-signed", emf_parse_inlinepgp_signed, },
 		{ (gchar *) "application/x-inlinepgp-encrypted", emf_parse_inlinepgp_encrypted, },
+		{ (gchar *) "x-evolution/message", emf_parse_message, },
+		{ (gchar *) "x-evolution/message/headers", emf_parse_headers, },
+		{ (gchar *) "x-evolution/message/post-headers", emf_parse_post_headers, },
 		{ (gchar *) "x-evolution/message/source", emf_parse_source, },
 		{ (gchar *) "x-evolution/message/attachment", emf_parse_attachment, },
 };
@@ -1536,9 +1591,6 @@ em_format_add_puri (EMFormat *emf,
 
 	g_hash_table_insert (emf->mail_part_table,
 			puri->uri, puri);
-
-	printf("  added PURI '%s', type %s, cid %s\n", puri->uri,
-			camel_content_type_simple (camel_mime_part_get_content_type (puri->part)), puri->cid);
 }
 
 EMFormatPURI*
@@ -2131,24 +2183,9 @@ em_format_puri_new (EMFormat *emf,
 
 	if (part)
 		puri->part = g_object_ref (part);
-	else
-		puri->part = NULL;
 
 	if (uri)
 		puri->uri = g_strdup (uri);
-	else
-		puri->uri = NULL;
-
-	puri->cid = NULL;
-
-	puri->validity_type = 0;
-	puri->validity = NULL;
-	puri->validity_parent = NULL;
-
-	puri->write_func = NULL;
-	puri->widget_func = NULL;
-
-	puri->free = NULL;
 
 	return puri;
 }
@@ -2167,6 +2204,9 @@ em_format_puri_free (EMFormatPURI *puri)
 	if (puri->cid)
 		g_free (puri->cid);
 
+	if (puri->mime_type)
+		g_free (puri->mime_type);
+
 	if (puri->validity)
 		camel_cipher_validity_free (puri->validity);
 
@@ -2185,30 +2225,25 @@ em_format_puri_write (EMFormatPURI *puri,
 		      CamelStream *stream,
 		      GCancellable *cancellable)
 {
-	const EMFormatHandler *handler;
-	CamelContentType *ct;
-	gchar *mime_type;
-
 	g_return_if_fail (puri);
 	g_return_if_fail (CAMEL_IS_STREAM (stream));
 
-	ct = camel_mime_part_get_content_type (puri->part);
-	if (ct) {
-		mime_type = camel_content_type_simple (ct);
-	} else {
-		mime_type = (gchar *) "plain/text";
-	}
-
 	if (puri->write_func) {
 		puri->write_func (puri->emf, puri, stream, cancellable);
 	} else {
+		const EMFormatHandler *handler;
+		const gchar *mime_type;
+
+		if (puri->mime_type) {
+			mime_type = puri->mime_type;
+		} else {
+			mime_type = (gchar *) "plain/text";
+		}
+
 		handler = em_format_find_handler (puri->emf, mime_type);
 		if (handler && handler->write_func) {
 			handler->write_func (puri->emf,
 					puri, stream, cancellable);
 		}
 	}
-
-	if (ct)
-		g_free (mime_type);
 }
diff --git a/em-format/em-format.h b/em-format/em-format.h
index ba3909a..78f28b4 100644
--- a/em-format/em-format.h
+++ b/em-format/em-format.h
@@ -128,6 +128,7 @@ struct _EMFormatPURI {
 
 	gchar *uri;
 	gchar *cid;
+	gchar *mime_type;
 
 	/* EM_FORMAT_VALIDITY_* flags */
 	guint32 validity_type;
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index a26913f..0ec33bf 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -632,8 +632,6 @@ e_mail_display_load (EMailDisplay *display,
 		     const gchar *msg_uri)
 {
 	EWebView *web_view;
-	EAttachmentStore *attachment_store;
-	GtkWidget *attachment_bar;
 	EMFormatPURI *puri;
 	EMFormat *emf = (EMFormat *) display->priv->formatter;
 	gchar *uri;
@@ -655,38 +653,29 @@ e_mail_display_load (EMailDisplay *display,
 	box = GTK_BOX (display->priv->vbox);
 	gtk_widget_show (display->priv->vbox);
 
-	/* Headers webview */
-	web_view = mail_display_setup_webview (display);
-	mail_display_insert_web_view (display, web_view, FALSE);
-	uri = em_format_build_mail_uri (emf->folder, emf->message_uid, "headers");
-	e_web_view_load_uri (web_view, uri);
-	g_free (uri);
-
-	/* Attachment bar */
-	attachment_store = NULL;
-	puri = g_hash_table_lookup (emf->mail_part_table, "attachment-bar:");
-	if (puri && puri->widget_func) {
-		attachment_bar = g_object_ref (puri->widget_func (emf, puri, NULL));
-		gtk_box_pack_start (box, attachment_bar, TRUE, TRUE, 0);
-		attachment_store = e_attachment_view_get_store (E_ATTACHMENT_VIEW (attachment_bar));
-		gtk_widget_show (attachment_bar);
-	}
-
 	for (iter = emf->mail_part_list; iter; iter = iter->next) {
 		GtkWidget *widget = NULL;
 
 		puri = iter->data;
 		uri = em_format_build_mail_uri (emf->folder, emf->message_uid, puri->uri);
 
-		if (puri->widget_func && strcmp (puri->uri, "attachment-bar:") != 0) {
+		if (puri->widget_func) {
 
 			widget = puri->widget_func (emf, puri, NULL);
-			if (!widget) {
+			if (!GTK_IS_WIDGET (widget)) {
 				g_message ("Part %s didn't provide a valid widget, skipping!", puri->uri);
 				continue;
 			}
+
 			gtk_box_pack_start (box, widget, TRUE, TRUE, 0);
-			gtk_widget_show (widget);
+			if (E_IS_ATTACHMENT_VIEW (widget)) {
+				EAttachmentStore *store = e_attachment_view_get_store (E_ATTACHMENT_VIEW (widget));
+				if (e_attachment_store_get_num_attachments (store) > 0)
+					gtk_widget_show (widget);
+				else
+					gtk_widget_hide (widget);
+			} else
+				gtk_widget_show (widget);
 
 		}
 
@@ -704,10 +693,6 @@ e_mail_display_load (EMailDisplay *display,
 
 		g_free (uri);
 	}
-
-	/* Don't display EAttachmentBar if it's empty. */
-	if (attachment_store && e_attachment_store_get_num_attachments (attachment_store) == 0)
-		gtk_widget_hide (attachment_bar);
 }
 
 void
@@ -757,6 +742,9 @@ remove_widget (GtkWidget *widget, gpointer user_data)
 {
 	EMailDisplay *display = user_data;
 
+	if (!GTK_IS_WIDGET (widget))
+		return;
+
 	gtk_container_remove  (GTK_CONTAINER (display->priv->vbox), widget);
 
 	/* We must not destroy attachment bar, it's owned by EMFormatHTMLDisplay */
diff --git a/mail/e-mail-request.c b/mail/e-mail-request.c
index 6497cc1..cf40415 100644
--- a/mail/e-mail-request.c
+++ b/mail/e-mail-request.c
@@ -13,29 +13,17 @@ G_DEFINE_TYPE (EMailRequest, e_mail_request, SOUP_TYPE_REQUEST)
 
 struct _EMailRequestPrivate {
 	EMFormatHTML *efh;
-	CamelMimePart *part;
 
 	CamelStream *output_stream;
-
-	CamelContentType *content_type;
+	EMFormatPURI *puri;
 	gchar *mime_type;
+
 	gint content_length;
 
 	GHashTable *uri_query;
 };
 
 static void
-mail_request_set_content_type (EMailRequest *emr,
-			       CamelContentType *ct)
-{
-	if (emr->priv->content_type)
-		camel_content_type_unref (emr->priv->content_type);
-
-	emr->priv->content_type = ct;
-	camel_content_type_ref (emr->priv->content_type);
-}
-
-static void
 start_mail_formatting (GSimpleAsyncResult *res,
 		       GObject *object,
 		       GCancellable *cancellable)
@@ -58,21 +46,11 @@ start_mail_formatting (GSimpleAsyncResult *res,
 	part_id = g_hash_table_lookup (request->priv->uri_query, "part_id");
 
 	if (part_id) {
-		gboolean all_headers = GPOINTER_TO_INT (g_hash_table_lookup (
-				request->priv->uri_query, "all-headers"));
-
-		if (strcmp (part_id, "headers") == 0) {
-			em_format_html_format_headers (efh, request->priv->output_stream,
-				CAMEL_MEDIUM (emf->message), all_headers, cancellable);
+		request->priv->puri = em_format_find_puri (emf, part_id);
+		if (request->priv->puri) {
+			em_format_puri_write (request->priv->puri, request->priv->output_stream, NULL);
 		} else {
-			EMFormatPURI *puri = em_format_find_puri (emf, part_id);
-			if (puri) {
-				em_format_puri_write (puri, request->priv->output_stream, NULL);
-				mail_request_set_content_type (request,
-					camel_mime_part_get_content_type (puri->part));
-			} else {
-				g_warning ("Failed to lookup requested part '%s' - this should not happen!", part_id);
-			}
+			g_warning ("Failed to lookup requested part '%s' - this should not happen!", part_id);
 		}
 	}
 
@@ -106,11 +84,7 @@ get_file_content (GSimpleAsyncResult *res,
 	uri = soup_request_get_uri (SOUP_REQUEST (request));
 
 	if (g_file_get_contents (uri->path, &contents, &length, NULL)) {
-		CamelContentType *ct;
 		request->priv->mime_type = g_content_type_guess (uri->path, NULL, 0, NULL);
-		ct = camel_content_type_decode (request->priv->mime_type);
-		mail_request_set_content_type (request, ct);
-		camel_content_type_unref (ct);
 
 		request->priv->content_length = length;
 
@@ -126,10 +100,9 @@ e_mail_request_init (EMailRequest *request)
 		request, E_TYPE_MAIL_REQUEST, EMailRequestPrivate);
 
 	request->priv->efh = NULL;
-	request->priv->part = NULL;
 	request->priv->output_stream = NULL;
 	request->priv->uri_query = NULL;
-	request->priv->content_type = NULL;
+	request->priv->puri = NULL;
 	request->priv->mime_type = NULL;
 	request->priv->content_length = 0;
 }
@@ -144,11 +117,6 @@ mail_request_finalize (GObject *object)
 		request->priv->output_stream = NULL;
 	}
 
-	if (request->priv->content_type) {
-		camel_content_type_unref (request->priv->content_type);
-		request->priv->content_type = NULL;
-	}
-
 	if (request->priv->mime_type) {
 		g_free (request->priv->mime_type);
 		request->priv->mime_type = NULL;
@@ -251,27 +219,19 @@ mail_request_get_content_type (SoupRequest *request)
 {
 	EMailRequest *emr = E_MAIL_REQUEST (request);
 
-	if (emr->priv->mime_type) {
-		d(printf("Content-Type: %s\n", emr->priv->mime_type));
+	if (emr->priv->mime_type)
 		return emr->priv->mime_type;
-	}
-
-	if (emr->priv->content_type == NULL) {
-		emr->priv->mime_type = g_strdup ("text/html; charset=utf-8");
 
-	/* For text/* content type, return text/html, because we
-	 * have converted it from whatever type it was to HTML */
-	} else if (camel_content_type_is (emr->priv->content_type, "text", "*")) {
-		emr->priv->mime_type = g_strdup ("text/html; charset=utf-8");
+	if (!emr->priv->puri)
+		return "text/html";
 
-	/* For any other format return it's native format, because then it is
-	 * most probably image or something similar */
-	} else {
-		emr->priv->mime_type = camel_content_type_simple (emr->priv->content_type);
-	}
+	if (!emr->priv->puri->mime_type) {
+		CamelContentType *ct = camel_mime_part_get_content_type (emr->priv->puri->part);
+		return camel_content_type_format (ct);
+	} else
+		return emr->priv->puri->mime_type;
 
-	d(printf("Content-Type: %s\n", emr->priv->mime_type));
-	return emr->priv->mime_type;
+	return "text/html";
 }
 
 static const char *data_schemes[] = { "mail", "evo-file", NULL };
diff --git a/mail/em-format-html-display.c b/mail/em-format-html-display.c
index 154bfff..4644889 100644
--- a/mail/em-format-html-display.c
+++ b/mail/em-format-html-display.c
@@ -367,17 +367,19 @@ efhd_parse_attachment (EMFormat *emf,
                        EMFormatParserInfo *info,
                        GCancellable *cancellable)
 {
-	gchar *classid, *text, *html;
+	gchar *text, *html;
 	EMFormatAttachmentPURI *puri;
 	const EMFormatHandler *handler;
 	CamelContentType *ct;
 	gchar *mime_type;
+	gint len;
 	const gchar *cid;
 
 	if (g_cancellable_is_cancelled (cancellable))
 		return;
 
-	classid = g_strdup_printf ("attachment.%s", part_id->str);
+	len = part_id->len;
+	g_string_append (part_id, ".attachment");
 
 	ct = camel_mime_part_get_content_type (part);
 	if (ct) {
@@ -395,14 +397,13 @@ efhd_parse_attachment (EMFormat *emf,
 	g_free (mime_type);
 
 	puri = (EMFormatAttachmentPURI*) em_format_puri_new (
-			emf, sizeof (EMFormatAttachmentPURI), part, classid);
+			emf, sizeof (EMFormatAttachmentPURI), part, part_id->str);
 	puri->puri.free = efhd_free_attach_puri_data;
 	puri->puri.widget_func = efhd_attachment_button;
-	puri->shown = em_format_is_inline (
-		emf, part_id->str,part, info->handler);
+	puri->shown = em_format_is_inline (emf, part_id->str, part, info->handler);
 	puri->snoop_mime_type = em_format_snoop_type (part);
 	puri->attachment = e_attachment_new ();
-	puri->attachment_view_part_id = g_strdup (classid);
+	puri->attachment_view_part_id = g_strdup (part_id->str);
 	puri->description = html;
 	puri->handle = handler;
 
@@ -422,7 +423,7 @@ efhd_parse_attachment (EMFormat *emf,
 		puri->encrypt = info->validity->encrypt.status;
 	}
 
-	g_free (classid);
+	g_string_truncate (part_id, len);
 }
 
 static void
@@ -794,7 +795,7 @@ em_format_html_display_new (void)
 
 static EMFormatHandler type_builtin_table[] = {
 	{ (gchar *) "x-evolution/message/prefix", efhd_message_prefix, },
-	{ (gchar *) "x-evolution/message/post-header", (EMFormatParseFunc) efhd_message_add_bar, },
+	{ (gchar *) "x-evolution/message/attachment-bar", (EMFormatParseFunc) efhd_message_add_bar, },
 	{ (gchar *) "x-evolution/message/attachment", efhd_parse_attachment, },
 };
 
@@ -1029,19 +1030,19 @@ efhd_message_add_bar (EMFormat *emf,
 {
 	gchar *classid;
 	EMFormatAttachmentPURI *puri;
+	gint len;
 
 	if (g_cancellable_is_cancelled (cancellable))
 		return;
 
-	classid = g_strdup_printf (
-		"attachment-bar:%s", part_id->str);
-
+	len = part_id->len;
+	g_string_append (part_id, ".attachment-bar");
 	puri = (EMFormatAttachmentPURI *) em_format_puri_new (
-			emf, sizeof (EMFormatAttachmentPURI), part, classid);
+			emf, sizeof (EMFormatAttachmentPURI), part, part_id->str);
 	puri->puri.widget_func = efhd_attachment_bar;
 	em_format_add_puri (emf, (EMFormatPURI*) puri);
 
-	g_free (classid);
+	g_string_truncate (part_id, len);
 }
 
 static void
diff --git a/mail/em-format-html.c b/mail/em-format-html.c
index 430fec4..d3d9da7 100644
--- a/mail/em-format-html.c
+++ b/mail/em-format-html.c
@@ -146,6 +146,7 @@ static void efh_write_text_plain		(EMFormat *emf, EMFormatPURI *puri, CamelStrea
 static void efh_write_text_html			(EMFormat *emf, EMFormatPURI *puri, CamelStream *stream, GCancellable *cancellable);
 static void efh_write_source			(EMFormat *emf, EMFormatPURI *puri, CamelStream *stream, GCancellable *cancellable);
 static void efh_write_message_rfc822		(EMFormat *emf, EMFormatPURI *puri, CamelStream *stream, GCancellable *cancellable);
+static void efh_write_headers			(EMFormat *emf, EMFormatPURI *puri, CamelStream *stream, GCancellable *cancellable);
 /*****************************************************************************/
 static void
 efh_parse_image (EMFormat *emf,
@@ -175,6 +176,7 @@ efh_parse_image (EMFormat *emf,
 	puri = em_format_puri_new (emf, sizeof (EMFormatPURI), part, part_id->str);
 	puri->cid = cid;
 	puri->write_func = efh_write_image;
+	puri->mime_type = g_strdup (info->handler->mime_type);
 	puri->is_attachment = TRUE;
 
 	em_format_add_puri (emf, puri);
@@ -207,6 +209,7 @@ efh_parse_text_enriched (EMFormat *emf,
 	g_string_append (part_id, ".text_enriched");
 	puri = em_format_puri_new (emf, sizeof (EMFormatPURI), part, part_id->str);
 	puri->cid = cid;
+	puri->mime_type = g_strdup (info->handler->mime_type);
 	puri->write_func = efh_write_text_enriched;
 
 	em_format_add_puri (emf, puri);
@@ -318,6 +321,7 @@ efh_parse_text_plain (EMFormat *emf,
 			g_string_append (part_id, ".plain_text");
 			puri = em_format_puri_new (emf, sizeof (EMFormatPURI), newpart, part_id->str);
 			puri->write_func = efh_write_text_plain;
+			puri->mime_type = g_strdup ("text/html");
 			g_string_truncate (part_id, s_len);
 			em_format_add_puri (emf, puri);
 		} else {
@@ -486,6 +490,7 @@ addPart:
 	g_string_append (part_id, ".msg_external");
 	puri = em_format_puri_new (emf, sizeof (EMFormatPURI), part, part_id->str);
 	puri->write_func = efh_write_text_html;
+	puri->mime_type = g_strdup ("text/html");
 
 	em_format_add_puri (emf, puri);
 	g_string_truncate (part_id, len);
@@ -508,6 +513,7 @@ efh_parse_message_deliverystatus (EMFormat *emf,
 	g_string_append (part_id, ".deliverystatus");
 	puri = em_format_puri_new (emf, sizeof (EMFormatPURI), part, part_id->str);
 	puri->write_func = efh_write_source;
+	puri->mime_type = g_strdup ("text/html");
 
 	em_format_add_puri (emf, puri);
 	g_string_truncate (part_id, len);
@@ -520,16 +526,37 @@ efh_parse_message_rfc822 (EMFormat *emf,
 			  EMFormatParserInfo *info,
 			  GCancellable *cancellable)
 {
-	EMFormatPURI *puri;
+	CamelDataWrapper *dw;
+	CamelMimePart *opart;
+	CamelStream *stream;
+	CamelMimeParser *parser;
+	CamelContentType *ct;
+	gchar *cts;
 	gint len;
+	EMFormatParserInfo oinfo = *info;
 
 	len = part_id->len;
 	g_string_append (part_id, ".rfc822");
-	puri = em_format_puri_new (emf, sizeof (EMFormatPURI), part, part_id->str);
-	puri->write_func = efh_write_message_rfc822;
 
-	em_format_add_puri (emf, puri);
+	stream = camel_stream_mem_new ();
+	dw = camel_medium_get_content ((CamelMedium *) part);
+	camel_data_wrapper_write_to_stream_sync (dw, stream, cancellable, NULL);
+	g_seekable_seek (G_SEEKABLE (stream), 0, G_SEEK_SET, cancellable, NULL);
+
+	parser = camel_mime_parser_new ();
+	camel_mime_parser_init_with_stream (parser, stream, NULL);
+
+	opart = camel_mime_part_new ();
+	camel_mime_part_construct_from_parser_sync (opart, parser, cancellable, NULL);
+
+	em_format_parse_part_as (emf, opart, part_id, &oinfo,
+		"x-evolution/message", cancellable);
+
 	g_string_truncate (part_id, len);
+
+	g_object_unref (opart);
+	g_object_unref (parser);
+	g_object_unref (stream);
 }
 
 
@@ -730,13 +757,13 @@ efh_write_source (EMFormat *emf,
 }
 
 static void
-efh_write_message_rfc822 (EMFormat *emf,
-			  EMFormatPURI *puri,
-			  CamelStream *stream,
-			  GCancellable *cancellable)
+efh_write_headers (EMFormat *emf,
+		   EMFormatPURI *puri,
+		   CamelStream *stream,
+		   GCancellable *cancellable)
 {
-
-
+	/* FIXME: We could handle this more nicely */
+	em_format_html_format_headers ((EMFormatHTML *) emf, stream, (CamelMedium *)  puri->part, FALSE, cancellable);
 }
 
 /*****************************************************************************/
@@ -771,10 +798,10 @@ static EMFormatHandler type_builtin_table[] = {
 	{ (gchar *) "text/html", efh_parse_text_html, efh_write_text_html, },
 	{ (gchar *) "text/richtext", efh_parse_text_enriched, efh_write_text_enriched, },
 	{ (gchar *) "text/*", efh_parse_text_plain, efh_write_text_plain, },
-        { (gchar *) "nessage/rfc822", efh_parse_message_rfc822, efh_write_message_rfc822, EM_FORMAT_HANDLER_INLINE },
-        { (gchar *) "message/news", efh_parse_message_rfc822, efh_write_message_rfc822, EM_FORMAT_HANDLER_INLINE },
-        { (gchar *) "message/delivery-status", efh_parse_message_deliverystatus, efh_write_message_rfc822, },
-	{ (gchar *) "message/external-body", efh_parse_message_external, efh_write_message_rfc822, },
+        { (gchar *) "message/rfc822", efh_parse_message_rfc822, 0, EM_FORMAT_HANDLER_INLINE },
+        { (gchar *) "message/news", efh_parse_message_rfc822, 0, EM_FORMAT_HANDLER_INLINE },
+        { (gchar *) "message/delivery-status", efh_parse_message_deliverystatus, efh_write_text_plain, },
+	{ (gchar *) "message/external-body", efh_parse_message_external, efh_write_text_plain, },
         { (gchar *) "message/*", efh_parse_message_rfc822, 0, EM_FORMAT_HANDLER_INLINE },
 
 	/* This is where one adds those busted, non-registered types,
@@ -784,7 +811,8 @@ static EMFormatHandler type_builtin_table[] = {
 	{ (gchar *) "image/pjpeg", efh_parse_image, efh_write_image, },
 
 	/* special internal types */
-	{ (gchar *) "x-evolution/message/rfc822", 0, efh_write_text_plain }
+	{ (gchar *) "x-evolution/message/rfc822", 0, efh_write_text_plain, },
+	{ (gchar *) "x-evolution/message/headers", 0, efh_write_headers, },
 };
 
 static void
@@ -1029,6 +1057,7 @@ efh_format_error (EMFormat *emf,
 
 	puri = em_format_puri_new (emf, sizeof (EMFormatPURI), part, em_format_get_error_id (emf));
 	puri->write_func = efh_write_text_html;
+	puri->mime_type = g_strdup ("text/html");
 
 	em_format_add_puri (emf, puri);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]