[evolution-patches] Initial patch for spam-filter e-plugin



Hi,

Here is the initial patch and plugin for the task of making
sa/spamd-junk filtering an e-plugin.

This patch makes evolution not to do junk-filtering using
spamassasin/spamd by default. If user wants to use sa/spamd for junk
learning, he has to enable the "sa junk plugin" (and restart evo.).

I have introduced a new "store.load" event which is emitted when the
store is loaded and it passes session in the target. Listeners can catch
it and assign their own junk-plugin object in the session.

The files specific to the sa/spamd operations are still in mail/ ,
probably they should be moved to plugins/junk-sa-plugin/ .

Thanks,

Vivek Jain



/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 *
 *  Authors: Vivek Jain <jvivek novell com>
 *
 *  Copyright 2004 Novell, Inc. (www.novell.com)
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of version 2 of the GNU General Public
 *  License as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
 *
 */

/* This is prototype code only, this may, or may not, use undocumented
 * unstable or private internal function calls. */

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>

#include <glib.h>
#include <glib/gi18n.h>

#include <camel/camel-folder.h>
#include <camel/camel-session.h>
#include <camel/camel-exception.h>
#include <camel/camel-mime-message.h>
#include <camel/camel-multipart.h>
#include <camel/camel-utf8.h>

#include "e-util/e-error.h"

#include "mail/em-menu.h"
#include "mail/em-utils.h"
#include <mail/mail-component.h>
#include <mail/em-junk-filter.h>

/* these are sort of mail-internal */
#include "mail/mail-mt.h"
#include "mail/mail-ops.h"
#include <mail/em-event.h>


void 
org_gnome_junk_sa_plugin (EPlugin *ep, EMEventTargetSession *target)
{
	CamelSession *session ;

	session = target->session;
	session->junk_plugin = CAMEL_JUNK_PLUGIN (em_junk_filter_get_plugin ());
	if (session->junk_plugin)
		camel_junk_plugin_init (session->junk_plugin);

}



<?xml version="1.0"?>
<e-plugin-list>
  <!-- the path to the shared library -->
  <e-plugin
	  id="org.gnome.plugin.plugin.sa.junk"
    type="shlib"
    location="@PLUGINDIR@/liborg-gnome-junk-sa-plugin.so"
    _name="Sa Junk Plugin">
    
    <author name="Vivek Jain" email="jvivek novell com"/>
    <_description>A plugin for filtering junk using spam assasin (Needs Restart of Evolution)</_description>

		<hook class="org.gnome.evolution.mail.events:1.0">
			<event
				target="session"
				id="store.load"
					handle="org_gnome_junk_sa_plugin"/>
		</hook>

 </e-plugin>
</e-plugin-list>
INCLUDES =						\
	-I$(top_srcdir)					\
	$(EVOLUTION_MAIL_CFLAGS)

@EVO_PLUGIN_RULE@

plugin_DATA = org-gnome-junk-sa-plugin.eplug 
plugin_LTLIBRARIES = liborg-gnome-junk-sa-plugin.la

liborg_gnome_junk_sa_plugin_la_SOURCES = junk-sa-plugin.c
liborg_gnome_junk_sa_plugin_la_LDFLAGS = -module -avoid-version

EXTRA_DIST = 					\
	org-gnome-junk-sa-plugin.eplug.xml

