RSSyl: Allow use of .netrc by libcurl. Bug/enhancement #3309, by Vincent Pelletier
[claws.git] / src / plugins / bogofilter / bogofilter.c
index e659d51f4418547ccbb7facfb42b419feb2db8af..d5e6076d0067291db4cd53446c84cc9fad8e78d6 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Colin Leroy <colin@colino.net> and 
+ * Copyright (C) 1999-2012 Colin Leroy <colin@colino.net> and 
  * the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
@@ -20,6 +20,7 @@
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
+#include "claws-features.h"
 #endif
 
 #include "defs.h"
@@ -73,6 +74,9 @@
 #ifdef HAVE_PWD_H
 #include <pwd.h>
 #endif
+#ifdef USE_PTHREAD
+#include <pthread.h>
+#endif
 
 #define PLUGIN_NAME (_("Bogofilter"))
 
@@ -194,7 +198,7 @@ static void bogofilter_do_filter(BogoFilterData *data)
        int status = 0;
        MsgInfo *msginfo;
        GSList *cur = NULL;
-       int total = 0, curnum = 0;
+       int total = 0, curnum = 1;
        gchar *file = NULL;
        gchar buf[BUFSIZ];
 
@@ -216,7 +220,7 @@ static void bogofilter_do_filter(BogoFilterData *data)
                        gchar *ab_folderpath;
 
                        if (*config.whitelist_ab_folder == '\0' ||
-                               strcasecmp(config.whitelist_ab_folder, _("Any")) == 0) {
+                               strcasecmp(config.whitelist_ab_folder, "Any") == 0) {
                                /* match the whole addressbook */
                                ab_folderpath = NULL;
                        } else {
@@ -259,6 +263,8 @@ static void bogofilter_do_filter(BogoFilterData *data)
                                        data->new_hams = g_slist_prepend(data->new_hams, msginfo);
                                } else {
                                        gchar **parts = NULL;
+
+                                       buf[sizeof(buf) - 1] = '\0';
                                        if (strchr(buf, '/')) {
                                                tmp = strrchr(buf, '/')+1;
                                        } else {
@@ -272,21 +278,21 @@ static void bogofilter_do_filter(BogoFilterData *data)
                                            FOLDER_TYPE(msginfo->folder->folder) == F_MH &&
                                            config.insert_header) {
                                                gchar *tmpfile = get_tmp_file();
-                                               FILE *input = fopen(file, "r");
-                                               FILE *output = fopen(tmpfile, "w");
+                                               FILE *input = g_fopen(file, "r");
+                                               FILE *output = g_fopen(tmpfile, "w");
                                                if (strstr(parts[2], "\n"))
                                                        *(strstr(parts[2], "\n")) = '\0';
                                                if (input && !output) 
                                                        fclose (input);
                                                else if (!input && output)
                                                        fclose (output);
-                                               else {
+                                               else if (input && output) {
                                                        gchar tmpbuf[BUFFSIZE];
                                                        gboolean err = FALSE;
                                                        const gchar *bogosity = *parts[1] == 'S' ? "Spam":
                                                                                 (*parts[1] == 'H' ? "Ham":"Unsure");
                                                        gchar *tmpstr = g_strdup_printf(
-                                                                       "X-Claws-Bogosity: %s, spamicity=%s%s\n",
+                                                                       "X-Bogosity: %s, spamicity=%s%s\n",
                                                                        bogosity, parts[2],
                                                                        whitelisted?" [whitelisted]":"");
                                                        if (fwrite(tmpstr, 1, strlen(tmpstr), output) < strlen(tmpstr)) {
@@ -738,6 +744,7 @@ int bogofilter_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam)
        gchar *file = NULL;
        const gchar *bogo_exec = (config.bogopath && *config.bogopath) ? config.bogopath:"bogofilter";
        gint status = 0;
+
        if (msginfo == NULL && msglist == NULL) {
                return -1;
        }
@@ -767,10 +774,8 @@ int bogofilter_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam)
                        g_free(file);
                        if (message_callback != NULL)
                                message_callback(NULL, 0, 0, FALSE);
-                       return 0;
                }
-       }
-       if (msglist) {
+       } else if (msglist) {
                GSList *cur = msglist;
                MsgInfo *info;
                int total = g_slist_length(msglist);
@@ -877,9 +882,8 @@ int bogofilter_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam)
 
                if (message_callback != NULL)
                        message_callback(NULL, 0, 0, FALSE);
-               return 0;
        }
-       return -1;
+       return 0;
 }
 
 void bogofilter_save_config(void)