Index: mail/ChangeLog
===================================================================
--- mail/ChangeLog	(revision 35412)
+++ mail/ChangeLog	(working copy)
@@ -1,3 +1,14 @@
+2008-04-23  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #467892
+
+	* em-folder-view.c: (em_folder_view_open_selected):
+	Do not inherit search filters when opening messages in new window.
+	* message-list.c: (regen_list_exec):
+	If we are called from folder_changed even, then keep the actually
+	selected message so it will not disappear when user reads it and
+	it doesn't belong to actual filter anymore.
+
 2008-04-23  Milan Crha  <mcrha@redhat.com>
 
 	* em-format-html-display.c: (efhd_update_bar):
Index: mail/em-folder-view.c
===================================================================
--- mail/em-folder-view.c	(revision 35412)
+++ mail/em-folder-view.c	(working copy)
@@ -561,7 +561,8 @@ em_folder_view_open_selected(EMFolderVie
 
 		emmb = (EMMessageBrowser *)em_message_browser_window_new();
 		message_list_set_threaded(((EMFolderView *)emmb)->list, emfv->list->threaded);
-		message_list_set_search(((EMFolderView *)emmb)->list, emfv->list->search);
+		/* do not inherit search filter, because it can hide actual message for some filters */
+		/*message_list_set_search(((EMFolderView *)emmb)->list, emfv->list->search);*/
 		em_folder_view_set_hide_deleted((EMFolderView *)emmb, emfv->hide_deleted);
 		/* FIXME: session needs to be passed easier than this */
 		em_format_set_session((EMFormat *)((EMFolderView *)emmb)->preview, ((EMFormat *)emfv->preview)->session);
Index: mail/message-list.c
===================================================================
--- mail/message-list.c	(revision 35412)
+++ mail/message-list.c	(working copy)
@@ -3845,6 +3845,7 @@ regen_list_exec (struct _regen_list_msg 
 	CamelMessageInfo *info;
 	ETreePath cursor;
 	int i;
+	char *expr = NULL;
 
 	if (m->folder != m->ml->folder)
 		return;
@@ -3858,10 +3859,8 @@ regen_list_exec (struct _regen_list_msg 
 	/* if we have hidedeleted on, use a search to find it out, merge with existing search if set */
 	if (!camel_folder_has_search_capability(m->folder)) {
 		/* if we have no search capability, dont let search or hide deleted work */
-		uids = camel_folder_get_uids(m->folder);
+		expr = NULL;
 	} else if (m->hidedel) {
-		char *expr;
-
 		if (m->hidejunk) {
 			if (m->search) {
 				expr = alloca(strlen(m->search) + 92);
@@ -3875,23 +3874,34 @@ regen_list_exec (struct _regen_list_msg 
 			} else
 				expr = "(match-all (not (system-flag \"deleted\")))";
 		}
-		searchuids = uids = camel_folder_search_by_expression (m->folder, expr, &m->base.ex);
 	} else {
-		char *expr;
-
 		if (m->hidejunk) {
 			if (m->search) {
 				expr = alloca(strlen(m->search) + 64);
 				sprintf(expr, "(and (match-all (not (system-flag \"junk\")))\n %s)", m->search);
 			} else
 				expr = "(match-all (not (system-flag \"junk\")))";
-			searchuids = uids = camel_folder_search_by_expression (m->folder, expr, &m->base.ex);
 		} else {
-			if (m->search)
-				searchuids = uids = camel_folder_search_by_expression (m->folder, m->search, &m->base.ex);
-			else
-				uids = camel_folder_get_uids (m->folder);
+			expr = m->search;
+		}
+	}
+
+	if (expr == NULL) {
+		uids = camel_folder_get_uids (m->folder);
+	} else {
+		char *tmp_expr = NULL;
+
+		/* If m->changes is not NULL, then it means we are called from folder_changed event,
+		   thus we will keep the selected message to be sure it doesn't disappear because
+		   it no longer belong to our search filter. */
+		if (m->changes && m->ml->search && m->ml->cursor_uid) {
+			tmp_expr = g_strdup_printf ("(or %s (match-all (uid \"%s\")))", expr, m->ml->cursor_uid);
+			expr = tmp_expr;
 		}
+
+		searchuids = uids = camel_folder_search_by_expression (m->folder, expr, &m->base.ex);
+
+		g_free (tmp_expr);
 	}
 
 	if (camel_exception_is_set (&m->base.ex))
