2006-08-27 [colin] 2.4.0cvs100
authorColin Leroy <colin@colino.net>
Sun, 27 Aug 2006 14:19:22 +0000 (14:19 +0000)
committerColin Leroy <colin@colino.net>
Sun, 27 Aug 2006 14:19:22 +0000 (14:19 +0000)
* src/folder.c
Don't use F_UNKNOWN folders for any default
outbox/trash/etc
* src/plugins/bogofilter/bogofilter.c
* src/plugins/bogofilter/bogofilter.h
* src/plugins/bogofilter/bogofilter_gtk.c
Add an option to specify the path to bogofilter
Use single-quotes to be able to learn in folders
with spaces in their names
Verify learning status

ChangeLog
PATCHSETS
configure.ac
src/folder.c
src/plugins/bogofilter/bogofilter.c
src/plugins/bogofilter/bogofilter.h
src/plugins/bogofilter/bogofilter_gtk.c

index 8ca4386..edf6081 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2006-08-27 [colin]     2.4.0cvs100
+
+       * src/folder.c
+               Don't use F_UNKNOWN folders for any default
+               outbox/trash/etc
+       * src/plugins/bogofilter/bogofilter.c
+       * src/plugins/bogofilter/bogofilter.h
+       * src/plugins/bogofilter/bogofilter_gtk.c
+               Add an option to specify the path to bogofilter
+               Use single-quotes to be able to learn in folders
+               with spaces in their names
+               Verify learning status
+
 2006-08-27 [colin]     2.4.0cvs99
 
        * manual/faq.xml
index ec571c2..86d4516 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.16.2.37 -r 1.16.2.38 src/msgcache.c;  cvs diff -u -r 1.395.2.235 -r 1.395.2.236 src/summaryview.c;  cvs diff -u -r 1.13.2.19 -r 1.13.2.20 src/common/plugin.c;  cvs diff -u -r 1.5.2.6 -r 1.5.2.7 src/common/plugin.h;  cvs diff -u -r 1.1.2.4 -r 1.1.2.5 src/common/timing.h;  cvs diff -u -r 1.13.2.22 -r 1.13.2.23 src/plugins/clamav/clamav_plugin.c;  cvs diff -u -r 1.13.2.7 -r 1.13.2.8 src/plugins/demo/demo.c;  cvs diff -u -r 1.12.2.13 -r 1.12.2.14 src/plugins/dillo_viewer/dillo_viewer.c;  cvs diff -u -r 1.1.2.9 -r 1.1.2.10 src/plugins/pgpcore/plugin.c;  cvs diff -u -r 1.1.2.16 -r 1.1.2.17 src/plugins/pgpinline/pgpinline.c;  cvs diff -u -r 1.1.2.37 -r 1.1.2.38 src/plugins/pgpmime/pgpmime.c;  cvs diff -u -r 1.18.2.36 -r 1.18.2.37 src/plugins/spamassassin/spamassassin.c;  cvs diff -u -r 1.14.2.36 -r 1.14.2.37 src/plugins/trayicon/trayicon.c;  ) > 2.4.0cvs97.patchset
 ( cvs diff -u -r 1.382.2.304 -r 1.382.2.305 src/compose.c;  cvs diff -u -r 1.94.2.99 -r 1.94.2.100 src/messageview.c;  cvs diff -u -r 1.150.2.75 -r 1.150.2.76 src/procmsg.c;  cvs diff -u -r 1.60.2.33 -r 1.60.2.34 src/procmsg.h;  ) > 2.4.0cvs98.patchset
 ( cvs diff -u -r 1.1.2.10 -r 1.1.2.11 manual/faq.xml;  cvs diff -u -r 1.1.2.14 -r 1.1.2.15 manual/plugins.xml;  ) > 2.4.0cvs99.patchset
+( cvs diff -u -r 1.213.2.109 -r 1.213.2.110 src/folder.c;  cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/plugins/bogofilter/bogofilter.c;  cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/plugins/bogofilter/bogofilter.h;  cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/plugins/bogofilter/bogofilter_gtk.c;  ) > 2.4.0cvs100.patchset
index 3783a25..f383863 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=4
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=99
+EXTRA_VERSION=100
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index b26b123..a55dcac 100644 (file)
@@ -1366,6 +1366,8 @@ FolderItem *folder_get_default_outbox(void)
                        continue;
                if (folder->outbox == NULL)
                        continue;
