[evolution] Bug #674249 - Crash when showing message with large text/plain



commit f4c30fef04885ebb69df9fb5b8a61a525c5de948
Author: Dan VrÃtil <dvratil redhat com>
Date:   Thu Apr 19 10:30:55 2012 +0200

    Bug #674249 - Crash when showing message with large text/plain

 data/org.gnome.evolution.mail.gschema.xml.in |   10 --
 em-format/em-format.c                        |   38 +------
 mail/em-format-html-display.c                |  154 --------------------------
 modules/mail/e-mail-shell-settings.c         |   10 --
 4 files changed, 5 insertions(+), 207 deletions(-)
---
diff --git a/data/org.gnome.evolution.mail.gschema.xml.in b/data/org.gnome.evolution.mail.gschema.xml.in
index bdc4089..f75ead7 100644
--- a/data/org.gnome.evolution.mail.gschema.xml.in
+++ b/data/org.gnome.evolution.mail.gschema.xml.in
@@ -295,16 +295,6 @@
       <_summary>Compress display of addresses in TO/CC/BCC</_summary>
       <_description>Compress display of addresses in TO/CC/BCC to the number specified in address_count.</_description>
     </key>
-    <key name="force-message-limit" type="b">
-      <default>true</default>
-      <_summary>Display only message texts not exceeding certain size</_summary>
-      <_description>Enable to display only message texts not exceeding size defined in 'message_text_part_limit' key.</_description>
-    </key>
-    <key name="message-text-part-limit" type="i">
-      <default>4096</default>
-      <_summary>Message text limit for display</_summary>
-      <_description>This decides the max size of the message text that will be displayed under Evolution, specified in terms of KB. The default is 4096 (4MB). This value is used only when 'force_message_limit' key is activated.</_description>
-    </key>
     <key name="address-count" type="i">
       <default>5</default>
       <_summary>Number of addresses to display in TO/CC/BCC</_summary>
