[evolution-patches] sa-junk-plugin



Hello,

I've created a patch for sa-junk-plugin to add remote spamd option.
This kind of setup is useful in situation where you have spamassassin
installed on the mail server itself. For instance I have SA installed on
my home mailserver and I have office email account (no SA at office) and
I would like to use my home SA to identify junk. On my office account I
have report spam plugin(rspam) installed  so I didn't touch learn/report
stuff. Of course spamc is still required.
If this makes sense I'll add port option, ssl, and username option.

Thanks
-- 
Regards, 
Lucian Langa <cooly mips edu ms>

diff -Naur sa-junk-plugin.old/ChangeLog sa-junk-plugin/ChangeLog
--- sa-junk-plugin.old/ChangeLog	2006-09-02 09:43:32.000000000 +0300
+++ sa-junk-plugin/ChangeLog	2007-03-15 13:20:48.000000000 +0200
@@ -1,3 +1,14 @@
+2007-03-15  Lucian Langa <cooly mips edu ms>
+
+	* em-junk-filter.c: 
+	(em_junk_sa_check_junk): added use of remote spamd
+	(use_remote_cb),
+	(org_gnome_sa_use_remote),
+	(set_string_cb),
+	(org_gnome_sa_remote_config_mode)
+	
+	* org-gnome-sa-junk-plugin.eplug.xml: added items for remote spamd configuration.
+	
 2006-08-22  Kjartan Maraas  <kmaraas gnome org>
 
 	* em-junk-filter.c: (em_junk_sa_init): #if 0 out unused function and
diff -Naur sa-junk-plugin.old/em-junk-filter.c sa-junk-plugin/em-junk-filter.c
--- sa-junk-plugin.old/em-junk-filter.c	2006-09-02 09:43:32.000000000 +0300
+++ sa-junk-plugin/em-junk-filter.c	2007-03-15 13:27:44.000000000 +0200
@@ -47,6 +47,19 @@
 #include <mail/em-utils.h>
 #include <e-util/e-mktemp.h>
 
+#include <gtk/gtk.h>
+#include <gtk/gtkcombobox.h>
+#include <gtk/gtkliststore.h>
+#include <gtk/gtkcellrenderertext.h>
+#include <gtk/gtkcelllayout.h>
+#include <gtk/gtktable.h>
+#include <gtk/gtklabel.h>
+#include "mail/em-config.h"
+
+#define GCONF_KEY_SA_USE_REMOTE "/apps/evolution/mail/junk/sa/use_remote"
+#define GCONF_KEY_SA_USE_DAEMON "/apps/evolution/mail/junk/sa/use_daemon"
+#define GCONF_KEY_SA_SERVER "/apps/evolution/mail/junk/sa/server"
+
 #include <gconf/gconf-client.h>
 
 #define d(x) (camel_debug("junk")?(x):0)
@@ -65,6 +78,8 @@
 static void em_junk_sa_init (void);
 static void em_junk_sa_finalize (void);
 static void em_junk_sa_kill_spamd (void);
+GtkWidget *org_gnome_sa_use_remote(struct _EPlugin *epl, struct _EConfigHookItemFactoryData *data);
+GtkWidget *org_gnome_sa_remote_config_mode(struct _EPlugin *epl, struct _EConfigHookItemFactoryData *data);
 
 
 static gboolean em_junk_sa_tested = FALSE;
@@ -83,6 +98,7 @@
 /* volatile so not cached between threads */
 static volatile gboolean em_junk_sa_local_only;
 static volatile gboolean em_junk_sa_use_daemon;
+static volatile gboolean em_junk_sa_use_remote;
 static char * em_junk_sa_preferred_socket_path;
 
 static char *em_junk_sa_spamc_binaries [3] = {"spamc", "/usr/sbin/spamc", NULL};
@@ -110,6 +126,7 @@
 	CamelStream *stream;
 	char *program;
 	pid_t pid;
+	int i;
 	
 
 	if (camel_debug_start ("junk")) {
@@ -173,12 +190,11 @@
 		errno = errnosav;
 		return rv_err;
 	}