+               if (folder->klass->type == F_UNKNOWN)
+                       continue;
 
                return folder->outbox;
        }
@@ -1384,6 +1386,8 @@ FolderItem *folder_get_default_draft(void)
                        continue;
                if (folder->draft == NULL)
                        continue;
+               if (folder->klass->type == F_UNKNOWN)
+                       continue;
 
                return folder->draft;
        }
@@ -1402,6 +1406,8 @@ FolderItem *folder_get_default_queue(void)
                        continue;
                if (folder->queue == NULL)
                        continue;
+               if (folder->klass->type == F_UNKNOWN)
+                       continue;
 
                return folder->queue;
        }
@@ -1420,6 +1426,8 @@ FolderItem *folder_get_default_trash(void)
                        continue;
                if (folder->trash == NULL)
                        continue;
+               if (folder->klass->type == F_UNKNOWN)
+                       continue;
 
                return folder->trash;
        }
index 5f8eff2..05fc698 100644 (file)
@@ -90,6 +90,8 @@ static PrefParam param[] = {
         NULL, NULL, NULL},
        {"max_size", "250", &config.max_size, P_INT,
         NULL, NULL, NULL},
+       {"bogopath", "bogofilter", &config.bogopath, P_STRING,
+        NULL, NULL, NULL},
 
        {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
@@ -102,6 +104,7 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data)
        static gboolean warned_error = FALSE;
        gchar *file = NULL, *cmd = NULL;
        int status = 3;
+       gchar *bogo_exec = (config.bogopath && *config.bogopath) ? config.bogopath:"bogofilter";
 
        if (!config.process_emails) {
                return FALSE;
@@ -113,7 +116,7 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data)
        file = procmsg_get_message_file(msginfo);
 
        if (file)
-               cmd = g_strdup_printf("bogofilter -I %s", file);
+               cmd = g_strdup_printf("%s -I %s", bogo_exec, file);
        
        if (cmd)
                status = system(cmd);
@@ -125,7 +128,7 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data)
 
        g_free(cmd);
        g_free(file);
-       printf("bogofilter status %d\n", status);
+       debug_print("bogofilter status %d\n", status);
        is_spam = (status == 0);
        
        if (is_spam) {
@@ -176,7 +179,8 @@ int bogofilter_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam)
 {
        gchar *cmd = NULL;
        gchar *file = NULL;
-
+       const gchar *bogo_exec = (config.bogopath && *config.bogopath) ? config.bogopath:"bogofilter";
+       gint status = 0;
        if (msginfo == NULL && msglist == NULL) {
                return -1;
        }
@@ -188,9 +192,18 @@ int bogofilter_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam)
                } else {
                        if (message_callback != NULL)
                                message_callback(_("Bogofilter: learning from message..."), 0, 0);
-                       cmd = g_strdup_printf("bogofilter -%c -I %s",
-                                                       spam ? 's':'n', file);
-                       execute_command_line(cmd, FALSE);
+                       if (spam)
+                               /* learn as spam */
+                               cmd = g_strdup_printf("%s -s -I '%s'", bogo_exec, file);
+                       else if (MSG_IS_SPAM(msginfo->flags))
+                               /* correct bogofilter, this wasn't spam */
+                               cmd = g_strdup_printf("%s -Sn -I '%s'", bogo_exec, file);
+                       else 
+                               /* learn as ham */
+                               cmd = g_strdup_printf("%s -n -I '%s'", bogo_exec, file);
+                       if ((status = execute_command_line(cmd, FALSE)) != 0)
+                               alertpanel_error(_("Learning failed; `%s` returned with status %d."),
+                                               cmd, status);
                        g_free(cmd);
                        g_free(file);
                        if (message_callback != NULL)
@@ -206,13 +219,24 @@ int bogofilter_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam)
                if (message_callback != NULL)
                        message_callback(_("Bogofilter: learning from messages..."), total, 0);
                
