[evolution-patches] Probable solution for evolution-plugins junk learn cann't work with SpamAssassin 3.0



hi guys,

	Evolution-plugins junk learn can not work with SpamAssassin3.0 because
the sync option of "sa-learn" needed after SpamAssassin3.0 is "--sync"
and "--no-sync", but evolution-plugins assumes that junk learning works
based on SpamAssassin 2.x, whose sync option of sa-learn is "--rebuild"
and "--no-rebuild". 

	so i did the patch to resolve this problem. it analysize the output of
"sa-learn --version", and get the main version No.. Anyone who could do
me a favor to review it for me, and give me suggestions?

regards,

jerry
Index: plugins/sa-junk-plugin/em-junk-filter.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/sa-junk-plugin/em-junk-filter.c,v
retrieving revision 1.4.2.1
diff -u -p -r1.4.2.1 em-junk-filter.c
--- plugins/sa-junk-plugin/em-junk-filter.c	3 Oct 2005 08:53:24 -0000	1.4.2.1
+++ plugins/sa-junk-plugin/em-junk-filter.c	28 Dec 2005 07:04:45 -0000
@@ -586,12 +586,45 @@ em_junk_sa_check_junk(EPlugin *ep, EMJun
 	return rv;
 }
 
+int get_spamassassin_version ()
+{
+	GByteArray *out = g_byte_array_new ();
+	int i;
+	int version = 0;
+	int rv;
+	
+	char * argv[3] = {
+		"sa-learn",
+		"--version",
+		NULL
+	};
+
+	if(pipe_to_sa_full (NULL, NULL, argv, -1, 1, out) < 0){
+		if(out)
+			g_byte_array_free (out, TRUE);
+
+		return version;
+	}
+
+	if(out->len > 0){
+		for(i = 0; i < out->len; i++){
+			if(g_ascii_isdigit (out->data[i])){
+				version = (out->data[i] - '0');
+				break;
+			}
+		}	
+	}
+
+
+	if (out)
+		g_byte_array_free (out, TRUE);
+
+	return version;
+}
+
 void
 em_junk_sa_report_junk (EPlugin *ep, EMJunkHookTarget *target)
 {
+	char *sync_op = ((get_spamassassin_version() >= 3) ? "--no-sync": "--no-rebuild");
 	char *argv[6] = {
 		"sa-learn",
-		"--no-rebuild",
+		sync_op,
 		"--spam",
 		"--single",
 		NULL,
@@ -618,9 +651,10 @@ em_junk_sa_report_junk (EPlugin *ep, EMJ
 void
 em_junk_sa_report_non_junk (EPlugin *ep, EMJunkHookTarget *target)
 {
+	char *sync_op = ((get_spamassassin_version() >= 3) ? "--no-sync": "--no-rebuild");
 	char *argv[6] = {
 		"sa-learn",
-		"--no-rebuild",
+		sync_op,
 		"--ham",
 		"--single",
 		NULL,
@@ -643,9 +677,10 @@ em_junk_sa_report_non_junk (EPlugin *ep,
 void
 em_junk_sa_commit_reports (EPlugin *ep, EMJunkHookTarget *target)
 {
+	char *sync_op = ((get_spamassassin_version() >= 3) ? "--sync": "--rebuild");
 	char *argv[4] = {
 		"sa-learn",
-		"--rebuild",
+		sync_op,
 		NULL,
 		NULL
 	};


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