commit 281365d012b2e012fb7fd64fd2bf122c797d3a0b
parent 8d5cf03effe55baaa6bfded773cb9d7c2c84827f
Author: Colin Leroy <colin@colino.net>
Date: Tue, 25 Mar 2008 07:40:03 +0000
2008-03-25 [colin] 3.3.1cvs38
* src/plugins/bogofilter/bogofilter.c
* src/plugins/bogofilter/bogofilter.h
* src/plugins/bogofilter/bogofilter_gtk.c
Add a "learn from whitelist" preference
Whitelist Unsure mails too.
Diffstat:
6 files changed, 58 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,11 @@
+2008-03-25 [colin] 3.3.1cvs38
+
+ * src/plugins/bogofilter/bogofilter.c
+ * src/plugins/bogofilter/bogofilter.h
+ * src/plugins/bogofilter/bogofilter_gtk.c
+ Add a "learn from whitelist" preference
+ Whitelist Unsure mails too.
+
2008-03-24 [paul] 3.3.1cvs37
* src/prefs_account.c
diff --git a/PATCHSETS b/PATCHSETS
@@ -3272,3 +3272,4 @@
( cvs diff -u -r 1.1.2.45 -r 1.1.2.46 manual/advanced.xml; ) > 3.3.1cvs35.patchset
( cvs diff -u -r 1.49.2.107 -r 1.49.2.108 src/procmime.c; ) > 3.3.1cvs36.patchset
( cvs diff -u -r 1.105.2.128 -r 1.105.2.129 src/prefs_account.c; ) > 3.3.1cvs37.patchset
+( cvs diff -u -r 1.1.2.36 -r 1.1.2.37 src/plugins/bogofilter/bogofilter.c; cvs diff -u -r 1.1.2.13 -r 1.1.2.14 src/plugins/bogofilter/bogofilter.h; cvs diff -u -r 1.1.2.30 -r 1.1.2.31 src/plugins/bogofilter/bogofilter_gtk.c; ) > 3.3.1cvs38.patchset
diff --git a/configure.ac b/configure.ac
@@ -11,7 +11,7 @@ MINOR_VERSION=3
MICRO_VERSION=1
INTERFACE_AGE=0
BINARY_AGE=0
-EXTRA_VERSION=37
+EXTRA_VERSION=38
EXTRA_RELEASE=
EXTRA_GTK2_VERSION=
diff --git a/src/plugins/bogofilter/bogofilter.c b/src/plugins/bogofilter/bogofilter.c
@@ -102,6 +102,8 @@ static PrefParam param[] = {
NULL, NULL, NULL},
{"whitelist_ab_folder", N_("Any"), &config.whitelist_ab_folder, P_STRING,
NULL, NULL, NULL},
+ {"learn_from_whitelist", "FALSE", &config.learn_from_whitelist, P_BOOL,
+ NULL, NULL, NULL},
{"mark_as_read", "TRUE", &config.mark_as_read, P_BOOL,
NULL, NULL, NULL},
@@ -316,9 +318,11 @@ static void bogofilter_do_filter(BogoFilterData *data)
data->mail_filtering_data->filtered, msginfo);
data->new_spams = g_slist_prepend(data->new_spams, msginfo);
- } else if (whitelisted && parts && parts[0] && parts[1] && *parts[1] == 'S') {
+ } else if (whitelisted && parts && parts[0] && parts[1] &&
+ (*parts[1] == 'S' || *parts[1] == 'U')) {
- debug_print("message %d is whitelisted spam\n", msginfo->msgnum);
+ debug_print("message %d is whitelisted %s\n", msginfo->msgnum,
+ *parts[1] == 'S' ? "spam":"unsure");
/* Whitelisted spam will *not* be filtered away, but continue
* their trip through filtering as if it was ham. */
data->mail_filtering_data->unfiltered = g_slist_prepend(
@@ -366,7 +370,7 @@ static void bogofilter_do_filter(BogoFilterData *data)
else
status = WEXITSTATUS(status);
}
-
+
to_filter_data->status = status;
}
@@ -542,17 +546,38 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data)
for (cur = new_hams; cur; cur = cur->next) {
MsgInfo *msginfo = (MsgInfo *)cur->data;
procmsg_msginfo_unset_flags(msginfo, MSG_SPAM, 0);
+ debug_print("unflagging ham: %d\n", msginfo->msgnum);
}
/* unflag unsure */
for (cur = new_unsure; cur; cur = cur->next) {
MsgInfo *msginfo = (MsgInfo *)cur->data;
procmsg_msginfo_unset_flags(msginfo, MSG_SPAM, 0);
+ debug_print("unflagging unsure: %d\n", msginfo->msgnum);
}
- /* flag whitelisted spams */
- for (cur = whitelisted_new_spams; cur; cur = cur->next) {
- MsgInfo *msginfo = (MsgInfo *)cur->data;
- procmsg_msginfo_set_flags(msginfo, MSG_SPAM, 0);
+ if (config.learn_from_whitelist && whitelisted_new_spams) {
+ /* flag whitelisted spams */
+ for (cur = whitelisted_new_spams; cur; cur = cur->next) {
+ MsgInfo *msginfo = (MsgInfo *)cur->data;
+ procmsg_msginfo_set_flags(msginfo, MSG_SPAM, 0);
+ debug_print("flagging whitelisted non-ham: %d\n", msginfo->msgnum);
+ }
+ /* correct bogo */
+ bogofilter_learn(NULL, whitelisted_new_spams, FALSE);
+
+ /* unflag them */
+ for (cur = whitelisted_new_spams; cur; cur = cur->next) {
+ MsgInfo *msginfo = (MsgInfo *)cur->data;
+ procmsg_msginfo_unset_flags(msginfo, MSG_SPAM, 0);
+ debug_print("unflagging whitelisted non-ham: %d\n", msginfo->msgnum);
+ }
+ } else {
+ for (cur = whitelisted_new_spams; cur; cur = cur->next) {
+ MsgInfo *msginfo = (MsgInfo *)cur->data;
+ procmsg_msginfo_unset_flags(msginfo, MSG_SPAM, 0);
+ debug_print("not flagging whitelisted non-ham: %d\n", msginfo->msgnum);
+ }
}
+
/* flag spams and delete them if !config.receive_spam
* (if config.receive_spam is set, we'll move them later) */
for (cur = new_spams; cur; cur = cur->next) {
diff --git a/src/plugins/bogofilter/bogofilter.h b/src/plugins/bogofilter/bogofilter.h
@@ -38,6 +38,7 @@ struct _BogofilterConfig
gboolean insert_header;
gboolean whitelist_ab;
gchar *whitelist_ab_folder;
+ gboolean learn_from_whitelist;
gboolean save_unsure;
gchar *save_unsure_folder;
gboolean mark_as_read;
diff --git a/src/plugins/bogofilter/bogofilter_gtk.c b/src/plugins/bogofilter/bogofilter_gtk.c
@@ -59,6 +59,7 @@ struct BogofilterPage
GtkWidget *bogopath;
GtkWidget *whitelist_ab;
GtkWidget *whitelist_ab_folder_combo;
+ GtkWidget *learn_from_whitelist_chkbtn;
GtkWidget *mark_as_read;
};
@@ -121,6 +122,7 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
GtkWidget *insert_header_checkbtn;
GtkWidget *whitelist_ab_checkbtn;
+ GtkWidget *learn_from_whitelist_chkbtn;
GtkWidget *bogopath_label;
GtkWidget *bogopath_entry;
@@ -242,6 +244,13 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
_("Click this button to select a book or folder in the address book"),
NULL);
+ learn_from_whitelist_chkbtn = gtk_check_button_new_with_label(_("Learn whitelisted emails as ham"));
+ gtk_tooltips_set_tip(tooltips, learn_from_whitelist_chkbtn,
+ _("If Bogofilter thought an email was spam or unsure, but it was whitelisted, "
+ "learn it as ham."), NULL);
+ gtk_widget_show(learn_from_whitelist_chkbtn);
+ gtk_box_pack_start (GTK_BOX (vbox2), learn_from_whitelist_chkbtn, TRUE, TRUE, 0);
+
hbox_bogopath = gtk_hbox_new(FALSE, 8);
gtk_widget_show(hbox_bogopath);
gtk_box_pack_start (GTK_BOX (vbox2), hbox_bogopath, FALSE, FALSE, 0);
@@ -271,6 +280,7 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
SET_TOGGLE_SENSITIVITY(save_unsure_checkbtn, save_unsure_folder_select);
SET_TOGGLE_SENSITIVITY(whitelist_ab_checkbtn, whitelist_ab_folder_combo);
SET_TOGGLE_SENSITIVITY(whitelist_ab_checkbtn, whitelist_ab_select_btn);
+ SET_TOGGLE_SENSITIVITY(whitelist_ab_checkbtn, learn_from_whitelist_chkbtn);
SET_TOGGLE_SENSITIVITY(save_spam_checkbtn, mark_as_read_checkbtn);
config = bogofilter_get_config();
@@ -288,6 +298,7 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(save_unsure_checkbtn), config->save_unsure);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(insert_header_checkbtn), config->insert_header);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(whitelist_ab_checkbtn), config->whitelist_ab);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(learn_from_whitelist_chkbtn), config->learn_from_whitelist);
if (config->whitelist_ab_folder != NULL)
gtk_entry_set_text(GTK_ENTRY(GTK_BIN(whitelist_ab_folder_combo)->child),
config->whitelist_ab_folder);
@@ -313,6 +324,7 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
page->insert_header = insert_header_checkbtn;
page->whitelist_ab = whitelist_ab_checkbtn;
page->whitelist_ab_folder_combo = whitelist_ab_folder_combo;
+ page->learn_from_whitelist_chkbtn = learn_from_whitelist_chkbtn;
page->bogopath = bogopath_entry;
page->mark_as_read = mark_as_read_checkbtn;
@@ -360,6 +372,9 @@ static void bogofilter_save_func(PrefsPage *_page)
config->whitelist_ab_folder = gtk_editable_get_chars(
GTK_EDITABLE(GTK_BIN(page->whitelist_ab_folder_combo)->child), 0, -1);
+ /* learn_from_whitelist_chkbtn */
+ config->learn_from_whitelist = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->learn_from_whitelist_chkbtn));
+
/* bogopath */
g_free(config->bogopath);
config->bogopath = gtk_editable_get_chars(GTK_EDITABLE(page->bogopath), 0, -1);