CVS: sylpheedclaws/sylpheed-claws/src/plugins/bogofilter bogofilter.c,1.1.2.16,1.1.2.17 bogofilter.h,1.1.2.5,1.1.2.6 bogofilter_gtk.c,1.1.2.9,1.1.2.10
[email protected] Fri, 15 Dec 2006 13:35:09 +0000
| Newsgroups | gmane.mail.sylpheed.claws.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /pack/anoncvs/sylpheedclaws/sylpheed-claws/src/plugins/bogofilter
In directory sunsite.dk:/tmp/cvs-serv26799/src/plugins/bogofilter
Modified Files:
Tag: gtk2
bogofilter.c bogofilter.h bogofilter_gtk.c
Log Message:
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.
Index: bogofilter.c
===================================================================
RCS file: /pack/anoncvs/sylpheedclaws/sylpheed-claws/src/plugins/bogofilter/Attic/bogofilter.c,v
retrieving revision 1.1.2.16
retrieving revision 1.1.2.17
diff -u -d -r1.1.2.16 -r1.1.2.17
--- bogofilter.c 2006/12/15 09:12:56 1.1.2.16
+++ bogofilter.c 2006/12/15 13:35:05 1.1.2.17
@@ -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 @@
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_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 @@
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 @@
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 @@
}
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 @@
data->new_hams = g_slist_prepend(data->new_hams, msginfo);
}
}
+ if (config.whitelist_ab)
+ end_address_completion();
}
if (status != -1) {
close(bogo_stdout);
Index: bogofilter.h
===================================================================
RCS file: /pack/anoncvs/sylpheedclaws/sylpheed-claws/src/plugins/bogofilter/Attic/bogofilter.h,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -u -d -r1.1.2.5 -r1.1.2.6
--- bogofilter.h 2006/12/15 09:12:56 1.1.2.5
+++ bogofilter.h 2006/12/15 13:35:05 1.1.2.6
@@ -34,6 +34,7 @@
guint max_size;
gchar *bogopath;
gboolean insert_header;
+ gboolean whitelist_ab;
};
BogofilterConfig *bogofilter_get_config (void);
Index: bogofilter_gtk.c
===================================================================
RCS file: /pack/anoncvs/sylpheedclaws/sylpheed-claws/src/plugins/bogofilter/Attic/bogofilter_gtk.c,v
retrieving revision 1.1.2.9
retrieving revision 1.1.2.10
diff -u -d -r1.1.2.9 -r1.1.2.10
--- bogofilter_gtk.c 2006/12/15 09:12:56 1.1.2.9
+++ bogofilter_gtk.c 2006/12/15 13:35:06 1.1.2.10
@@ -52,6 +52,7 @@
GtkWidget *insert_header;
GtkWidget *max_size;
GtkWidget *bogopath;
+ GtkWidget *whitelist_ab;
};
static void foldersel_cb(GtkWidget *widget, gpointer data)
@@ -92,6 +93,7 @@
GtkWidget *save_spam_folder_select;
GtkWidget *insert_header_chkbtn;
+ GtkWidget *whitelist_ab_chkbtn;
GtkWidget *bogopath_label;
GtkWidget *bogopath_entry;
@@ -162,9 +164,15 @@
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 @@
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 @@
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;
@@ -235,6 +245,9 @@
/* 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);