BUILT_SOURCES = org-gnome-junk-sa-plugin.eplug
CLEANFILES = $(BUILT_SOURCES)
Index: em-event.h
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-event.h,v
retrieving revision 1.4
diff -u -p -r1.4 em-event.h
--- em-event.h	22 Oct 2004 04:32:27 -0000	1.4
+++ em-event.h	19 Jun 2005 11:43:06 -0000
@@ -34,6 +34,7 @@ extern "C" {
 
 struct _CamelFolder;
 struct _CamelMimeMessage;
+struct _CamelSession;
 
 typedef struct _EMEvent EMEvent;
 typedef struct _EMEventClass EMEventClass;
@@ -42,6 +43,7 @@ typedef struct _EMEventClass EMEventClas
 enum _em_event_target_t {
 	EM_EVENT_TARGET_FOLDER,
 	EM_EVENT_TARGET_MESSAGE,
+	EM_EVENT_TARGET_SESSION,
 };
 
 /* Flags that describe TARGET_FOLDER */
@@ -61,6 +63,12 @@ struct _EMEventTargetFolder {
 	char *uri;
 };
 
+struct _EMEventTargetSession {
+	EEventTarget target;
+	struct _CamelSession *session;
+};
+
+typedef struct _EMEventTargetSession EMEventTargetSession; 
 typedef struct _EMEventTargetMessage EMEventTargetMessage;
 
 struct _EMEventTargetMessage {
@@ -89,6 +97,7 @@ EMEvent *em_event_peek(void);
 
 EMEventTargetFolder *em_event_target_new_folder(EMEvent *emp, const char *uri, guint32 flags);
 EMEventTargetMessage *em_event_target_new_message(EMEvent *emp, struct _CamelFolder *folder, struct _CamelMimeMessage *message, const char *uid, guint32 flags);
+EMEventTargetSession *em_event_target_new_session(EMEvent *emp, struct _CamelSession *session);
 
 /* ********************************************************************** */
 
Index: em-event.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-event.c,v
retrieving revision 1.8
diff -u -p -r1.8 em-event.c
--- em-event.c	3 Dec 2004 03:38:03 -0000	1.8
+++ em-event.c	19 Jun 2005 11:43:06 -0000
@@ -34,6 +34,8 @@
 #include <e-util/e-icon-factory.h>
 
 #include <camel/camel-store.h>
+#include <camel/camel-session.h>
+
 #include <camel/camel-folder.h>
 #include <camel/camel-mime-message.h>
 #include <camel/camel-string-utils.h>
@@ -77,8 +79,14 @@ eme_target_free(EEvent *ep, EEventTarget
 			camel_object_unref(s->message);
 		g_free(s->uid);
 		break; }
-	}
-
+	case EM_EVENT_TARGET_SESSION: {
+		EMEventTargetSession *s = (EMEventTargetSession *)t;
+		
+		if (s->session)
+        	      camel_object_unref(s->session);
+	         break;
+      }
+ }
 	((EEventClass *)eme_parent)->target_free(ep, t);
 }
 
@@ -128,6 +136,16 @@ EMEvent *em_event_peek(void)
 	return em_event;
 }
 
+EMEventTargetSession *
+em_event_target_new_session (EMEvent *eme, CamelSession *session)
+{
+	EMEventTargetSession *t = e_event_target_new(&eme->popup, EM_EVENT_TARGET_SESSION, sizeof(*t));
+
+	t->session = (CamelSession *)session;
+
+	return t;
+}
+
 EMEventTargetFolder *
 em_event_target_new_folder (EMEvent *eme, const char *uri, guint32 flags)
 {
@@ -172,9 +190,14 @@ static const EEventHookTargetMask emeh_m
 	{ 0 }
 };
 
+static const EEventHookTargetMask emeh_session_masks[] = {
+	{0}
+};
+
 static const EEventHookTargetMap emeh_targets[] = {
 	{ "folder", EM_EVENT_TARGET_FOLDER, emeh_folder_masks },
 	{ "message", EM_EVENT_TARGET_MESSAGE, emeh_message_masks },
+	{"session", EM_EVENT_TARGET_SESSION, emeh_session_masks },
 	{ 0 }
 };
 
Index: mail-component.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-component.c,v
retrieving revision 1.119
diff -u -p -r1.119 mail-component.c
--- mail-component.c	17 Jun 2005 15:20:29 -0000	1.119
+++ mail-component.c	19 Jun 2005 11:43:07 -0000
@@ -45,7 +45,8 @@
 #include "em-folder-selection.h"
 #include "em-folder-utils.h"
 #include "em-migrate.h"
-
+#include "em-event.h"
+#include "e-util/e-event.h"
 #include "widgets/misc/e-info-label.h"
 #include "e-util/e-error.h"
 