-	
+
 	/* parent process */
 	close (fds[0]);
 	if (output_buffer)
 		close (out_fds [1]);
-	
 	if (msg) {
 		stream = camel_stream_fs_new_with_fd (fds[1]);
 		
@@ -287,11 +303,17 @@
 		NULL,
 	};
 	
-	if (pipe_to_sa (NULL, NULL, argv) != 0)
+	// if we have remote sa enabled do not even bother with spamassassin binary
+	if (!em_junk_sa_use_remote)
+	{
+	    if (pipe_to_sa (NULL, NULL, argv) != 0)
 		em_junk_sa_available = FALSE;
-	else
+	    else
 		em_junk_sa_available = TRUE;
-
+	}
+	else
+	    em_junk_sa_available = FALSE;
+	    
 	em_junk_sa_tested = TRUE;
 }
 
@@ -533,14 +555,33 @@
 	char *argv[7], *to_free = NULL;
 	int i = 0, socket_i;
 	gboolean rv;
+	gchar *rs = NULL;
 	CamelMimeMessage *msg = target->m;
 
 	d(fprintf (stderr, "em_junk_sa_check_junk\n"));
 	
-	if (!em_junk_sa_is_available ())
-		return FALSE;
+	if (em_junk_sa_use_remote)
+	{
+	        em_junk_sa_spamc_binary = em_junk_sa_spamc_binaries [0];
+		em_junk_sa_use_spamc = 1;
+	}
+	else if (!em_junk_sa_is_available ())
+              return FALSE;
+
 
-	if (em_junk_sa_use_spamc && em_junk_sa_use_daemon) {
+	if (em_junk_sa_use_spamc)
+	{
+	    if (em_junk_sa_use_remote)
+	    {
+		out = g_byte_array_new ();
+		argv[i++] = em_junk_sa_spamc_binary;
+		argv[i++] = "-c";
+		argv[i++] = "-t";
+		argv[i++] = "60";
+		rs = g_strconcat("-d", gconf_client_get_string(em_junk_sa_gconf, GCONF_KEY_SA_SERVER, NULL), NULL);
+		argv[i++] = rs;
+	    }
+	    else if (em_junk_sa_use_daemon) {
 		out = g_byte_array_new ();
 		argv[i++] = em_junk_sa_spamc_binary;
 		argv[i++] = "-c";
@@ -554,12 +595,14 @@
 			argv[i++] = to_free = g_strdup (em_junk_sa_get_socket_path ());
 			pthread_mutex_unlock (&em_junk_sa_preferred_socket_path_lock);
 		}
+	    }
 	} else {
 		argv [i++] = "spamassassin";
 		argv [i++] = "--exit-code";
 		if (em_junk_sa_local_only)
 			argv [i++] = "--local";
 	}
+
 	
 	argv[i] = NULL;
 
@@ -582,6 +625,7 @@
 	}
 
 	g_free (to_free);
+	g_free (rs);
 
 	d(fprintf (stderr, "em_junk_sa_check_junk rv = %d\n", rv));
 
@@ -754,6 +798,7 @@
 
 		em_junk_sa_local_only = gconf_client_get_bool (em_junk_sa_gconf, "/apps/evolution/mail/junk/sa/local_only", NULL);
 		em_junk_sa_use_daemon = gconf_client_get_bool (em_junk_sa_gconf, "/apps/evolution/mail/junk/sa/use_daemon", NULL);
+		em_junk_sa_use_remote = gconf_client_get_bool (em_junk_sa_gconf, "/apps/evolution/mail/junk/sa/use_remote", NULL);
 
 		pthread_mutex_lock (&em_junk_sa_preferred_socket_path_lock);
 		g_free (em_junk_sa_preferred_socket_path);
@@ -815,3 +860,67 @@
 	g_object_unref(em_junk_sa_gconf);
 	em_junk_sa_kill_spamd ();
 }
