2006-11-09 [colin] 2.6.0cvs23
authorColin Leroy <colin@colino.net>
Thu, 9 Nov 2006 21:59:44 +0000 (21:59 +0000)
committerColin Leroy <colin@colino.net>
Thu, 9 Nov 2006 21:59:44 +0000 (21:59 +0000)
* 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
PATCHSETS
configure.ac
src/plugins/bogofilter/bogofilter.c
src/plugins/bogofilter/bogofilter_gtk.c

index 540f480fd7223218364d15cf76285b489e787129..c33989bd06fec909dca5d902cd2eee0b40d53cbf 100644 (file)
--- 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
index 8a925ab1fb21aad08bbe1f70881251717d18eb86..eae543b47ae61d6ef51be5b03e73980ade41d544 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( 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
index e430802e21b6ca8b2bf19224982a204d0a8e8847..db01b830a1377805afc66bf807412e6fb37a2587 100644 (file)
@@ -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=
 
index 0b7bdb9f86834767d1b0b65a9fc598092ee3bf98..c6a95c4814ffc67a614444c3c23c62838758bc17 100644 (file)
@@ -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;
                
index 30eda9f97826a0f1d994b1d750e0787357e55bde..4a582619e90f2319c887d02be2e2f16f13a380be 100644 (file)
@@ -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;