0.9.4claws18
authorChristoph Hohmann <reboot@gmx.ch>
Mon, 11 Aug 2003 21:47:44 +0000 (21:47 +0000)
committerChristoph Hohmann <reboot@gmx.ch>
Mon, 11 Aug 2003 21:47:44 +0000 (21:47 +0000)
* src/plugins/spamassassin/spamassassin.c
        run spam check in background process

ChangeLog.claws
configure.ac
src/plugins/spamassassin/spamassassin.c

index 1a5133f3e39883c9089d71313e169cf41821bd29..a823f9086b2825149484293dbf1a83d21ee76954 100644 (file)
@@ -1,3 +1,8 @@
+2003-08-11 [christoph] 0.9.4claws18
+
+       * src/plugins/spamassassin/spamassassin.c
+               run spam check in background process
+
 2003-08-10 [alfons]    0.9.4claws17
 
        * src/summaryview.c
 2003-08-10 [alfons]    0.9.4claws17
 
        * src/summaryview.c
index 95b8bd63bd88291c663e2178b19d4d95f44ff701..395b42d3c89f57e55fa811a31e054d997aee6784 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=4
 INTERFACE_AGE=0
 BINARY_AGE=0
 MICRO_VERSION=4
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=17
+EXTRA_VERSION=18
 if test $EXTRA_VERSION -eq 0; then
     VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}claws
 else
 if test $EXTRA_VERSION -eq 0; then
     VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}claws
 else
index b42af74b84fda1def5c0c004cd769fc7af238364..8af60adcb216923b0d170ea6a5a1e938691389ea 100644 (file)
@@ -23,6 +23,9 @@
 
 #include "defs.h"
 
 
 #include "defs.h"
 
+#include <sys/types.h>
+#include <sys/wait.h>
+
 #include <glib.h>
 
 #if HAVE_LOCALE_H
 #include <glib.h>
 
 #if HAVE_LOCALE_H
 #include <pwd.h>
 #endif
 
 #include <pwd.h>
 #endif
 
+enum {
+    CHILD_RUNNING = 1 << 0,
+    TIMEOUT_RUNNING = 1 << 1,
+};
+
 static guint hook_id;
 static int flags = SPAMC_RAW_MODE | SPAMC_SAFE_FALLBACK | SPAMC_CHECK_ONLY;
 static gchar *username = NULL;
 static guint hook_id;
 static int flags = SPAMC_RAW_MODE | SPAMC_SAFE_FALLBACK | SPAMC_CHECK_ONLY;
 static gchar *username = NULL;
@@ -88,20 +96,22 @@ static PrefParam param[] = {
        {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
 
        {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
 
-static gboolean mail_filtering_hook(gpointer source, gpointer data)
+gboolean timeout_func(gpointer data)
 {
 {
-       MailFilteringData *mail_filtering_data = (MailFilteringData *) source;
-       MsgInfo *msginfo = mail_filtering_data->msginfo;
-       gboolean is_spam = FALSE;
-       FILE *fp = NULL;
-       struct message m;
-       struct sockaddr addr;
-       int ret;
+       gint *running = (gint *) data;
 
 
-       if (!config.enable)
-               return FALSE;
+       if (*running & CHILD_RUNNING)
+               return TRUE;
 
 
-       debug_print("Filtering message %d\n", msginfo->msgnum);
+       *running &= ~TIMEOUT_RUNNING;
+       return FALSE;
+}
+
+static gboolean msg_is_spam(FILE *fp)
+{
+       struct sockaddr addr;
+       struct message m;
+       gboolean is_spam = FALSE;
 
        if (lookup_host(config.hostname, config.port, &addr) != EX_OK) {
                debug_print("failed to look up spamd host\n");
 
        if (lookup_host(config.hostname, config.port, &addr) != EX_OK) {
                debug_print("failed to look up spamd host\n");
@@ -112,21 +122,14 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data)
        m.max_len = config.max_size * 1024;
        m.timeout = 30;
 
        m.max_len = config.max_size * 1024;
        m.timeout = 30;
 
-       if ((fp = procmsg_open_message(msginfo)) == NULL) {
-               debug_print("failed to open message file\n");
-               return FALSE;
-       }
-
        if (message_read(fileno(fp), flags, &m) != EX_OK) {
                debug_print("failed to read message\n");
        if (message_read(fileno(fp), flags, &m) != EX_OK) {
                debug_print("failed to read message\n");
-               fclose(fp);
                message_cleanup(&m);
                return FALSE;
        }
 
                message_cleanup(&m);
                return FALSE;
        }
 
-       if ((ret = message_filter(&addr, username, flags, &m)) != EX_OK) {
+       if (message_filter(&addr, username, flags, &m) != EX_OK) {
                debug_print("filtering the message failed\n");
                debug_print("filtering the message failed\n");
-               fclose(fp);
                message_cleanup(&m);
                return FALSE;
        }
                message_cleanup(&m);
                return FALSE;
        }
@@ -135,6 +138,54 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data)
                is_spam = TRUE;
 
        message_cleanup(&m);
                is_spam = TRUE;
 
        message_cleanup(&m);
+
+       return is_spam;
+}
+
+static gboolean mail_filtering_hook(gpointer source, gpointer data)
+{
+       MailFilteringData *mail_filtering_data = (MailFilteringData *) source;
+       MsgInfo *msginfo = mail_filtering_data->msginfo;
+       gboolean is_spam = FALSE;
+       FILE *fp = NULL;
+       int pid = 0;
+       int status;
+
+       if (!config.enable)
+               return FALSE;
+
+       debug_print("Filtering message %d\n", msginfo->msgnum);
+
+       if ((fp = procmsg_open_message(msginfo)) == NULL) {
+               debug_print("failed to open message file\n");
+               return FALSE;
+       }
+
+       pid = fork();
+       if (pid == 0) {
+               _exit(msg_is_spam(fp) ? 1 : 0);
+       } else {
+               gint running = 0;
+
+               running |= CHILD_RUNNING;
+
+               g_timeout_add(1000, timeout_func, &running);
+               running |= TIMEOUT_RUNNING;
+
+               while(running & CHILD_RUNNING) {
+                       waitpid(pid, &status, WNOHANG);
+                       if (WIFEXITED(status)) {
+                               running &= ~CHILD_RUNNING;
+                       }
+           
+                       g_main_iteration(TRUE);
+               }
+
+               while (running & TIMEOUT_RUNNING)
+                       g_main_iteration(TRUE);
+       }
+        is_spam = WEXITSTATUS(status) == 1 ? TRUE : FALSE;
+
        fclose(fp);
 
        if (is_spam) {
        fclose(fp);
 
        if (is_spam) {