--- copies/shipped/evolution-2.8.1/mail/filtertypes.xml	2005-06-21 06:33:47.000000000 +0100
+++ evolution-2.9.5/mail/filtertypes.xml	2006-12-01 14:02:12.000000000 +0000
@@ -739,6 +739,10 @@
   <code>(play-sound ${sound})</code>
   <input type="file" name="sound"/>
  </part>
+ <part name="notify">
+  <title>New Mail Notify</title>
+  <code>(notify)</code>
+ </part>
  <part name="shell">
   <title>Run Program</title>
   <code>(shell "/bin/sh" "-c" ${command})</code>
--- copies/shipped/evolution-2.8.1/mail/mail-session.c	2006-04-24 12:20:33.000000000 +0100
+++ evolution-2.9.5/mail/mail-session.c	2007-01-09 19:59:24.000000000 +0000
@@ -23,6 +23,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 
 #include <glib.h>
 #include <glib/gstdio.h>
@@ -53,6 +54,8 @@
 #include "mail-session.h"
 #include "mail-tools.h"
 
+#include "em-event.h"
+
 #define d(x)
 
 CamelSession *session;
@@ -93,6 +96,14 @@ static void ms_thread_status(CamelSessio
 static void *ms_thread_msg_new(CamelSession *session, CamelSessionThreadOps *ops, unsigned int size);
 static void ms_thread_msg_free(CamelSession *session, CamelSessionThreadMsg *m);
 
+#define NOTIFY_THROTTLE 30       /* min no. seconds between newmail notifications */
+static guint notify_id = 0;
+static int notify_type = -1;
+
+static time_t last_notify = 0;
+static guint notify_idle_id = 0;
+static gboolean notify_idle_cb (gpointer user_data);
+
 static void
 init (MailSession *session)
 {
@@ -454,6 +465,93 @@ session_system_beep (CamelFilterDriver *
 			       driver, user_data, NULL);
 }
 
+static gboolean
+notify_idle_cb (gpointer user_data)
+{
+	GConfClient *gconf;
+	char *filename;
+	
+	gconf = mail_config_get_gconf_client ();
+	
+	switch (notify_type) {
+	case MAIL_CONFIG_NOTIFY_PLAY_SOUND:
+		filename = gconf_client_get_string (gconf, "/apps/evolution/mail/notify/sound", NULL);
+		if (filename != NULL) {
+			gnome_sound_play (filename);
+			g_free (filename);
+		}
+		break;
+	case MAIL_CONFIG_NOTIFY_BEEP:
+		gdk_beep ();
+		break;
+	default:
+		break;
+	}
+        
+    /* For now we create the EMEventTargetFolder with a dummy URI
+     * to fool the downstream code - the actual folder is not important
+     * to us anyway */
+	EMEvent *e = em_event_peek();
+        EMEventTargetFolder *t = em_event_target_new_folder(e, "mbox:dummy", EM_EVENT_FOLDER_NEWMAIL);
+        
+	/** @Event: folder.changed
+	 * @Title: Folder changed
+	 * @Target: EMEventTargetFolder
+	 * 
+	 * folder.changed is emitted whenever a folder changes.  There is no detail on how the folder has changed.
+	 */
+	e_event_emit((EEvent *)e, "folder.changed", (EEventTarget *)t);
+        
+        time (&last_notify);
+	
+	notify_idle_id = 0;
+	
+	return FALSE;
+}
+
+static void
+notify_type_changed (GConfClient *client, guint cnxn_id,
+		     GConfEntry *entry, gpointer user_data)
+{
+	notify_type = gconf_client_get_int (client, "/apps/evolution/mail/notify/type", NULL);
+}
+
+static void
+main_notify (CamelFilterDriver *driver, gpointer user_data)
+{
+        time_t now;
+    
+        if (notify_type == -1) {
+		/* need to track the user's new-mail-notification settings... */
+		GConfClient *gconf;
+		
+		gconf = mail_config_get_gconf_client ();
+		gconf_client_add_dir (gconf, "/apps/evolution/mail/notify",
+				      GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
+		notify_id = gconf_client_notify_add (gconf, "/apps/evolution/mail/notify",
+						     notify_type_changed, NULL, NULL, NULL);
+		notify_type = gconf_client_get_int (gconf, "/apps/evolution/mail/notify/type", NULL);
+	}
+	
+	time (&now);
+	if (notify_type != 0 && notify_idle_id == 0 && (now - last_notify >= NOTIFY_THROTTLE))
+		notify_idle_id = g_idle_add_full (G_PRIORITY_LOW, notify_idle_cb, user_data, NULL);
+
+}
+
+static void
+session_notify (CamelFilterDriver *driver, gpointer user_data)
+{
+	MailSession *ms = (MailSession *) session;
+	
+	camel_object_ref (session);
+    
+	mail_async_event_emit (ms->async, MAIL_ASYNC_GUI, (MailAsyncFunc) main_notify,
+			       driver, user_data, NULL);
+
+}    
+
+
 static CamelFilterDriver *
 main_get_filter_driver (CamelSession *session, const char *type, CamelException *ex)
 {
@@ -495,6 +593,7 @@ main_get_filter_driver (CamelSession *se
 	camel_filter_driver_set_shell_func (driver, mail_execute_shell_command, NULL);
 	camel_filter_driver_set_play_sound_func (driver, session_play_sound, NULL);
 	camel_filter_driver_set_system_beep_func (driver, session_system_beep, NULL);
+	camel_filter_driver_set_notify_func (driver, session_notify, NULL);
 
 	if ((!strcmp (type, FILTER_SOURCE_INCOMING) || !strcmp (type, FILTER_SOURCE_JUNKTEST))
 	    && camel_session_check_junk (session)) {
@@ -524,8 +623,15 @@ main_get_filter_driver (CamelSession *se
 		g_string_free (fsearch, TRUE);
 		g_string_free (faction, TRUE);
 	}
-	
-	g_object_unref (fc);
+        
+        if (!strcmp (type, FILTER_SOURCE_INCOMING)) {
+	        /* implicit newmail notification as last rule.
+	        * Note we check junk flag, in case any user rules set this
+	        */
+	        camel_filter_driver_add_rule (driver, "New Mail Notify", "(match-all (not (system-flag \"junk\")) (not (system-flag \"seen\")))", "(notify)");
+        }
+    
+        g_object_unref (fc);
 	
 	return driver;
 }
--- copies/shipped/evolution-2.8.1/mail/mail-folder-cache.c	2006-08-07 05:47:44.000000000 +0100
+++ evolution-2.9.5/mail/mail-folder-cache.c	2006-12-01 16:21:58.000000000 +0000
@@ -123,13 +123,6 @@ static void folder_finalised(CamelObject
 static guint ping_id = 0;
 static gboolean ping_cb (gpointer user_data);
 
-static guint notify_id = 0;
-static int notify_type = -1;
-
-static time_t last_notify = 0;
-static guint notify_idle_id = 0;
-static gboolean notify_idle_cb (gpointer user_data);
-
 
 /* Store to storeinfo table, active stores */
 static GHashTable *stores = NULL;
@@ -154,50 +147,12 @@ free_update(struct _folder_update *up)
 	g_free(up);
 }
 
-static gboolean
-notify_idle_cb (gpointer user_data)
-{
-	GConfClient *gconf;
-	char *filename;
-	
-	gconf = mail_config_get_gconf_client ();
-	
-	switch (notify_type) {
-	case MAIL_CONFIG_NOTIFY_PLAY_SOUND:
-		filename = gconf_client_get_string (gconf, "/apps/evolution/mail/notify/sound", NULL);
-		if (filename != NULL) {
-			gnome_sound_play (filename);
-			g_free (filename);
-		}
-		break;
-	case MAIL_CONFIG_NOTIFY_BEEP:
-		gdk_beep ();
-		break;
-	default:
-		break;
-	}
-	
-	time (&last_notify);
-	
-	notify_idle_id = 0;
-	
-	return FALSE;
-}
-
-static void
-notify_type_changed (GConfClient *client, guint cnxn_id,
-		     GConfEntry *entry, gpointer user_data)
-{
-	notify_type = gconf_client_get_int (client, "/apps/evolution/mail/notify/type", NULL);
-}
-
 static void
 real_flush_updates(void *o, void *event_data, void *data)
 {
 	struct _MailComponent *component;
 	struct _EMFolderTreeModel *model;
 	struct _folder_update *up;
-	time_t now;
 	
 	component = mail_component_peek ();
 	model = mail_component_peek_tree_model (component);
@@ -231,36 +186,6 @@ real_flush_updates(void *o, void *event_
 		/* update unread counts */
 		em_folder_tree_model_set_unread_count (model, up->store, up->full_name, up->unread);
 		
-		/* new mail notification */
-		if (notify_type == -1) {
-			/* need to track the user's new-mail-notification settings... */
-			GConfClient *gconf;
-			
-			gconf = mail_config_get_gconf_client ();
-			gconf_client_add_dir (gconf, "/apps/evolution/mail/notify",
-					      GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
-			notify_id = gconf_client_notify_add (gconf, "/apps/evolution/mail/notify",
-							     notify_type_changed, NULL, NULL, NULL);
-			notify_type = gconf_client_get_int (gconf, "/apps/evolution/mail/notify/type", NULL);
-		}
-		
-		time (&now);
-		if (notify_type != 0 && up->new && notify_idle_id == 0 && (now - last_notify >= 5))
-			notify_idle_id = g_idle_add_full (G_PRIORITY_LOW, notify_idle_cb, NULL, NULL);
-		
-		if (up->uri) {
-			EMEvent *e = em_event_peek();
-			EMEventTargetFolder *t = em_event_target_new_folder(e, up->uri, up->new?EM_EVENT_FOLDER_NEWMAIL:0);
-
-			/** @Event: folder.changed
-			 * @Title: Folder changed
-			 * @Target: EMEventTargetFolder
-			 * 
-			 * folder.changed is emitted whenever a folder changes.  There is no detail on how the folder has changed.
-			 */
-			e_event_emit((EEvent *)e, "folder.changed", (EEventTarget *)t);
-		}
-
 		free_update(up);
 		
 		LOCK(info_lock);
