From 9aca81db38a653f05129b7fd55d8ad24fa0825a0 Mon Sep 17 00:00:00 2001 From: Colin Leroy Date: Thu, 9 Nov 2006 21:59:44 +0000 Subject: [PATCH] 2006-11-09 [colin] 2.6.0cvs23 * src/plugins/bogofilter/bogofilter.c * src/plugins/bogofilter/bogofilter_gtk.c Prepare things needed to thread bogofilter filtering: separate bogo stuff and possible GUI stuff. --- ChangeLog | 8 ++++++ PATCHSETS | 1 + configure.ac | 2 +- src/plugins/bogofilter/bogofilter.c | 38 ++++++++++++++++++------- src/plugins/bogofilter/bogofilter_gtk.c | 35 ++++++++++++++++++----- 5 files changed, 65 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 540f480fd..c33989bd0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-11-09 [colin] 2.6.0cvs23 + + * src/plugins/bogofilter/bogofilter.c + * src/plugins/bogofilter/bogofilter_gtk.c + Prepare things needed to thread bogofilter + filtering: separate bogo stuff and possible GUI + stuff. + 2006-11-09 [colin] 2.6.0cvs22 * src/account.c diff --git a/PATCHSETS b/PATCHSETS index 8a925ab1f..eae543b47 100644 --- a/PATCHSETS +++ b/PATCHSETS @@ -2047,3 +2047,4 @@ ( cvs diff -u -r 1.1.2.28 -r 1.1.2.29 src/gtk/authors.h; ) > 2.6.0cvs20.patchset ( cvs diff -u -r 1.382.2.324 -r 1.382.2.325 src/compose.c; cvs diff -u -r 1.204.2.108 -r 1.204.2.109 src/prefs_common.c; cvs diff -u -r 1.103.2.66 -r 1.103.2.67 src/prefs_common.h; cvs diff -u -r 1.1.2.11 -r 1.1.2.12 src/prefs_compose_writing.c; ) > 2.6.0cvs21.patchset ( cvs diff -u -r 1.61.2.54 -r 1.61.2.55 src/account.c; cvs diff -u -r 1.382.2.325 -r 1.382.2.326 src/compose.c; cvs diff -u -r 1.207.2.131 -r 1.207.2.132 src/folderview.c; cvs diff -u -r 1.274.2.154 -r 1.274.2.155 src/mainwindow.c; cvs diff -u -r 1.39.2.26 -r 1.39.2.27 src/mainwindow.h; cvs diff -u -r 1.14.2.41 -r 1.14.2.42 src/plugins/trayicon/trayicon.c; ) > 2.6.0cvs22.patchset +( cvs diff -u -r 1.1.2.11 -r 1.1.2.12 src/plugins/bogofilter/bogofilter.c; cvs diff -u -r 1.1.2.4 -r 1.1.2.5 src/plugins/bogofilter/bogofilter_gtk.c; ) > 2.6.0cvs23.patchset diff --git a/configure.ac b/configure.ac index e430802e2..db01b830a 100644 --- a/configure.ac +++ b/configure.ac @@ -11,7 +11,7 @@ MINOR_VERSION=6 MICRO_VERSION=0 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=22 +EXTRA_VERSION=23 EXTRA_RELEASE= EXTRA_GTK2_VERSION= diff --git a/src/plugins/bogofilter/bogofilter.c b/src/plugins/bogofilter/bogofilter.c index 0b7bdb9f8..c6a95c481 100644 --- a/src/plugins/bogofilter/bogofilter.c +++ b/src/plugins/bogofilter/bogofilter.c @@ -132,7 +132,7 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data) int status = 0; gchar *bogo_exec = (config.bogopath && *config.bogopath) ? config.bogopath:"bogofilter"; int total = 0, curnum = 0; - GSList *spams = NULL; + GSList *spams = NULL, *new_hams = NULL, *new_spams = NULL; gchar buf[BUFSIZ]; gchar *bogo_args[4]; @@ -154,6 +154,7 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data) if (message_callback != NULL) message_callback(_("Bogofilter: filtering messages..."), total, 0); + /* determine spam status - should be threaded */ bogo_args[0] = bogo_exec; bogo_args[1] = "-T"; bogo_args[2] = "-b"; @@ -177,6 +178,8 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data) if (message_callback != NULL) message_callback(NULL, total, curnum++); + /* can set flags (SCANNED, ATTACHMENT) but that's ok + * as GUI updates are hooked not direct */ file = procmsg_get_message_file(msginfo); if (file) { @@ -187,9 +190,9 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data) if (read(bogo_stdout, buf, sizeof(buf)-1) < 0) { g_warning("bogofilter short read\n"); debug_print("message %d is ham\n", msginfo->msgnum); - procmsg_msginfo_unset_flags(msginfo, MSG_SPAM, 0); mail_filtering_data->unfiltered = g_slist_prepend( mail_filtering_data->unfiltered, msginfo); + new_hams = g_slist_prepend(new_hams, msginfo); } else { gchar **parts = NULL; if (strchr(buf, '/')) { @@ -201,31 +204,26 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data) debug_print("read %s\n", buf); if (parts && parts[0] && parts[1] && *parts[1] == 'S') { debug_print("message %d is spam\n", msginfo->msgnum); - procmsg_msginfo_set_flags(msginfo, MSG_SPAM, 0); - if (config.receive_spam) { - procmsg_msginfo_unset_flags(msginfo, ~0, 0); - procmsg_msginfo_set_flags(msginfo, MSG_SPAM, 0); spams = g_slist_prepend(spams, msginfo); - } else { - folder_item_remove_msg(msginfo->folder, msginfo->msgnum); - } + } mail_filtering_data->filtered = g_slist_prepend( mail_filtering_data->filtered, msginfo); + new_spams = g_slist_prepend(new_spams, msginfo); } else { debug_print("message %d is ham\n", msginfo->msgnum); - procmsg_msginfo_unset_flags(msginfo, MSG_SPAM, 0); mail_filtering_data->unfiltered = g_slist_prepend( mail_filtering_data->unfiltered, msginfo); + new_hams = g_slist_prepend(new_hams, msginfo); } g_strfreev(parts); } g_free(file); } else { - procmsg_msginfo_unset_flags(msginfo, MSG_SPAM, 0); mail_filtering_data->unfiltered = g_slist_prepend( mail_filtering_data->unfiltered, msginfo); + new_hams = g_slist_prepend(new_hams, msginfo); } } } @@ -239,7 +237,25 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data) else status = WEXITSTATUS(status); } + /* end of thread */ + /* flag hams */ + for (cur = new_hams; cur; cur = cur->next) { + MsgInfo *msginfo = (MsgInfo *)cur->data; + procmsg_msginfo_unset_flags(msginfo, MSG_SPAM, 0); + } + g_slist_free(new_hams); + /* flag spams */ + for (cur = new_spams; cur; cur = cur->next) { + MsgInfo *msginfo = (MsgInfo *)cur->data; + if (config.receive_spam) { + procmsg_msginfo_change_flags(msginfo, MSG_SPAM, 0, ~0, 0); + } else { + folder_item_remove_msg(msginfo->folder, msginfo->msgnum); + } + } + g_slist_free(new_spams); + if (status < 0 || status > 2) { /* I/O or other errors */ gchar *msg = NULL; diff --git a/src/plugins/bogofilter/bogofilter_gtk.c b/src/plugins/bogofilter/bogofilter_gtk.c index 30eda9f97..4a582619e 100644 --- a/src/plugins/bogofilter/bogofilter_gtk.c +++ b/src/plugins/bogofilter/bogofilter_gtk.c @@ -240,18 +240,39 @@ static void bogofilter_save_func(PrefsPage *_page) bogofilter_save_config(); } -static void gtk_message_callback(gchar *message, gint total, gint done) +typedef struct _BogoCbData { + gchar *message; + gint total; + gint done; +} BogoCbData; + +static gboolean gtk_message_callback(gpointer data) { - if (message) - statusbar_print_all(message); - else if (total == 0) { + BogoCbData *cbdata = (BogoCbData *)data; + + if (cbdata->message) + statusbar_print_all(cbdata->message); + else if (cbdata->total == 0) { statusbar_pop_all(); } - if (total && done) - statusbar_progress_all(done, total, 10); + if (cbdata->total && cbdata->done) + statusbar_progress_all(cbdata->done, cbdata->total, 10); else statusbar_progress_all(0,0,0); + g_free(cbdata->message); + g_free(cbdata); GTK_EVENTS_FLUSH(); + return FALSE; +} + +static void gtk_safe_message_callback(gchar *message, gint total, gint done) +{ + BogoCbData *cbdata = g_new0(BogoCbData, 1); + if (message) + cbdata->message = g_strdup(message); + cbdata->total = total; + cbdata->done = done; + g_timeout_add(0, gtk_message_callback, cbdata); } static struct BogofilterPage bogofilter_page; @@ -271,7 +292,7 @@ gint bogofilter_gtk_init(void) bogofilter_page.page.weight = 35.0; prefs_gtk_register_page((PrefsPage *) &bogofilter_page); - bogofilter_set_message_callback(gtk_message_callback); + bogofilter_set_message_callback(gtk_safe_message_callback); debug_print("Bogofilter GTK plugin loaded\n"); return 0; -- 2.25.1