Index: shell/ChangeLog
===================================================================
--- shell/ChangeLog	(revision 34382)
+++ shell/ChangeLog	(working copy)
@@ -1,3 +1,9 @@
+2007-10-12  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #300336
+
+	* main.c: Added new parameter option '--disable-vfolder'.
+
 2007-10-11  Milan Crha  <mcrha@redhat.com>
 
 	** Fix for bug #329823
Index: shell/main.c
===================================================================
--- shell/main.c	(revision 34382)
+++ shell/main.c	(working copy)
@@ -110,6 +110,10 @@
 static char *evolution_debug_log = NULL;
 static gchar **remaining_args;
 
+/* This one is used in mail-component.c as an extern and I use this
+   because I don't want to use gconf to store such information. */
+gboolean disable_vfolder = FALSE;
+
 static void
 no_windows_left_cb (EShell *shell, gpointer data)
 {
@@ -474,6 +478,8 @@
 	  N_("Disable preview pane of Mail, Contacts and Tasks."), NULL },	
 	{ "setup-only", '\0', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE,
 	  &setup_only, NULL, NULL },
+	{ "disable-vfolder", '\0', 0, G_OPTION_ARG_NONE, &disable_vfolder,
+	  N_("Disable virtual folders in Mail"), NULL },
 	{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining_args, NULL, NULL },
 	{ NULL }
 };
