2006-12-15 [ticho] 2.6.1cvs38
authorAndrej Kacian <ticho@claws-mail.org>
Fri, 15 Dec 2006 13:35:06 +0000 (13:35 +0000)
committerAndrej Kacian <ticho@claws-mail.org>
Fri, 15 Dec 2006 13:35:06 +0000 (13:35 +0000)
* src/plugins/bogofilter/bogofilter.c
* src/plugins/bogofilter/bogofilter.h
* src/plugins/bogofilter/bogofilter_gtk.c
Add option to whitelist senders found in addressbook. Patch by colin.

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

index f7c77af..0eba4a4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2006-12-15 [ticho]     2.6.1cvs38
+
+       * src/plugins/bogofilter/bogofilter.c
+       * src/plugins/bogofilter/bogofilter.h
+       * src/plugins/bogofilter/bogofilter_gtk.c
+               Add option to whitelist senders found in addressbook. Patch by colin.
+
 2006-12-15 [paul]      2.6.1cvs37
 
        * src/folderview.c
index a12cf74..884ac7f 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( 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
 ( cvs diff -u -r 1.207.2.137 -r 1.207.2.138 src/folderview.c;  ) > 2.6.1cvs37.patchset
+( cvs diff -u -r 1.1.2.16 -r 1.1.2.17 src/plugins/bogofilter/bogofilter.c;  cvs diff -u -r 1.1.2.5 -r 1.1.2.6 src/plugins/bogofilter/bogofilter.h;  cvs diff -u -r 1.1.2.9 -r 1.1.2.10 src/plugins/bogofilter/bogofilter_gtk.c;  ) > 2.6.1cvs38.patchset
index 6b00757..9b6753e 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=6
 MICRO_VERSION=1
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=37
+EXTRA_VERSION=38
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index fdd7ba3..3d6047d 100644 (file)
@@ -49,6 +49,7 @@
 #include "log.h"
 #include "prefs_common.h"
 #include "alertpanel.h"
+#include "addr_compl.h"
 
 #ifdef HAVE_SYSEXITS_H
 #include <sysexits.h>
@@ -90,6 +91,8 @@ static PrefParam param[] = {
         NULL, NULL, NULL},
        {"insert_header", "FALSE", &config.insert_header, P_BOOL,
         NULL, NULL, NULL},
+       {"whitelist_ab", "TRUE", &config.whitelist_ab, P_BOOL,
+        NULL, NULL, NULL},
 
        {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
@@ -141,6 +144,33 @@ static pthread_mutex_t wait_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t wait_cond = PTHREAD_COND_INITIALIZER; 
 #endif
 
+static gboolean found_in_addressbook(const gchar *address)
+{
+       gchar *addr = NULL;
+       gboolean found = FALSE;
+       gint num_addr = 0;
+       
+       if (!address)
+               return FALSE;
+       
+       addr = g_strdup(address);
+       extract_address(addr);
+       num_addr = complete_address(addr);
+       if (num_addr > 1) {
+               /* skip first item (this is the search string itself) */
+               int i = 1;
+               for (; i < num_addr && !found; i++) {
+                       gchar *caddr = get_complete_address(i);
+                       extract_address(caddr);
+                       if (strcasecmp(caddr, addr) == 0)
+                               found = TRUE;
+                       g_free(caddr);
+               }
+       }
+       g_free(addr);
+       return found;
+}
+
 static void bogofilter_do_filter(BogoFilterData *data)
 {
        GPid bogo_pid;
@@ -167,16 +197,27 @@ static void bogofilter_do_filter(BogoFilterData *data)
                error = NULL;
                status = -1;
        } else {
+       
+               if (config.whitelist_ab)
+                       start_address_completion(NULL);
+
                for (cur = data->msglist; cur; cur = cur->next) {
+                       gboolean whitelisted = FALSE;
                        msginfo = (MsgInfo *)cur->data;
                        debug_print("Filtering message %d (%d/%d)\n", msginfo->msgnum, curnum, total);
 
                        if (message_callback != NULL)
                                message_callback(NULL, total, curnum++, data->in_thread);
 
+                       if (config.whitelist_ab && msginfo->from && 
+                           found_in_addressbook(msginfo->from))
+                               whitelisted = TRUE;
+
                        /* 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));
@@ -214,8 +255,9 @@ static void bogofilter_do_filter(BogoFilterData *data)
                                                        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]);
+                                                                       "X-Claws-Bogosity: %s, spamicity=%s%s\n",
+                                                                       bogosity, parts[2],
+                                                                       whitelisted?" [whitelisted]":"");
                                                        fwrite(tmpstr, 1, strlen(tmpstr), output);
                                                        while (fgets(tmpbuf, sizeof(buf), input))
                                                                fputs(tmpbuf, output);
@@ -226,7 +268,7 @@ static void bogofilter_do_filter(BogoFilterData *data)
                                                }
                                                g_free(tmpfile);
                                        }
-                                       if (parts && parts[0] && parts[1] && *parts[1] == 'S') {
+                                       if (!whitelisted && parts && parts[0] && parts[1] && *parts[1] == 'S') {
                                                debug_print("message %d is spam\n", msginfo->msgnum);
                                                if (config.receive_spam) {
                                                        data->spams_to_receive = g_slist_prepend(data->spams_to_receive, msginfo);
@@ -250,6 +292,8 @@ static void bogofilter_do_filter(BogoFilterData *data)
                                data->new_hams = g_slist_prepend(data->new_hams, msginfo);
                        }
                }
+               if (config.whitelist_ab)
+                       end_address_completion();
        }
        if (status != -1) {
                close(bogo_stdout);
index a8b2fc9..a976721 100644 (file)
@@ -34,6 +34,7 @@ struct _BogofilterConfig
        guint                    max_size;
        gchar                   *bogopath;
        gboolean                 insert_header;
+       gboolean                 whitelist_ab;
 };
 
 BogofilterConfig *bogofilter_get_config              (void);
index 0a0e605..ad3241b 100644 (file)
@@ -52,6 +52,7 @@ struct BogofilterPage
        GtkWidget *insert_header;
        GtkWidget *max_size;
        GtkWidget *bogopath;
+       GtkWidget *whitelist_ab;
 };
 
 static void foldersel_cb(GtkWidget *widget, gpointer data)
@@ -92,6 +93,7 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
        GtkWidget *save_spam_folder_select;
 
        GtkWidget *insert_header_chkbtn;
+       GtkWidget *whitelist_ab_chkbtn;
        GtkWidget *bogopath_label;
        GtkWidget *bogopath_entry;
 
@@ -162,9 +164,15 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
        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"),
+                       _("Only done for messages in MH folders"),
                        NULL);
 
+       whitelist_ab_chkbtn = gtk_check_button_new_with_label(_("Whitelist senders present in addressbook"));
+       gtk_widget_show(whitelist_ab_chkbtn);
+       gtk_box_pack_start(GTK_BOX(vbox2), whitelist_ab_chkbtn, FALSE, FALSE, 0);
+       gtk_tooltips_set_tip(tooltips, whitelist_ab_chkbtn,
+                       _("Messages coming from your addressbook contacts will never be marked as spam"), 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);
@@ -193,6 +201,7 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
        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);
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(whitelist_ab_chkbtn), config->whitelist_ab);
        if (config->save_folder != NULL)
                gtk_entry_set_text(GTK_ENTRY(save_spam_folder_entry), config->save_folder);
        if (config->bogopath != NULL)
@@ -202,6 +211,7 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
        page->process_emails = process_emails_checkbtn;
        page->receive_spam = save_spam_checkbtn;
        page->insert_header = insert_header_chkbtn;
+       page->whitelist_ab = whitelist_ab_chkbtn;
        page->save_folder = save_spam_folder_entry;
        page->save_folder_select = save_spam_folder_select;
        page->bogopath = bogopath_entry;
@@ -236,6 +246,9 @@ static void bogofilter_save_func(PrefsPage *_page)
        /* insert_header */
        config->insert_header = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->insert_header));
 
+       /* whitelist_ab */
+       config->whitelist_ab = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->whitelist_ab));
+
        /* bogopath */
        g_free(config->bogopath);
        config->bogopath = gtk_editable_get_chars(GTK_EDITABLE(page->bogopath), 0, -1);