Index: mail/ChangeLog
===================================================================
--- mail/ChangeLog	(revision 35676)
+++ mail/ChangeLog	(working copy)
@@ -1,3 +1,12 @@
+2008-06-23  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #537275
+
+	* em-html-stream.c: (emhs_cleanup): Close GtkHTMLStream on cancel.
+	* em-html-stream.c: (emhs_gtkhtml_destroy): Set the cancel.
+	* em-sync-stream.c: (emss_process_message):
+	Do not pass data to the child structure if we were canceled.
+
 2008-06-21  Paul Bolle  <pebolle@tiscali.nl>
 
 	** Fix for bug #539268
Index: mail/em-html-stream.c
===================================================================
--- mail/em-html-stream.c	(revision 35676)
+++ mail/em-html-stream.c	(working copy)
@@ -80,6 +80,8 @@ em_html_stream_init (CamelObject *object
 static void
 emhs_cleanup(EMHTMLStream *emhs)
 {
+	if (emhs->sync.cancel && emhs->html_stream)
+		gtk_html_stream_close (emhs->html_stream, GTK_HTML_STREAM_ERROR);
 	emhs->html_stream = NULL;
 	emhs->sync.cancel = TRUE;
 	g_signal_handler_disconnect(emhs->html, emhs->destroy_id);
@@ -147,6 +149,7 @@ static void
 emhs_gtkhtml_destroy(struct _GtkHTML *html, EMHTMLStream *emhs)
 {
 	d(printf("%p: emhs gtkhtml destroy\n", emhs));
+	emhs->sync.cancel = TRUE;
 	emhs_cleanup(emhs);
 }
 
Index: mail/em-sync-stream.c
===================================================================
--- mail/em-sync-stream.c	(revision 35676)
+++ mail/em-sync-stream.c	(working copy)
@@ -59,6 +59,13 @@ emss_process_message (struct _write_msg 
 {
 	struct _EMSyncStream *emss = msg->emss;
 
+	if (emss->cancel) {
+		/* Do not pass data to the child if we are canceled. */
+		e_flag_set (msg->done);
+
+		return FALSE;
+	}
+
 	/* Force out any pending data before doing anything else. */
 	if (emss->buffer != NULL && emss->buffer->len > 0) {
 		EMSS_CLASS (emss)->sync_write (
