2006-12-15 [paul] 2.6.1cvs36
authorColin Leroy <colin@colino.net>
Fri, 15 Dec 2006 09:12:56 +0000 (09:12 +0000)
committerColin Leroy <colin@colino.net>
Fri, 15 Dec 2006 09:12:56 +0000 (09:12 +0000)
* src/plugins/bogofilter/bogofilter.c
* src/plugins/bogofilter/bogofilter.h
* src/plugins/bogofilter/bogofilter_gtk.c
Add an option to allow inserting an
X-Claws-Bogosity header (on MH folders
only). Patch by Colin

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

index 7b238b2dc022383b9eb55b899602bbc9a63882db..887ff22bc9c698fd9aaee9b4a040ef9b45736647 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2006-12-15 [paul]      2.6.1cvs36
+
+       * src/plugins/bogofilter/bogofilter.c
+       * src/plugins/bogofilter/bogofilter.h
+       * src/plugins/bogofilter/bogofilter_gtk.c
+               Add an option to allow inserting an
+               X-Claws-Bogosity header (on MH folders
+               only). Patch by Colin
+
 2006-12-14 [colin]     2.6.1cvs35
 
        * src/main.c
index 23679c9e08f65710c32a8439f89bdc593a369d9a..afbe1a5c53baf0dd05fb48634244a08cf1653f9f 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.94.2.111 -r 1.94.2.112 src/messageview.c;  cvs diff -u -r 1.19.2.11 -r 1.19.2.12 src/messageview.h;  cvs diff -u -r 1.83.2.93 -r 1.83.2.94 src/mimeview.c;  cvs diff -u -r 1.20.2.16 -r 1.20.2.17 src/mimeview.h;  cvs diff -u -r 1.395.2.271 -r 1.395.2.272 src/summaryview.c;  cvs diff -u -r 1.96.2.161 -r 1.96.2.162 src/textview.c;  cvs diff -u -r 1.12.2.15 -r 1.12.2.16 src/textview.h;  cvs diff -u -r 1.1.2.5 -r 1.1.2.6 src/gtk/gtksourceprintjob.c;  ) > 2.6.1cvs33.patchset
 ( cvs diff -u -r 1.1.2.28 -r 1.1.2.29 src/prefs_summaries.c;  cvs diff -u -r 1.1.2.36 -r 1.1.2.37 manual/advanced.xml;  ) > 2.6.1cvs34.patchset
 ( cvs diff -u -r 1.115.2.119 -r 1.115.2.120 src/main.c;  ) > 2.6.1cvs35.patchset
+( cvs diff -u -r 1.1.2.15 -r 1.1.2.16 src/plugins/bogofilter/bogofilter.c;  cvs diff -u -r 1.1.2.4 -r 1.1.2.5 src/plugins/bogofilter/bogofilter.h;  cvs diff -u -r 1.1.2.8 -r 1.1.2.9 src/plugins/bogofilter/bogofilter_gtk.c;  ) > 2.6.1cvs36.patchset
index 20d03faf7cc7b5ff02d205418f9e9eb10a6a907d..bd30de5b0d3fe225b0de18ac3e868a2f31efa161 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=6
 MICRO_VERSION=1
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=35
+EXTRA_VERSION=36
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 2e422f1a1803703a44e577651986f2e653bbef5e..fdd7ba3493b29b5e3fa647c4c681fb183c762b6b 100644 (file)
@@ -88,6 +88,8 @@ static PrefParam param[] = {
         NULL, NULL, NULL},
        {"bogopath", "bogofilter", &config.bogopath, P_STRING,
         NULL, NULL, NULL},
