2006-08-30 [colin] 2.4.0cvs113
authorColin Leroy <colin@colino.net>
Wed, 30 Aug 2006 06:47:55 +0000 (06:47 +0000)
committerColin Leroy <colin@colino.net>
Wed, 30 Aug 2006 06:47:55 +0000 (06:47 +0000)
* src/plugins/bogofilter/bogofilter.c
Really fast mass learning - thanks to David
Relson for the options explanations :)

ChangeLog
PATCHSETS
configure.ac
src/plugins/bogofilter/bogofilter.c

index a21a164..895e73a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-08-30 [colin]     2.4.0cvs113
+
+       * src/plugins/bogofilter/bogofilter.c
+               Really fast mass learning - thanks to David
+               Relson for the options explanations :)
+
 2006-08-30 [colin]     2.4.0cvs112
 
        * src/msgcache.c
index 5cda250..0320445 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.1.2.3 -r 1.1.2.4 src/plugins//bogofilter/bogofilter.c;  cvs diff -u -r 1.18.2.38 -r 1.18.2.39 src/plugins//spamassassin/spamassassin.c;  ) > 2.4.0cvs110.patchset
 ( cvs diff -u -r 1.207.2.113 -r 1.207.2.114 src/folderview.c;  cvs diff -u -r 1.83.2.82 -r 1.83.2.83 src/mimeview.c;  cvs diff -u -r 1.20.2.14 -r 1.20.2.15 src/mimeview.h;  cvs diff -u -r 1.395.2.236 -r 1.395.2.237 src/summaryview.c;  cvs diff -u -r 1.96.2.141 -r 1.96.2.142 src/textview.c;  cvs diff -u -r 1.5.2.39 -r 1.5.2.40 src/gtk/gtkutils.c;  cvs diff -u -r 1.4.2.24 -r 1.4.2.25 src/gtk/gtkutils.h;  ) > 2.4.0cvs111.patchset
 ( cvs diff -u -r 1.16.2.38 -r 1.16.2.39 src/msgcache.c;  ) > 2.4.0cvs112.patchset
+( cvs diff -u -r 1.1.2.4 -r 1.1.2.5 src/plugins/bogofilter/bogofilter.c;  ) > 2.4.0cvs113.patchset
index ba8dd68..3d0d5ae 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=4
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=112
+EXTRA_VERSION=113
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 0490ef8..0c6a388 100644 (file)
@@ -223,33 +223,92 @@ int bogofilter_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam)
                MsgInfo *info;
                int total = g_slist_length(msglist);
                int done = 0;
+               gboolean some_correction = FALSE, some_no_correction = FALSE;
+       
                if (message_callback != NULL)
                        message_callback(_("Bogofilter: learning from messages..."), total, 0);
                
-               for (; cur && status == 0; cur = cur->next) {
+               for (cur = msglist; cur && status == 0; cur = cur->next) {
                        info = (MsgInfo *)cur->data;
-                       file = procmsg_get_message_file(info);
-
                        if (spam)
-                               /* learn as spam */
-                               cmd = g_strdup_printf("%s -s -I '%s'", bogo_exec, file);
+                               some_no_correction = TRUE;
                        else if (MSG_IS_SPAM(info->flags))
                                /* correct bogofilter, this wasn't spam */
-                               cmd = g_strdup_printf("%s -Sn -I '%s'", bogo_exec, file);
+                               some_correction = TRUE;
                        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++;
-                       if (message_callback != NULL)
-                               message_callback(NULL, total, done);
+                               some_no_correction = TRUE;
+                       
                }
+               
+               if (some_correction && some_no_correction) {
+                       /* we potentially have to do different stuff for every mail */
+                       for (cur = msglist; cur && status == 0; cur = cur->next) {
+                               info = (MsgInfo *)cur->data;
+                               file = procmsg_get_message_file(info);
+
+                               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++;
+                               if (message_callback != NULL)
+                                       message_callback(NULL, total, done);
+                       }
+               } else if (some_correction || some_no_correction) {
+                       int count = 0;
+                       gchar *file_list = NULL;
+                       cur = msglist;
+                       
+                       while (cur && status == 0) {
+                               gchar *tmp = NULL;
+                               info = (MsgInfo *)cur->data;
+                               file = procmsg_get_message_file(info);
+                               if (file) {
+                                       tmp = g_strdup_printf("%s%s'%s'", 
+                                               file_list?file_list:"",
+                                               file_list?" ":"",
+                                               file);
+                                       g_free(file_list);
+                                       file_list = tmp;
+                               }
+                               g_free(file);
+                               count ++;
+                               done++;
+                               if (count > 10 || cur->next == NULL) {
+                                       /* flush */
+                                       if (some_correction && !some_no_correction)
+                                               cmd = g_strdup_printf("%s -Sn -B %s", bogo_exec, file_list);
+                                       else if (some_no_correction && !some_correction)
+                                               cmd = g_strdup_printf("%s -%c -B %s", bogo_exec, spam?'s':'n', file_list);
+                                       else
+                                               g_warning("duuh bogofilter plugin shouldn't be there!\n");
+                                       if ((status = execute_command_line(cmd, FALSE)) != 0)
+                                               alertpanel_error(_("Learning failed; `%s` returned with status %d."),
+                                                               cmd, status);
+                                       count = 0;
+                                       g_free(cmd);
+                                       g_free(file_list);
+                                       file_list = NULL;
+                               }
+                               if (message_callback != NULL)
+                                       message_callback(NULL, total, done);
+                               cur = cur->next;
+                       }
+                       g_free(file_list);
+               }
+
                if (message_callback != NULL)
                        message_callback(NULL, 0, 0);
                return 0;