--- ../evoorig.patch	2011-04-22 17:28:09.094147347 +0200
+++ ../evofix.patch	2011-04-22 17:16:55.855443020 +0200
@@ -17,7 +17,7 @@
          <hook class="org.gnome.evolution.ui:1.0">
            <ui-manager id="org.gnome.evolution.shell"
 diff --git a/plugins/templates/templates.c b/plugins/templates/templates.c
-index fd8f802..ccd1114 100644
+index fd8f802..02a6960 100644
 --- a/plugins/templates/templates.c
 +++ b/plugins/templates/templates.c
 @@ -84,6 +84,10 @@ static void  value_cell_edited_callback (GtkCellRendererText *cell, gchar *path_
@@ -39,7 +39,7 @@
 +static void
 +replace_template_variable (GString *text, const gchar *variable, const gchar *replacement)
 +{
-+        const gchar *p, *next;
++	const gchar *p, *next;
 +	GString *str;
 +	gint find_len;
 +	gchar *find;
@@ -113,7 +113,7 @@
 +	gboolean message_html, template_html;
 +
 +	ct = camel_mime_part_get_content_type (template);
-+	template_html = camel_content_type_is (ct, "text", "html");
++	template_html = ct && camel_content_type_is (ct, "text", "html");
 +
 +	message_html = FALSE;
 +	/* When template is html, then prefer HTML part of the original message. Otherwise go for plaintext */
@@ -144,7 +144,7 @@
 +	camel_data_wrapper_decode_to_stream_sync (camel_medium_get_content (CAMEL_MEDIUM (template)), stream, NULL, NULL);
 +	camel_stream_flush (stream, NULL, NULL);
 +	byte_array = camel_stream_mem_get_byte_array (CAMEL_STREAM_MEM (stream));
-+	template_body = g_string_new_len ((gchar*)byte_array->data, byte_array->len);
++	template_body = g_string_new_len ((gchar *) byte_array->data, byte_array->len);
 +	g_object_unref (stream);
 +
 +	/* Replace all $ORIG[header_name] by respective values */
@@ -262,10 +262,10 @@
 +			CamelMimePart *part = camel_multipart_get_part (CAMEL_MULTIPART (dw), i);
 +			CamelContentType *ct = camel_mime_part_get_content_type (part);
 +
-+			if (camel_content_type_is (ct, "text", "html")) {
++			if (ct && camel_content_type_is (ct, "text", "html")) {
 +				new_content_type = ct;
 +				template_part = camel_multipart_get_part (CAMEL_MULTIPART (dw), i);
-+			} else if (camel_content_type_is (ct, "text", "plain") && new_content_type == NULL) {
++			} else if (ct && camel_content_type_is (ct, "text", "plain") && new_content_type == NULL) {
 +				new_content_type = ct;
 +				template_part = camel_multipart_get_part (CAMEL_MULTIPART (dw), i);
 +			} else {
@@ -277,8 +277,8 @@
 +	} else {
 +		CamelContentType *ct = camel_mime_part_get_content_type (CAMEL_MIME_PART (template));
 +
-+		if (camel_content_type_is (ct, "text", "html") ||
-+		    camel_content_type_is (ct, "text", "plain")) {
++		if (ct && (camel_content_type_is (ct, "text", "html") ||
++		    camel_content_type_is (ct, "text", "plain"))) {
 +		    	template_part = CAMEL_MIME_PART (template);
 +			new_content_type = ct;
 +		}
@@ -386,7 +386,7 @@
                                CamelFolderInfo *folder_info,
 -                              CamelFolder *message_folder,
 -                              const gchar *message_uid)
-+                              EShellView *shell_view)
++			       EShellView *shell_view)
  {
  	CamelStore *store;
 +	EShellWindow *shell_window = e_shell_view_get_shell_window (shell_view);
@@ -398,8 +398,8 @@
  			action_name, GTK_UI_MANAGER_MENU, FALSE);
  
 +		/* Disconnect previous connection to avoid possible multiple calls because
-+		   folder can is a persistent structure */
-+		g_signal_handlers_disconnect_by_func (folder, G_CALLBACK(templates_folder_msg_changed_cb), NULL);
++		   folder is a persistent structure */
++		g_signal_handlers_disconnect_by_func (folder, G_CALLBACK (templates_folder_msg_changed_cb), shell_window);
 +		g_signal_connect (folder, "changed",
 +			G_CALLBACK (templates_folder_msg_changed_cb), shell_window);
 +
@@ -561,7 +561,7 @@
  }
  
  gboolean
-@@ -831,31 +1076,87 @@ init_composer_actions (GtkUIManager *ui_manager,
+@@ -831,31 +1076,89 @@ init_composer_actions (GtkUIManager *ui_manager,
  }
  
  static void
@@ -605,7 +605,8 @@
 +			     CamelFolderInfo *folder_info,
 +			     EShellWindow *shell_window)
 +{
-+	rebuild_template_menu (shell_window);
++	if (folder_info->full_name && strstr (folder_info->full_name, _("Templates")) != NULL)
++		rebuild_template_menu (shell_window);
 +}
 +
 +static void
@@ -614,7 +615,8 @@
 +			     CamelFolderInfo *folder_info,
 +			     EShellWindow *shell_window)
 +{
-+	rebuild_template_menu (shell_window);
++	if (folder_info->full_name && strstr (folder_info->full_name, _("Templates")) != NULL)
++		rebuild_template_menu (shell_window);
 +}
 +
 +static void