+       {"insert_header", "FALSE", &config.insert_header, P_BOOL,
+        NULL, NULL, NULL},
 
        {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
@@ -175,7 +177,6 @@ static void bogofilter_do_filter(BogoFilterData *data)
                        /* can set flags (SCANNED, ATTACHMENT) but that's ok 
                         * as GUI updates are hooked not direct */
                        file = procmsg_get_message_file(msginfo);
-
                        if (file) {
                                gchar *tmp = g_strdup_printf("%s\n",file);
                                write_all(bogo_stdin, tmp, strlen(tmp));
@@ -196,6 +197,35 @@ static void bogofilter_do_filter(BogoFilterData *data)
                                        }
                                        parts = g_strsplit(tmp, " ", 0);
                                        debug_print("read %s\n", buf);
+                                       if (parts && parts[0] && parts[1] && parts[2] && 
+                                           FOLDER_TYPE(msginfo->folder->folder) == F_MH &&
+                                           config.insert_header) {
+                                               gchar *tmpfile = get_tmp_file();
+                                               FILE *input = fopen(file, "r");
+                                               FILE *output = fopen(tmpfile, "w");
+                                               if (strstr(parts[2], "\n"))
+                                                       *(strstr(parts[2], "\n")) = '\0';
+                                               if (input && !output) 
+                                                       fclose (input);
+                                               else if (!input && output)
+                                                       fclose (output);
+                                               else {
+                                                       gchar tmpbuf[BUFFSIZE];
+                                                       const gchar *bogosity = *parts[1] == 'S' ? "Spam":
+                                                                                (*parts[1] == 'H' ? "Ham":"Unsure");
+                                                       gchar *tmpstr = g_strdup_printf(
+                                                                       "X-Claws-Bogosity: %s, spamicity=%s\n",
+                                                                       bogosity, parts[2]);
+                                                       fwrite(tmpstr, 1, strlen(tmpstr), output);
+                                                       while (fgets(tmpbuf, sizeof(buf), input))
+                                                               fputs(tmpbuf, output);
+                                                       fclose(input);
+                                                       fclose(output);
+                                                       move_file(tmpfile, file, TRUE);
+                                                       g_free(tmpstr);
+                                               }
+                                               g_free(tmpfile);
+                                       }
                                        if (parts && parts[0] && parts[1] && *parts[1] == 'S') {
                                                debug_print("message %d is spam\n", msginfo->msgnum);
                                                if (config.receive_spam) {
index b9ebe32f933864486b975966e5093dc894949752..a8b2fc9d52db4dcb4eba144ce325facc14e7f448 100644 (file)
@@ -33,6 +33,7 @@ struct _BogofilterConfig
        gchar                   *save_folder;
        guint                    max_size;
        gchar                   *bogopath;
+       gboolean                 insert_header;
 };
 
 BogofilterConfig *bogofilter_get_config              (void);
index b5b620690db91691c1111b4389a95cf323976f40..0a0e60574a473a4bb34044b88bb345d294b46ed0 100644 (file)
@@ -49,6 +49,7 @@ struct BogofilterPage
        GtkWidget *receive_spam;
        GtkWidget *save_folder;
        GtkWidget *save_folder_select;
+       GtkWidget *insert_header;
        GtkWidget *max_size;
        GtkWidget *bogopath;
 };
@@ -90,6 +91,7 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
        GtkWidget *save_spam_folder_entry;
        GtkWidget *save_spam_folder_select;
 
+       GtkWidget *insert_header_chkbtn;
        GtkWidget *bogopath_label;
        GtkWidget *bogopath_entry;
 
@@ -156,6 +158,13 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
                        _("Click this button to select a folder for storing spam"),
                        NULL);
 
+       insert_header_chkbtn = gtk_check_button_new_with_label(_("Insert X-Bogosity header"));
+       gtk_widget_show(insert_header_chkbtn);
+       gtk_box_pack_start(GTK_BOX(vbox2), insert_header_chkbtn, FALSE, FALSE, 0);
+       gtk_tooltips_set_tip(tooltips, insert_header_chkbtn,
+                       _("Only done for mails in MH folders"),
+                       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);
@@ -173,6 +182,7 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
 
        SET_TOGGLE_SENSITIVITY(save_spam_checkbtn, save_spam_folder_entry);
        SET_TOGGLE_SENSITIVITY(save_spam_checkbtn, save_spam_folder_select);
+       SET_TOGGLE_SENSITIVITY(save_spam_checkbtn, insert_header_chkbtn);
 
        config = bogofilter_get_config();
 
@@ -182,6 +192,7 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(max_size_spinbtn), (float) config->max_size);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(process_emails_checkbtn), config->process_emails);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(save_spam_checkbtn), config->receive_spam);
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(insert_header_chkbtn), config->insert_header);
        if (config->save_folder != NULL)
                gtk_entry_set_text(GTK_ENTRY(save_spam_folder_entry), config->save_folder);
        if (config->bogopath != NULL)
@@ -190,6 +201,7 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
        page->max_size = max_size_spinbtn;
        page->process_emails = process_emails_checkbtn;
        page->receive_spam = save_spam_checkbtn;
+       page->insert_header = insert_header_chkbtn;
        page->save_folder = save_spam_folder_entry;
        page->save_folder_select = save_spam_folder_select;
        page->bogopath = bogopath_entry;
@@ -221,6 +233,9 @@ 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);
 
+       /* insert_header */
+       config->insert_header = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->insert_header));
+
        /* bogopath */
        g_free(config->bogopath);
        config->bogopath = gtk_editable_get_chars(GTK_EDITABLE(page->bogopath), 0, -1);