2006-03-10 [colin] 2.0.0cvs130
[claws.git] / src / plugins / spamassassin / spamassassin.c
index e4c5f1772ba82fcaf24b9b28010a04ad83ac791f..c27b16f66a4bc8a720424f5e40c6d8d0661e62b9 100644 (file)
@@ -83,6 +83,8 @@ static MessageCallback message_callback;
 static SpamAssassinConfig config;
 
 static PrefParam param[] = {
+       {"enable", "FALSE", &config.enable, P_BOOL,
+       NULL, NULL, NULL},
        {"transport", "0", &config.transport, P_INT,
         NULL, NULL, NULL},
        {"hostname", "localhost", &config.hostname, P_STRING,
@@ -124,6 +126,9 @@ static gboolean msg_is_spam(FILE *fp)
        struct message m;
        gboolean is_spam = FALSE;
 
+       if (!config.enable)
+               return FALSE;
+
        transport_init(&trans);
        switch (config.transport) {
        case SPAMASSASSIN_TRANSPORT_LOCALHOST:
@@ -182,7 +187,8 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data)
        int pid = 0;
        int status;
 
-       if (config.transport == SPAMASSASSIN_DISABLED) {
+       /* SPAMASSASSIN_DISABLED : keep test for compatibility purpose */
+       if (!config.enable || config.transport == SPAMASSASSIN_DISABLED) {
                log_error("Spamassassin plugin is disabled by its preferences.\n");
                return FALSE;
        }
@@ -284,7 +290,6 @@ int spamassassin_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam)
 {
        gchar *cmd = NULL;
        gchar *file = NULL;
-       gboolean async = FALSE;
        const gchar *shell = g_getenv("SHELL");
        gchar *spamc_wrapper = NULL;
 
@@ -338,7 +343,7 @@ int spamassassin_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam)
                                        tmpcmd = g_strconcat(shell?shell:"sh", " ", spamc_wrapper, " ",
                                                                                tmpfile, NULL);
                                        debug_print("%s\n", tmpcmd);
-                                       execute_command_line(tmpcmd, TRUE);
+                                       execute_command_line(tmpcmd, FALSE);
                                        g_free(tmpcmd);
                                }
                                if (tmpfile != NULL) {
@@ -371,17 +376,14 @@ int spamassassin_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam)
                                        g_free(tmpfile);
                                }
                        }
-                       async = TRUE;
                }
        }
        if (cmd == NULL) {
                return -1;
        }
        debug_print("%s\n", cmd);
-       /* only run async if we have a list, or we could end up
-        * forking lots of perl processes and bury the machine */
-       
-       execute_command_line(cmd, async);
+       /* only run sync calls to sa-learn/spamc to prevent system lockdown */
+       execute_command_line(cmd, FALSE);
        g_free(cmd);
        if (spamc_wrapper != NULL) {
                g_free(spamc_wrapper);
@@ -465,11 +467,10 @@ gint plugin_init(gchar **error)
                spamassassin_register_hook();
        }
 
-       if (config.transport == SPAMASSASSIN_DISABLED) {
+       if (!config.enable || config.transport == SPAMASSASSIN_DISABLED) {
                log_error("Spamassassin plugin is loaded but disabled by its preferences.\n");
        }
-
-       if (config.transport != SPAMASSASSIN_DISABLED) {
+       else {
                if (config.transport == SPAMASSASSIN_TRANSPORT_TCP)
                        debug_print("Enabling learner with a remote spamassassin server requires spamc/spamd 3.1.x\n");
                procmsg_register_spam_learner(spamassassin_learn);