+
+static void
+use_remote_cb (GtkWidget *widget, gpointer data)
+{
+    gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
+    gconf_client_set_bool (em_junk_sa_gconf, GCONF_KEY_SA_USE_REMOTE, active, NULL);
+    em_junk_sa_use_remote = active;
+}
+
+GtkWidget *
+org_gnome_sa_use_remote(struct _EPlugin *epl, struct _EConfigHookItemFactoryData *data)
+{
+   	GtkWidget *check;
+	guint i = ((GtkTable *)data->parent)->nrows;
+    
+	if (data->old)
+                return data->old;
+		
+	check = gtk_check_button_new_with_mnemonic (_("Use remote spamassassin server"));
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check),
+	     gconf_client_get_bool (em_junk_sa_gconf, GCONF_KEY_SA_USE_REMOTE, NULL));
+	g_signal_connect (GTK_TOGGLE_BUTTON (check), "toggled", G_CALLBACK (use_remote_cb), 
+	    GCONF_KEY_SA_USE_REMOTE);
+	gtk_table_attach((GtkTable *)data->parent, check, 0, 1, i, i+1, 0, 0, 0, 0);
+
+	return (GtkWidget *)check;
+}
+
+
+static void
+set_string_cb (GtkWidget *widget, gpointer data)
+{
+    const gchar *server = gtk_entry_get_text(GTK_ENTRY(widget));
+    gconf_client_set_string (em_junk_sa_gconf, data, server, NULL);
+}
+
+GtkWidget *
+org_gnome_sa_remote_config_mode(struct _EPlugin *epl, struct _EConfigHookItemFactoryData *data)
+{
+	GtkWidget *table1, *entry1, *label1;
+
+        if (data->old)
+                return data->old;
+
+	table1 = gtk_table_new (4, 2, FALSE);
+        gtk_container_add (GTK_CONTAINER (data->parent), table1);
+        gtk_table_set_row_spacings (GTK_TABLE (table1), 4);
+
+	label1 = gtk_label_new_with_mnemonic (_("Server: "));
+        gtk_table_attach (GTK_TABLE(table1), label1, 0, 1, 0, 1,
+                    (GtkAttachOptions) (GTK_FILL),
+                    (GtkAttachOptions) (0), 0, 0);
+        gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5);
+
+	entry1 = gtk_entry_new ();
+        gtk_table_attach(GTK_TABLE(table1), (GtkWidget *)entry1, 1, 2, 0, 1,
+			 GTK_FILL|GTK_EXPAND, 0, 0, 0);
+        gchar *server = gconf_client_get_string(em_junk_sa_gconf, GCONF_KEY_SA_SERVER, NULL);
+        gtk_entry_set_text(GTK_ENTRY(entry1), server);
+        g_signal_connect (GTK_ENTRY (entry1), "changed", G_CALLBACK (set_string_cb), GCONF_KEY_SA_SERVER);
+
+        return (GtkWidget *)table1;
+}
+
diff -Naur sa-junk-plugin.old/org-gnome-sa-junk-plugin.eplug.xml sa-junk-plugin/org-gnome-sa-junk-plugin.eplug.xml
--- sa-junk-plugin.old/org-gnome-sa-junk-plugin.eplug.xml	2006-01-11 13:14:51.000000000 +0200
+++ sa-junk-plugin/org-gnome-sa-junk-plugin.eplug.xml	2007-03-15 13:05:11.000000000 +0200
@@ -14,5 +14,14 @@
 				      	commit_reports="em_junk_sa_commit_reports"/>
 			</group>
 				</hook>
+		<!-- hook into the 'mail properties' menu -->
+		<hook class="org.gnome.evolution.mail.config:1.0">
+		        <group target="prefs" id="org.gnome.evolution.mail.prefs">
+					<item type="section_table" path="40.junk" label="Remote Spamassassin"/>
+                                        <item type="item_table" path="40.junk" factory="org_gnome_sa_use_remote"/>
+			                <item type="section_table" path="40.junk" label="SpamAssassin Server"></item>
+					<item type="item_table" path="40.junk/00.mode" factory="org_gnome_sa_remote_config_mode"/>
+		        </group>
+			    </hook>
 	</e-plugin>
 </e-plugin-list>


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