Index: plugins/groupwise-features/share-folder-common.c
===================================================================
--- plugins/groupwise-features/share-folder-common.c	(revision 34389)
+++ 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 34389)
+++ plugins/groupwise-features/ChangeLog	(working copy)
@@ -1,3 +1,10 @@
+2007-10-16  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 34389)
+++ 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 34389)
+++ 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 34389)
+++ 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 34389)
+++ 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 34389)
+++ mail/ChangeLog	(working copy)
@@ -1,3 +1,23 @@
+2007-10-16  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 option '/apps/evolution/mail/display/enable_vfolders'.
+	* evolution-mail.schemas.in: Added schema for new option.
+	* mail-config.glade:
+	* em-mailer-prefs.h:
+	* em-mailer-prefs.c: Added checkbox for "Enable Search Folders" option.
+
 2007-10-15  Matthew Barnes  <mbarnes@redhat.com>
 
 	* em-folder-view.c:
Index: mail/mail-config.glade
===================================================================
--- mail/mail-config.glade	(revision 34389)
+++ mail/mail-config.glade	(working copy)
@@ -5262,6 +5262,62 @@
 			      <property name="fill">True</property>
 			    </packing>
 			  </child>
+			  <child>
+			    <widget class="GtkHBox" id="hboxEnableSearchFolders">
+			      <property name="visible">True</property>
+			      <property name="homogeneous">False</property>
+			      <property name="spacing">6</property>
+
+			      <child>
+				<widget class="GtkCheckButton" id="chkEnableSearchFolders">
+				  <property name="visible">True</property>
+				  <property name="can_focus">True</property>
+				  <property name="label" translatable="yes">Enable Sea_rch Folders</property>
+				  <property name="use_underline">True</property>
+				  <property name="relief">GTK_RELIEF_NORMAL</property>
+				  <property name="focus_on_click">True</property>
+				  <property name="active">True</property>
+				  <property name="inconsistent">False</property>
+				  <property name="draw_indicator">True</property>
+				</widget>
+				<packing>
+				  <property name="padding">0</property>
+				  <property name="expand">False</property>
+				  <property name="fill">False</property>
+				</packing>
+			      </child>
+
+			      <child>
+				<widget class="GtkLabel" id="lblEnableSFRestart">
+				  <property name="visible">True</property>
+				  <property name="label" translatable="yes">(Note: Requires restart)</property>
+				  <property name="use_underline">False</property>
+				  <property name="use_markup">False</property>
+				  <property name="justify">GTK_JUSTIFY_CENTER</property>
+				  <property name="wrap">False</property>
+				  <property name="selectable">False</property>
+				  <property name="xalign">0.5</property>
+				  <property name="yalign">0.5</property>
+				  <property name="xpad">0</property>
+				  <property name="ypad">0</property>
+				  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+				  <property name="width_chars">-1</property>
+				  <property name="single_line_mode">False</property>
+				  <property name="angle">0</property>
+				</widget>
+				<packing>
+				  <property name="padding">0</property>
+				  <property name="expand">False</property>
+				  <property name="fill">False</property>
+				</packing>
+			      </child>
+			    </widget>
+			    <packing>
+			      <property name="padding">0</property>
+			      <property name="expand">True</property>
+			      <property name="fill">True</property>
+			    </packing>
+			  </child>
 			</widget>
 			<packing>
 			  <property name="left_attach">0</property>
Index: mail/em-folder-view.c
===================================================================
--- mail/em-folder-view.c	(revision 34389)
+++ 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/evolution-mail.schemas.in
===================================================================
--- mail/evolution-mail.schemas.in	(revision 34389)
+++ mail/evolution-mail.schemas.in	(working copy)
@@ -401,6 +401,20 @@
     </schema>
 
     <schema>
+      <key>/schemas/apps/evolution/mail/display/enable_vfolders</key>
+      <applyto>/apps/evolution/mail/display/enable_vfolders</applyto>
+      <owner>evolution-mail</owner>
+      <type>bool</type>
+      <default>true</default>
+      <locale name="C">
+         <short>Enable Search Folders</short>
+         <long>
+          Enable Search Folders on startup.
+         </long>
+      </locale>
+    </schema>
+
+    <schema>
       <key>/schemas/apps/evolution/mail/display/safe_list</key>
       <applyto>/apps/evolution/mail/display/safe_list</applyto>
       <owner>evolution-mail</owner>
Index: mail/mail-component.c
===================================================================
--- mail/mail-component.c	(revision 34389)
+++ mail/mail-component.c	(working copy)
@@ -365,6 +365,7 @@
 mc_startup(MailComponent *mc)
 {
 	static int started = 0;
+	GConfClient *gconf;
 
 	if (started)
 		return;
@@ -372,7 +373,11 @@
 
 	mc_setup_local_store(mc);
 	load_accounts(mc, mail_config_get_accounts());
-	vfolder_load_storage();
+
+	gconf = mail_config_get_gconf_client();
+
+	if (gconf_client_get_bool (gconf, "/apps/evolution/mail/display/enable_vfolders", NULL))
+		vfolder_load_storage();
 }
 
 static void
Index: mail/em-mailer-prefs.c
===================================================================
--- mail/em-mailer-prefs.c	(revision 34389)
+++ mail/em-mailer-prefs.c	(working copy)
@@ -958,6 +958,11 @@
 		gtk_widget_set_sensitive ((GtkWidget *) prefs->citation_color, FALSE);
 	g_free (buf);
 	
+	prefs->enable_search_folders = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "chkEnableSearchFolders"));
+	toggle_button_init (prefs, prefs->enable_search_folders, FALSE,
+			    "/apps/evolution/mail/display/enable_vfolders",
+			    G_CALLBACK (toggle_button_toggled));
+
 	/* Deleting Mail */
 	prefs->empty_trash = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "chkEmptyTrashOnExit"));
 	prefs->empty_trash_days = GTK_OPTION_MENU (glade_xml_get_widget (gui, "omenuEmptyTrashDays"));
Index: mail/em-mailer-prefs.h
===================================================================
--- mail/em-mailer-prefs.h	(revision 34389)
+++ mail/em-mailer-prefs.h	(working copy)
@@ -80,6 +80,7 @@
 	struct _GtkOptionMenu *charset;
 	struct _GtkToggleButton *citation_highlight;
 	struct _GtkColorButton *citation_color;
+	struct _GtkToggleButton *enable_search_folders;
 	
 	/* Deleting Mail */
 	struct _GtkToggleButton *empty_trash;