-               for (; cur; cur = cur->next) {
+               for (; cur && status == 0; cur = cur->next) {
                        info = (MsgInfo *)cur->data;
                        file = procmsg_get_message_file(info);
 
-                       cmd = g_strdup_printf("bogofilter -%c -I %s",
-                                                       spam ? 's':'n', file);
-                       execute_command_line(cmd, FALSE);
+                       if (spam)
+                               /* learn as spam */
+                               cmd = g_strdup_printf("%s -s -I '%s'", bogo_exec, file);
+                       else if (MSG_IS_SPAM(info->flags))
+                               /* correct bogofilter, this wasn't spam */
+                               cmd = g_strdup_printf("%s -Sn -I '%s'", bogo_exec, file);
+                       else 
+                               /* learn as ham */
+                               cmd = g_strdup_printf("%s -n -I '%s'", bogo_exec, file);
+       
+                       if ((status = execute_command_line(cmd, FALSE)) != 0)
+                               alertpanel_error(_("Learning failed; `%s` returned with status %d."),
+                                               cmd, status);
+
                        g_free(cmd);
                        g_free(file);
                        done++;
index 588b337..581b780 100644 (file)
@@ -32,6 +32,7 @@ struct _BogofilterConfig
        gboolean                 receive_spam;
        gchar                   *save_folder;
        guint                    max_size;
+       gchar                   *bogopath;
 };
 
 BogofilterConfig *bogofilter_get_config              (void);
index e7b05c2..b62e5f7 100644 (file)
@@ -50,6 +50,7 @@ struct BogofilterPage
        GtkWidget *save_folder;
        GtkWidget *save_folder_select;
        GtkWidget *max_size;
+       GtkWidget *bogopath;
 };
 
 static void foldersel_cb(GtkWidget *widget, gpointer data)
@@ -76,7 +77,7 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
 
        GtkWidget *vbox1, *vbox2;
        GtkWidget *hbox_max_size;
-       GtkWidget *hbox_process_emails, *hbox_save_spam;
+       GtkWidget *hbox_process_emails, *hbox_save_spam, *hbox_bogopath;
 
        GtkWidget *max_size_label;
        GtkObject *max_size_spinbtn_adj;
@@ -89,6 +90,9 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
        GtkWidget *save_spam_folder_entry;
        GtkWidget *save_spam_folder_select;
 
+       GtkWidget *bogopath_label;
+       GtkWidget *bogopath_entry;
+
        GtkTooltips *tooltips;
 
        tooltips = gtk_tooltips_new();
@@ -152,6 +156,19 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
                        _("Click this button to select a folder for storing spam"),
                        NULL);
 
+       hbox_bogopath = gtk_hbox_new(FALSE, 8);
+       gtk_widget_show(hbox_bogopath);
+       gtk_box_pack_start (GTK_BOX (vbox2), hbox_bogopath, FALSE, FALSE, 0);
+
+       bogopath_label = gtk_label_new(
+                       _("Bogofilter call: "));
+       gtk_widget_show(bogopath_label);
+       gtk_box_pack_start(GTK_BOX(hbox_bogopath), bogopath_label, FALSE, FALSE, 0);
+
+       bogopath_entry = gtk_entry_new();
+       gtk_widget_show(bogopath_entry);
+       gtk_box_pack_start(GTK_BOX(hbox_bogopath), bogopath_entry, FALSE, FALSE, 0);
+
        SET_TOGGLE_SENSITIVITY(save_spam_checkbtn, save_spam_folder_entry);
        SET_TOGGLE_SENSITIVITY(save_spam_checkbtn, save_spam_folder_select);
 
@@ -165,12 +182,15 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(save_spam_checkbtn), config->receive_spam);
        if (config->save_folder != NULL)
                gtk_entry_set_text(GTK_ENTRY(save_spam_folder_entry), config->save_folder);
+       if (config->bogopath != NULL)
+               gtk_entry_set_text(GTK_ENTRY(bogopath_entry), config->bogopath);
 
        page->max_size = max_size_spinbtn;
        page->process_emails = process_emails_checkbtn;
        page->receive_spam = save_spam_checkbtn;
        page->save_folder = save_spam_folder_entry;
        page->save_folder_select = save_spam_folder_select;
+       page->bogopath = bogopath_entry;
 
        page->page.widget = vbox1;
 }
@@ -199,6 +219,10 @@ static void bogofilter_save_func(PrefsPage *_page)
        g_free(config->save_folder);
        config->save_folder = gtk_editable_get_chars(GTK_EDITABLE(page->save_folder), 0, -1);
 
+       /* bogopath */
+       g_free(config->bogopath);
+       config->bogopath = gtk_editable_get_chars(GTK_EDITABLE(page->bogopath), 0, -1);
+
        /* max_size */
        config->max_size = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->max_size));