diff --git a/em-format/em-format.c b/em-format/em-format.c
index 86fafdd..c3f790d 100644
--- a/em-format/em-format.c
+++ b/em-format/em-format.c
@@ -2173,9 +2173,6 @@ em_format_format_text (EMFormat *emf,
 	const gchar *charset = NULL;
 	CamelMimeFilterWindows *windows = NULL;
 	CamelStream *mem_stream = NULL;
-	gsize size;
-	gsize max;
-	GSettings *settings;
 
 	if (g_cancellable_is_cancelled (cancellable))
 		return;
@@ -2221,42 +2218,17 @@ em_format_format_text (EMFormat *emf,
 		g_object_unref (filter);
 	}
 
-	max = -1;
-
-	settings = g_settings_new ("org.gnome.evolution.mail");
-	if (g_settings_get_boolean (settings, "force-message-limit")) {
-		max = g_settings_get_int (settings, "message-text-part-limit");
-		if (max == 0)
-			max = -1;
-	}
-	g_object_unref (settings);
-
-	size = camel_data_wrapper_decode_to_stream_sync (
+	camel_data_wrapper_decode_to_stream_sync (
 			camel_medium_get_content ((CamelMedium *) dw),
-		(CamelStream *) filter_stream, cancellable, NULL);
+			(CamelStream *) filter_stream, cancellable, NULL);
 	camel_stream_flush ((CamelStream *) filter_stream, cancellable, NULL);
 	g_object_unref (filter_stream);
 
 	g_seekable_seek (G_SEEKABLE (mem_stream), 0, G_SEEK_SET, NULL, NULL);
 
-	if (max == -1 || size == -1 || size < (max * 1024) || emf->priv->composer) {
-		camel_stream_write_to_stream (
-			mem_stream, (CamelStream *) stream, cancellable, NULL);
-		camel_stream_flush ((CamelStream *) mem_stream, cancellable, NULL);
-	} else {
-		/* Parse it as an attachment */
-		CamelMimePart *part = camel_mime_part_new ();
-		EMFormatParserInfo info = { 0 };
-		GString *part_id = g_string_new (".attachment");
-		camel_medium_set_content ((CamelMedium *) part, dw);
-
-		info.is_attachment = TRUE;
-		em_format_parse_part_as (emf, part, part_id, &info,
-			"x-evolution/message/attachment", cancellable);
-
-		g_string_free (part_id, TRUE);
-		g_object_unref (part);
-	}
+	camel_stream_write_to_stream (
+		mem_stream, (CamelStream *) stream, cancellable, NULL);
+	camel_stream_flush ((CamelStream *) mem_stream, cancellable, NULL);
 
 	if (windows)
 		g_object_unref (windows);
diff --git a/mail/em-format-html-display.c b/mail/em-format-html-display.c
index 889d69f..4557a74 100644
--- a/mail/em-format-html-display.c
+++ b/mail/em-format-html-display.c
@@ -113,11 +113,9 @@ static void efhd_message_prefix	(EMFormat *emf, CamelMimePart *part, GString *pa
 static void efhd_message_add_bar	(EMFormat *emf, CamelMimePart *part, GString *part_id, EMFormatParserInfo *info, GCancellable *cancellable);
 static void efhd_parse_attachment	(EMFormat *emf, CamelMimePart *part, GString *part_id, EMFormatParserInfo *info, GCancellable *cancellable);
 static void efhd_parse_secure		(EMFormat *emf, CamelMimePart *part, GString *part_id, EMFormatParserInfo *info, GCancellable *cancellable);
-static void efhd_parse_optional		(EMFormat *emf, CamelMimePart *part, GString *part_id, EMFormatParserInfo *info, GCancellable *cancellable);
 
 static GtkWidget * efhd_attachment_bar		(EMFormat *emf, EMFormatPURI *puri, GCancellable *cancellable);
 static GtkWidget * efhd_attachment_button	(EMFormat *emf, EMFormatPURI *puri, GCancellable *cancellable);
-static GtkWidget * efhd_attachment_optional	(EMFormat *emf, EMFormatPURI *puri, GCancellable *cancellable);
 
 static void efhd_write_attachment_bar   (EMFormat *emf, EMFormatPURI *emp, CamelStream *stream, EMFormatWriterInfo *info, GCancellable *cancellable);
 static void efhd_write_attachment       (EMFormat *emf, EMFormatPURI *emp, CamelStream *stream, EMFormatWriterInfo *info, GCancellable *cancellable);
@@ -607,47 +605,6 @@ efhd_parse_attachment (EMFormat *emf,
 }
 
 static void
-efhd_parse_optional (EMFormat *emf,
-                     CamelMimePart *part,
-                     GString *part_id,
-                     EMFormatParserInfo *info,
-                     GCancellable *cancellable)
-{
-	EMFormatAttachmentPURI *puri;
-	gint len;
-
-	len = part_id->len;
-	g_string_append (part_id, ".optional");
-
-	puri = (EMFormatAttachmentPURI *) em_format_puri_new (
-			emf, sizeof (EMFormatAttachmentPURI), part, part_id->str);
-	puri->puri.free = efhd_free_attach_puri_data;
-	puri->puri.write_func = efhd_write_attachment;
-	puri->puri.widget_func = efhd_attachment_optional;
-	puri->attachment_view_part_id = g_strdup (part_id->str);
-	puri->handle = em_format_find_handler (emf, "text/plain");
-	puri->shown = FALSE;
-	puri->snoop_mime_type = "text/plain";
-	puri->attachment = e_attachment_new ();
-	e_attachment_set_mime_part (puri->attachment, puri->puri.part);
-	puri->description = g_strdup(_("Evolution cannot render this email as it is too "
-				       "large to process. You can view it unformatted or "
-				       "with an external text editor."));
-
-	puri->mstream = CAMEL_STREAM_MEM (camel_stream_mem_new ());
-	camel_data_wrapper_decode_to_stream_sync ((CamelDataWrapper *) part,
-		(CamelStream *) puri->mstream, cancellable, NULL);
-
-	if (info->validity) {
-		puri->puri.validity = camel_cipher_validity_clone (info->validity);
-	}
-
-	em_format_add_puri (emf, (EMFormatPURI *) puri);
-
-	g_string_truncate (part_id, len);
-}
-
-static void
 efhd_parse_secure (EMFormat *emf,
                    CamelMimePart *part,
                    GString *part_id,
@@ -932,7 +889,6 @@ static EMFormatHandler type_builtin_table[] = {
 	{ (gchar *) "x-evolution/message/attachment-bar", (EMFormatParseFunc) efhd_message_add_bar, efhd_write_attachment_bar, },
 	{ (gchar *) "x-evolution/message/attachment", efhd_parse_attachment, efhd_write_attachment, },
 	{ (gchar *) "x-evolution/message/x-secure-button", efhd_parse_secure, efhd_write_secure_button, },
-	{ (gchar *) "x-evolution/message/optional", efhd_parse_optional, },
 };
 
 static void
@@ -1100,116 +1056,6 @@ efhd_message_add_bar (EMFormat *emf,
 }
 
 static void
-efhd_optional_button_show (GtkWidget *widget,
-                           GtkWidget *w)
-{
-	GtkWidget *label = g_object_get_data (G_OBJECT (widget), "text-label");
-
-	if (gtk_widget_get_visible (w)) {
-		gtk_widget_hide (w);
-		gtk_label_set_text_with_mnemonic (GTK_LABEL (label), _("View _Unformatted"));
-	} else {
-		gtk_label_set_text_with_mnemonic (GTK_LABEL (label), _("Hide _Unformatted"));
-		gtk_widget_show (w);
-	}
-}
-
-/* optional render attachment button callback */
-static GtkWidget *
-efhd_attachment_optional (EMFormat *efh,
-                          EMFormatPURI *puri,
-                          GCancellable *cancellable)
-{
-	GtkWidget *hbox, *vbox, *button, *mainbox, *scroll, *label, *img;
-	AtkObject *a11y;
-	GtkWidget *view;
-	GtkTextBuffer *buffer;
-	GByteArray *byte_array;
-	EMFormatAttachmentPURI *info = (EMFormatAttachmentPURI *) puri;
-
-	if (g_cancellable_is_cancelled (cancellable))
-		return NULL;
-
-	/* FIXME: handle default shown case */
-	d(printf("adding attachment button/content for optional rendering\n"));
-
-	if (!info || info->forward) {
-		g_warning ("unable to expand the attachment\n");
-		return NULL;
-	}
-
-	scroll = gtk_scrolled_window_new (NULL, NULL);
-	mainbox = gtk_hbox_new (FALSE, 0);
-
-	button = gtk_button_new ();
-	hbox = gtk_hbox_new (FALSE, 0);
-	img = gtk_image_new_from_icon_name (
-		"stock_show-all", GTK_ICON_SIZE_BUTTON);
-	label = gtk_label_new_with_mnemonic(_("View _Unformatted"));
-	g_object_set_data (G_OBJECT (button), "text-label", (gpointer)label);
-	gtk_box_pack_start (GTK_BOX (hbox), img, TRUE, TRUE, 2);
-	gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 2);
-	gtk_widget_show_all (hbox);
-	gtk_container_add (GTK_CONTAINER (button), GTK_WIDGET (hbox));
-	if (info->handle)
-		g_signal_connect (
-			button, "clicked",
-			G_CALLBACK (efhd_optional_button_show), scroll);
-	else {
-		gtk_widget_set_sensitive (button, FALSE);
-		gtk_widget_set_can_focus (button, FALSE);
-	}
-
-	vbox = gtk_vbox_new (FALSE, 0);
-	gtk_box_pack_start (GTK_BOX (mainbox), button, FALSE, FALSE, 6);
-
-	button = gtk_button_new ();
-	hbox = gtk_hbox_new (FALSE, 0);
-	img = gtk_image_new_from_stock (
-		GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
-	label = gtk_label_new_with_mnemonic(_("O_pen With"));
-	gtk_box_pack_start (GTK_BOX (hbox), img, TRUE, TRUE, 2);
-	gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 2);
-	gtk_box_pack_start (GTK_BOX (hbox), gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE), TRUE, TRUE, 2);
-	gtk_widget_show_all (hbox);
-	gtk_container_add (GTK_CONTAINER (button), GTK_WIDGET (hbox));
-
-	a11y = gtk_widget_get_accessible (button);
-	/* Translators: Name of an Attachment button for a11y object */
-	atk_object_set_name (a11y, C_("Button", "Attachment"));
-
-	gtk_box_pack_start (GTK_BOX (mainbox), button, FALSE, FALSE, 6);
-
-	gtk_widget_show_all (mainbox);
-
-	gtk_box_pack_start (GTK_BOX (vbox), mainbox, FALSE, FALSE, 6);
-
-	view = gtk_text_view_new ();
-	gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
-	gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
-	buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-	byte_array = camel_stream_mem_get_byte_array (info->mstream);
-	gtk_text_buffer_set_text (
-		buffer, (gchar *) byte_array->data, byte_array->len);
-	g_object_unref (info->mstream);
-	info->mstream = NULL;
-	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
-					GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
-	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN);
-	gtk_container_add (GTK_CONTAINER (scroll), GTK_WIDGET (view));
-	gtk_box_pack_start (GTK_BOX (vbox), scroll, TRUE, TRUE, 6);
-	gtk_widget_show (GTK_WIDGET (view));
-
-	if (!info->shown)
-		gtk_widget_hide (scroll);
-
-	gtk_widget_show (vbox);
-	info->handle = NULL;
-
-	return view;
-}
-
-static void
 efhd_free_attach_puri_data (EMFormatPURI *puri)
 {
 	EMFormatAttachmentPURI *info = (EMFormatAttachmentPURI *) puri;
diff --git a/modules/mail/e-mail-shell-settings.c b/modules/mail/e-mail-shell-settings.c
index 0ad50d3..7d1fba1 100644
--- a/modules/mail/e-mail-shell-settings.c
+++ b/modules/mail/e-mail-shell-settings.c
@@ -155,11 +155,6 @@ e_mail_shell_settings_init (EShellBackend *shell_backend)
 		MAIL_SCHEMA,
 		"variable-width-font");
 
-	e_shell_settings_install_property_for_key (
-		"mail-force-message-limit",
-		MAIL_SCHEMA,
-		"force-message-limit");
-
 	/* This value corresponds to the EMailForwardStyle enum. */
 	e_shell_settings_install_property_for_key (
 		"mail-forward-style",
@@ -197,11 +192,6 @@ e_mail_shell_settings_init (EShellBackend *shell_backend)
 		MAIL_SCHEMA,
 		"mark-seen-timeout");
 
-	e_shell_settings_install_property_for_key (
-		"mail-message-text-part-limit",
-		MAIL_SCHEMA,
-		"message-text-part-limit");
-
 	/* Do not bind to this.  Use "mail-sidebar-ellipsize" instead. */
 	e_shell_settings_install_property_for_key (
 		"mail-no-folder-dots",



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