@@ -1026,6 +1027,8 @@ mail_component_load_store_by_uri (MailCo
 	CamelException ex;
 	CamelStore *store;
 	CamelProvider *prov;
+	EMEvent *eme;
+	EMEventTargetMessage *target;
 
 	MAIL_COMPONENT_DEFAULT(component);
 	
@@ -1059,6 +1062,9 @@ mail_component_load_store_by_uri (MailCo
 
 	mail_component_add_store(component, store, name);
 	camel_object_unref (store);
+	eme = em_event_peek();
+	target = em_event_target_new_session(eme, session);
+	e_event_emit((EEvent *)eme, "store.load", (EEventTarget *)target);
 	
 	return store;
 }
Index: mail-session.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-session.c,v
retrieving revision 1.104
diff -u -p -r1.104 mail-session.c
--- mail-session.c	16 May 2005 06:15:38 -0000	1.104
+++ mail-session.c	19 Jun 2005 11:43:07 -0000
@@ -56,6 +56,8 @@
 #include "libedataserver/e-msgport.h"
 #include "em-junk-filter.h"
 #include "e-util/e-error.h"
+#include "e-util/e-event.h"
+#include "em-event.h"
 
 #define d(x)
 
@@ -96,6 +98,13 @@ static CamelFilterDriver *get_filter_dri
 static void ms_thread_status(CamelSession *session, CamelSessionThreadMsg *msg, const char *text, int pc);
 static void *ms_thread_msg_new(CamelSession *session, CamelSessionThreadOps *ops, unsigned int size);
 static void ms_thread_msg_free(CamelSession *session, CamelSessionThreadMsg *m);
+static CamelJunkPlugin * get_junk_plugin (void);
+static const char * dummy_junk_get_name (void);
+static gboolean dummy_junk_check_junk (CamelMimeMessage *m);
+static void 	dummy_junk_report_junk (CamelMimeMessage *m);
+static void 	dummy_junk_report_not_junk(CamelMimeMessage *m);
+static void 	dummy_junk_commit_reports (void);
+static void 	dummy_junk_init (void);
 
 static void
 init (MailSession *session)
@@ -623,12 +632,68 @@ mail_session_check_junk_notify (GConfCli
 	}
 }
 
+static CamelJunkPlugin 
+dummy_junk_plugin = {
+	{
+		dummy_junk_get_name,
+		1,
+		dummy_junk_check_junk,
+		dummy_junk_report_junk,
+		dummy_junk_report_notjunk,
+		dummy_junk_commit_reports,
+		dummy_junk_init,
+	},
+	NULL,
+	NULL
+};
+
+static void
+dummy_junk_init ()
+{
+
+}
+
+static const char * 
+dummy_junk_get_name ()
+{
+ return _("dummy (does nothing)");
+}
+
+static gboolean
+dummy_junk_check_junk (CamelMimeMessage *msg)
+{
+ return FALSE;
+}
+
+static void
+dummy_junk_report_junk (CamelMimeMessage *msg)
+{
+
+}
+
+static void
+dummy_junk_report_not_junk (CamelMimeMessage *msg)
+{
+
+}
+static void
+dummy_junk_commit_reports (void)
+{
+
+}
+
+static CamelJunkPlugin * 
+get_junk_plugin ()
+{
+  return &dummy_junk_plugin;	
+}
+
 void
 mail_session_init (const char *base_directory)
 {
 	char *camel_dir;
 	GConfClient *gconf;
-	
+
 	if (camel_init (base_directory, TRUE) != 0)
 		exit (0);
 
@@ -645,7 +710,8 @@ mail_session_init (const char *base_dire
 	session_check_junk_notify_id = gconf_client_notify_add (gconf, "/apps/evolution/mail/junk",
 								(GConfClientNotifyFunc) mail_session_check_junk_notify,
 								session, NULL, NULL);
-	session->junk_plugin = CAMEL_JUNK_PLUGIN (em_junk_filter_get_plugin ());
+	session->junk_plugin = CAMEL_JUNK_PLUGIN (get_junk_plugin ());
+
 	if (session->junk_plugin)
 		camel_junk_plugin_init (session->junk_plugin);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]