Index: plugins/groupwise-features/share-folder-common.c
===================================================================
--- plugins/groupwise-features/share-folder-common.c	(revision 34382)
+++ plugins/groupwise-features/share-folder-common.c	(working copy)
@@ -279,6 +279,10 @@
 	if (CAMEL_IS_VEE_STORE(store)) {
 		EMVFolderRule *rule;
 
+		/* ensures vfolder is running */
+		if (!vfolder_loaded ())
+			vfolder_load_storage ();
+
 		rule = em_vfolder_rule_new();
 		filter_rule_set_name((FilterRule *)rule, path);
 		vfolder_gui_add_rule(rule);
Index: plugins/groupwise-features/ChangeLog
===================================================================
--- plugins/groupwise-features/ChangeLog	(revision 34382)
+++ plugins/groupwise-features/ChangeLog	(working copy)
@@ -1,3 +1,10 @@
+2007-10-12  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #300336
+
+	* share-folder-common.c: (users_dialog_response):
+	Ensure vfolder is running.
+
 2007-09-27  Matthew Barnes  <mbarnes@redhat.com>
 
 	** Fixes part of bug #477045
Index: mail/em-folder-utils.c
===================================================================
--- mail/em-folder-utils.c	(revision 34382)
+++ mail/em-folder-utils.c	(working copy)
@@ -718,6 +718,10 @@
 	if (CAMEL_IS_VEE_STORE(store)) {
 		EMVFolderRule *rule;
 
+		/* ensures vfolder is running */
+		if (!vfolder_loaded ())
+			vfolder_load_storage ();
+
 		rule = em_vfolder_rule_new();
 		filter_rule_set_name((FilterRule *)rule, path);
 		vfolder_gui_add_rule(rule);
Index: mail/mail-vfolder.c
===================================================================
--- mail/mail-vfolder.c	(revision 34382)
+++ mail/mail-vfolder.c	(working copy)
@@ -960,6 +960,17 @@
 	g_free(storeuri);
 }
 
+/**
+ * vfolder_loaded
+ * Test if we have vfolder already inited or not.
+ * @return Whether was vfolder inited or not (by call of @ref vfolder_load_storage).
+ **/
+gboolean
+vfolder_loaded (void)
+{
+	return vfolder_hash != NULL;
+}
+
 void
 vfolder_revert(void)
 {
@@ -1125,6 +1136,10 @@
 	GtkWidget *w;
 	GtkDialog *gd;
 
+	/* this should be done before we call this function */
+	if (!vfolder_loaded ())
+		vfolder_load_storage ();
+
 	w = filter_rule_get_widget((FilterRule *)rule, (RuleContext *)context);
 
 	gd = (GtkDialog *)gtk_dialog_new_with_buttons(_("New Search Folder"),
@@ -1154,6 +1169,10 @@
 
 	g_return_if_fail (msg != NULL);
 
+	/* ensures vfolder is running */
+	if (!vfolder_loaded ())
+		vfolder_load_storage ();
+
 	rule = (EMVFolderRule*)em_vfolder_rule_from_message(context, msg, flags, source);
 	vfolder_gui_add_rule(rule);
 }
@@ -1164,7 +1183,11 @@
 	EMVFolderRule *rule;
 
 	g_return_if_fail (addr != NULL);
-	
+
+	/* ensures vfolder is running */
+	if (!vfolder_loaded ())
+		vfolder_load_storage ();
+
 	rule = (EMVFolderRule*)em_vfolder_rule_from_address(context, addr, flags, source);
 	vfolder_gui_add_rule(rule);
 }
Index: mail/mail-vfolder.h
===================================================================
--- mail/mail-vfolder.h	(revision 34382)
+++ mail/mail-vfolder.h	(working copy)
@@ -10,6 +10,7 @@
 struct _CamelInternetAddress;
 
 void vfolder_load_storage(void);
+gboolean vfolder_loaded (void);
 void vfolder_revert(void);
 
 void vfolder_edit (void);
Index: mail/em-folder-browser.c
===================================================================
--- mail/em-folder-browser.c	(revision 34382)
+++ mail/em-folder-browser.c	(working copy)
@@ -720,9 +720,14 @@
 	case ESB_SAVE:
 		d(printf("Save vfolder\n"));
 		if (efb->current_query) {
-			FilterRule *rule = vfolder_clone_rule(efb->current_query);			
+			FilterRule *rule;
 			char *name, *text;
-			
+
+			/* ensures vfolder is running */
+			if (!vfolder_loaded ())
+				vfolder_load_storage ();
+
+			rule = vfolder_clone_rule (efb->current_query);
 			text = e_search_bar_get_text(esb);
 			name = g_strdup_printf("%s %s", rule->name, (text&&text[0])?text:"''");
 			g_free (text);
Index: mail/ChangeLog
===================================================================
--- mail/ChangeLog	(revision 34383)
+++ mail/ChangeLog	(working copy)
@@ -1,3 +1,19 @@
+2007-10-12  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #300336
+
+	* mail-vfolder.h: (vfolder_loaded):
+	* mail-vfolder.c: (vfolder_loaded): New helper function.
+	* em-folder-utils.c: (emfu_popup_new_folder_response):
+	* mail-vfolder.c: (vfolder_gui_add_rule),
+	(vfolder_gui_add_from_message), (vfolder_gui_add_from_address):
+	* em-folder-browser.c: (emfb_search_menu_activated):
+	* em-folder-view.c: (emp_uri_popup_vfolder_sender),
+	(emp_uri_popup_vfolder_recipient), (vfolder_type_current):
+	Ensure vfolder is running.
+	* mail-component.c: (mc_startup): Do not start vfolder when
+	disabled by parameter '--disable-vfolder'.
+
 2007-10-12  Michael Monreal <michael.monreal@gmail.com>
 
 	** New inbox/outbox/sent icons (bug #479257)
Index: mail/em-folder-view.c
===================================================================
--- mail/em-folder-view.c	(revision 34382)
+++ mail/em-folder-view.c	(working copy)
@@ -1806,6 +1806,10 @@
 	}
 
 	if (url->path && url->path[0]) {
+		/* ensures vfolder is running */
+		if (!vfolder_loaded ())
+			vfolder_load_storage ();
+
 		addr = camel_internet_address_new ();
 		camel_address_decode (CAMEL_ADDRESS (addr), url->path);
 		vfolder_gui_add_from_address (addr, AUTO_FROM, emfv->folder_uri);
@@ -1832,6 +1836,10 @@
 	}
 
 	if (url->path && url->path[0]) {
+		/* ensures vfolder is running */
+		if (!vfolder_loaded ())
+			vfolder_load_storage ();
+
 		addr = camel_internet_address_new ();
 		camel_address_decode (CAMEL_ADDRESS (addr), url->path);
 		vfolder_gui_add_from_address (addr, AUTO_TO, emfv->folder_uri);
@@ -1859,10 +1867,15 @@
 	GPtrArray *uids;
 	
 	uids = message_list_get_selected (emfv->list);
-	
-	if (uids->len == 1)
+
+	if (uids->len == 1) {
+		/* ensures vfolder is running */
+		if (!vfolder_loaded ())
+			vfolder_load_storage ();
+		
 		vfolder_type_uid (emfv->folder, (char *) uids->pdata[0], emfv->folder_uri, type);
-	
+	}
+
 	em_utils_uids_free (uids);
 }
 
Index: mail/mail-component.c
===================================================================
--- mail/mail-component.c	(revision 34382)
+++ mail/mail-component.c	(working copy)
@@ -90,6 +90,10 @@
 
 #define d(x) 
 
+/* This one is defined in main.c and I use this because
+   I don't want to use gconf to store such information. */
+extern gboolean disable_vfolder;
+
 static void create_local_item_cb(EUserCreatableItemsHandler *handler, const char *item_type_name, void *data);
 static void view_changed_timeout_remove (EComponentView *component_view);
 
@@ -372,7 +376,8 @@
 
 	mc_setup_local_store(mc);
 	load_accounts(mc, mail_config_get_accounts());
-	vfolder_load_storage();
+	if (!disable_vfolder)
+		vfolder_load_storage();
 }
 
 static void
