2005-07-20 [colin] 1.9.12cvs87
[claws.git] / src / plugins / spamassassin / spamassassin.c
index 2284a6ea1e93908eb40dbc2e27e95bef5e86a9da..13e484fd96e9ad07df6cbe99ed3ebd713d58ade0 100644 (file)
@@ -27,6 +27,7 @@
 #include <sys/wait.h>
 
 #include <glib.h>
+#include <glib/gi18n.h>
 
 #if HAVE_LOCALE_H
 #  include <locale.h>
@@ -41,7 +42,6 @@
 #include "folder.h"
 #include "prefs.h"
 #include "prefs_gtk.h"
-#include "intl.h"
 
 #include "libspamc.h"
 #include "spamassassin.h"
@@ -76,6 +76,7 @@ enum {
 static guint hook_id;
 static int flags = SPAMC_RAW_MODE | SPAMC_SAFE_FALLBACK | SPAMC_CHECK_ONLY;
 static gchar *username = NULL;
+static MessageCallback message_callback;
 
 static SpamAssassinConfig config;
 
@@ -178,6 +179,8 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data)
                return FALSE;
 
        debug_print("Filtering message %d\n", msginfo->msgnum);
+       if (message_callback != NULL)
+               message_callback(_("SpamAssassin: filtering message..."));
 
        if ((fp = procmsg_open_message(msginfo)) == NULL) {
                debug_print("failed to open message file\n");
@@ -192,14 +195,21 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data)
 
                running |= CHILD_RUNNING;
 
-               g_timeout_add(1000, timeout_func, &running);
+               g_timeout_add(50, timeout_func, &running);
                running |= TIMEOUT_RUNNING;
 
                while(running & CHILD_RUNNING) {
-                       waitpid(pid, &status, WNOHANG);
-                       if (WIFEXITED(status)) {
+                       int ret;
+
+                       ret = waitpid(pid, &status, WNOHANG);
+                       if (ret == pid) {
+                               if (WIFEXITED(status)) {
+                                       running &= ~CHILD_RUNNING;
+                                       is_spam = WEXITSTATUS(status) == 1 ? TRUE : FALSE;
+                               }
+                       } if (ret < 0) {
                                running &= ~CHILD_RUNNING;
-                       }
+                       } /* ret == 0 continue */
            
                        g_main_iteration(TRUE);
                }
@@ -207,7 +217,6 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data)
                while (running & TIMEOUT_RUNNING)
                        g_main_iteration(TRUE);
        }
-        is_spam = WEXITSTATUS(status) == 1 ? TRUE : FALSE;
 
        fclose(fp);
 
@@ -262,8 +271,15 @@ void spamassassin_save_config(void)
        prefs_file_close(pfile);
 }
 
+void spamassassin_set_message_callback(MessageCallback callback)
+{
+       message_callback = callback;
+}
+
 gint plugin_init(gchar **error)
 {
+       gchar *rcpath;
+
        if ((sylpheed_get_version() > VERSION_NUMERIC)) {
                *error = g_strdup("Your sylpheed version is newer than the version the plugin was built with");
                return -1;
@@ -282,12 +298,15 @@ gint plugin_init(gchar **error)
 
        username = g_get_user_name();
        if (username == NULL) {
+               hooks_unregister_hook(MAIL_FILTERING_HOOKLIST, hook_id);
                *error = g_strdup("Failed to get username");
                return -1;
        }
 
        prefs_set_default(param);
-       prefs_read_config(param, "SpamAssassin", COMMON_RC);
+       rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
+       prefs_read_config(param, "SpamAssassin", rcpath, NULL);
+       g_free(rcpath);
 
        debug_print("Spamassassin plugin loaded\n");