[Commits] .cvsignore NONE 1.1.2.1 Makefile.am NONE 1.1.2.1 bsfilter.c NONE 1.1.2.1 bsfilter.h NONE 1.1.2.1 bsfilter_gtk.c NONE 1.1.2.1 claws.def NONE 1.1.2.1 placeholder.txt 1.1.2.1 NONE plugin.def NONE 1.1.2.1 version.rc NONE 1.1.2.1

colin at claws-mail.org colin at claws-mail.org
Sat Feb 16 14:48:18 CET 2013


Update of /home/claws-mail/claws/src/plugins/bsfilter
In directory srv:/tmp/cvs-serv32400/src/plugins/bsfilter

Added Files:
      Tag: gtk2
	.cvsignore Makefile.am bsfilter.c bsfilter.h bsfilter_gtk.c 
	claws.def plugin.def version.rc 
Removed Files:
      Tag: gtk2
	placeholder.txt 
Log Message:
2013-02-16 [colin]	3.9.0cvs74

	* po/POTFILES.in
	* po/bg.po
	* po/ca.po
	* po/cs.po
	* po/de.po
	* po/en_GB.po
	* po/es.po
	* po/fi.po
	* po/fr.po
	* po/hu.po
	* po/id_ID.po
	* po/it.po
	* po/ja.po
	* po/lt.po
	* po/nl.po
	* po/pl.po
	* po/pt_BR.po
	* po/pt_PT.po
	* po/ru.po
	* po/sk.po
	* po/sv.po
	* po/uk.po
	* po/zh_CN.po
	* po/zh_TW.po
	* src/plugins/Makefile.am
	* src/plugins/archive/.cvsignore
	* src/plugins/archive/Makefile.am
	* src/plugins/archive/archiver.c
	* src/plugins/archive/archiver.h
	* src/plugins/archive/archiver_gtk.c
	* src/plugins/archive/archiver_prefs.c
	* src/plugins/archive/archiver_prefs.h
	* src/plugins/archive/libarchive_archive.c
	* src/plugins/archive/libarchive_archive.h
	* src/plugins/archive/placeholder.txt
	* src/plugins/att_remover/.cvsignore
	* src/plugins/att_remover/Makefile.am
	* src/plugins/att_remover/att_remover.c
	* src/plugins/att_remover/placeholder.txt
	* src/plugins/bsfilter/.cvsignore
	* src/plugins/bsfilter/Makefile.am
	* src/plugins/bsfilter/bsfilter.c
	* src/plugins/bsfilter/bsfilter.h
	* src/plugins/bsfilter/bsfilter_gtk.c
	* src/plugins/bsfilter/claws.def
	* src/plugins/bsfilter/placeholder.txt
	* src/plugins/bsfilter/plugin.def
	* src/plugins/bsfilter/version.rc
		Add archive, att_remover, bsfilter
	* src/plugins/vcalendar/Makefile.in
	* src/plugins/vcalendar/libical/libical/icalversion.h
		Remove useless files

--- NEW FILE: .cvsignore ---
.deps
.libs
Makefile
Makefile.in
*.o
*.lo
*.la

--- NEW FILE: version.rc ---
1 VERSIONINFO
 FILEVERSION 0, 0, 0, 0
 PRODUCTVERSION 0, 0, 0, 0
 FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x40004L
 FILETYPE 0x2L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "000004b0"
        BEGIN
            VALUE "FileDescription", "Bsfilter Plugin\0"
            VALUE "FileVersion", "0.0.0.0\0"
            VALUE "ProductVersion", "0.0.0.0 Win32\0"
            VALUE "LegalCopyright", "GPL / © 1999-2008 Hiroyuki Yamamoto & The Claws Mail Team\0"
            VALUE "CompanyName", "GNU / Free Software Foundation\0"
            VALUE "ProductName", "Claws Mail\0"
//            VALUE "Comments", "\0"
//            VALUE "InternalName", "\0"
//            VALUE "LegalTrademarks", "\0"
//            VALUE "OriginalFilename", "\0"
//            VALUE "PrivateBuild", "\0"
//            VALUE "SpecialBuild", "\0"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x0, 1200
    END
END

--- NEW FILE: claws.def ---
LIBRARY CLAWS-MAIL.EXE
EXPORTS
get_locale_dir
check_plugin_version
alertpanel
conv_codeset_strdup
conv_get_locale_charset_str_no_utf8
debug_print_real
debug_srcname
get_rc_dir 
hooks_register_hook
hooks_unregister_hook
line_has_quote_char
matcherlist_free
matcherlist_match
matcherlist_new
matcherprop_new
pref_get_escaped_pref
pref_get_unescaped_pref
prefs_common
prefs_file_close
prefs_file_close_revert
prefs_gtk_register_page
prefs_gtk_unregister_page
prefs_read_config
prefs_set_block_label
prefs_set_default
prefs_write_open
prefs_write_param
prefs_common_get_prefs
addressbook_folder_selection
alertpanel_error
combobox_text_new
complete_address
end_address_completion
execute_command_line
extract_address
folder_find_item_from_identifier
folder_get_default_trash
folder_item_get_identifier
folder_item_get_path
folder_item_remove_msg
foldersel_folder_sel
get_complete_address
gtkut_get_browse_directory_btn
log_error
prefs_button_toggled
prefs_button_toggled follow
procmsg_get_message_file
procmsg_msginfo_set_flags
procmsg_msginfo_unset_flags
procmsg_register_spam_learner
procmsg_spam_set_folder
procmsg_unregister_spam_learner
start_address_completion
statusbar_pop_all
statusbar_print_all
statusbar_progress_all

--- NEW FILE: plugin.def ---
EXPORTS
        plugin_desc
        plugin_done
        plugin_init
        plugin_licence
        plugin_name
        plugin_type
	plugin_provides
        plugin_version


--- NEW FILE: bsfilter_gtk.c ---
/*
 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
 * Copyright (C) 1999-2009 Colin Leroy <colin at colino.net> and 
 * the Claws Mail team
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */

#ifdef HAVE_CONFIG_H
#  include "config.h"
#include "claws-features.h"
#endif

#include <glib.h>
#include <glib/gi18n.h>

#include "defs.h"

#include <glib.h>
#include <gtk/gtk.h>
#include "gtk/gtkutils.h"

#include "common/claws.h"
#include "common/version.h"
#include "plugin.h"
#include "common/utils.h"
#include "prefs.h"
#include "folder.h"
#include "prefs_gtk.h"
#include "foldersel.h"
#include "statusbar.h"
#include "bsfilter.h"
#include "menu.h"
#include "addressbook.h"
#include "combobox.h"

struct BsfilterPage
{
	PrefsPage page;

	GtkWidget *process_emails;
	GtkWidget *receive_spam;
	GtkWidget *save_folder;
	GtkWidget *save_folder_select;
	GtkWidget *max_size;
	GtkWidget *bspath;
	GtkWidget *whitelist_ab;
	GtkWidget *whitelist_ab_folder_combo;
	GtkWidget *learn_from_whitelist_chkbtn;
	GtkWidget *mark_as_read;
};

static void foldersel_cb(GtkWidget *widget, gpointer data)
{
	GtkWidget *entry = (GtkWidget *) data;
	FolderItem *item;
	gchar *item_id;
	gint newpos = 0;
	
	item = foldersel_folder_sel(NULL, FOLDER_SEL_MOVE, NULL, FALSE);
	if (item && (item_id = folder_item_get_identifier(item)) != NULL) {
		gtk_editable_delete_text(GTK_EDITABLE(entry), 0, -1);
		gtk_editable_insert_text(GTK_EDITABLE(entry), item_id, strlen(item_id), &newpos);
		g_free(item_id);
	}
}

#ifndef USE_NEW_ADDRBOOK
static void bsfilter_whitelist_ab_select_cb(GtkWidget *widget, gpointer data)
{
	struct BsfilterPage *page = (struct BsfilterPage *) data;
	const gchar *folderpath = NULL;
	gchar *new_path = NULL;

	folderpath = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((page->whitelist_ab_folder_combo)))));
	new_path = addressbook_folder_selection(folderpath);
	if (new_path) {
		gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((page->whitelist_ab_folder_combo)))), new_path);
		g_free(new_path);
	} 
}
#endif

static void bsfilter_create_widget_func(PrefsPage * _page,
					    GtkWindow * window,
					    gpointer data)
{
	struct BsfilterPage *page = (struct BsfilterPage *) _page;
	BsfilterConfig *config;

	GtkWidget *vbox1, *vbox2;
	GtkWidget *hbox_max_size;
	GtkWidget *hbox_process_emails, *hbox_save_spam;
	GtkWidget *hbox_bspath, *hbox_whitelist;
	GtkWidget *hbox_mark_as_read;

	GtkWidget *max_size_label;
	GtkObject *max_size_spinbtn_adj;
	GtkWidget *max_size_spinbtn;
	GtkWidget *max_size_kb_label;

	GtkWidget *process_emails_checkbtn;

	GtkWidget *save_spam_checkbtn;
	GtkWidget *save_spam_folder_entry;
	GtkWidget *save_spam_folder_select;

	GtkWidget *whitelist_ab_checkbtn;
	GtkWidget *learn_from_whitelist_chkbtn;
	GtkWidget *bspath_label;
	GtkWidget *bspath_entry;

	GtkWidget *mark_as_read_checkbtn;

	GtkWidget *whitelist_ab_folder_combo;
	GtkWidget *whitelist_ab_select_btn;

	vbox1 = gtk_vbox_new (FALSE, VSPACING);
	gtk_widget_show (vbox1);
	gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);

	vbox2 = gtk_vbox_new (FALSE, 4);
	gtk_widget_show (vbox2);
	gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);

	hbox_process_emails = gtk_hbox_new(FALSE, 8);
	gtk_widget_show(hbox_process_emails);
	gtk_box_pack_start (GTK_BOX (vbox2), hbox_process_emails, TRUE, TRUE, 0);

	process_emails_checkbtn = gtk_check_button_new_with_label(
			_("Process messages on receiving"));
	gtk_widget_show(process_emails_checkbtn);
	gtk_box_pack_start(GTK_BOX(hbox_process_emails), process_emails_checkbtn, TRUE, TRUE, 0);

	hbox_max_size = gtk_hbox_new(FALSE, 8);
	gtk_widget_show(hbox_max_size);
	gtk_box_pack_start (GTK_BOX (vbox2), hbox_max_size, TRUE, TRUE, 0);

	max_size_label = gtk_label_new(_("Maximum size"));
	gtk_widget_show(max_size_label);
	gtk_box_pack_start(GTK_BOX(hbox_max_size), max_size_label, FALSE, FALSE, 0);

	max_size_spinbtn_adj = gtk_adjustment_new(250, 0, 10000, 10, 10, 0);
	max_size_spinbtn = gtk_spin_button_new(GTK_ADJUSTMENT(max_size_spinbtn_adj), 1, 0);
	gtk_widget_show(max_size_spinbtn);
	gtk_box_pack_start(GTK_BOX(hbox_max_size), max_size_spinbtn, FALSE, FALSE, 0);
	CLAWS_SET_TIP(max_size_spinbtn,
			_("Messages larger than this will not be checked"));
	gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(max_size_spinbtn), TRUE);

	max_size_kb_label = gtk_label_new(_("KB"));
	gtk_widget_show(max_size_kb_label);
	gtk_box_pack_start(GTK_BOX(hbox_max_size), max_size_kb_label, FALSE, FALSE, 0);

	hbox_save_spam = gtk_hbox_new(FALSE, 8);
	gtk_widget_show(hbox_save_spam);
	gtk_box_pack_start (GTK_BOX (vbox2), hbox_save_spam, TRUE, TRUE, 0);

	save_spam_checkbtn = gtk_check_button_new_with_label(_("Save spam in"));
	gtk_widget_show(save_spam_checkbtn);
	gtk_box_pack_start(GTK_BOX(hbox_save_spam), save_spam_checkbtn, FALSE, FALSE, 0);

	save_spam_folder_entry = gtk_entry_new();
	gtk_widget_show (save_spam_folder_entry);
	gtk_box_pack_start (GTK_BOX (hbox_save_spam), save_spam_folder_entry, TRUE, TRUE, 0);
	CLAWS_SET_TIP(save_spam_folder_entry,
			_("Folder for storing identified spam. Leave empty to use the trash folder."));

	save_spam_folder_select = gtkut_get_browse_directory_btn(_("_Browse"));
	gtk_widget_show (save_spam_folder_select);
	gtk_box_pack_start (GTK_BOX (hbox_save_spam), save_spam_folder_select, FALSE, FALSE, 0);
	CLAWS_SET_TIP(save_spam_folder_select,
			_("Click this button to select a folder for storing spam"));

	hbox_whitelist = gtk_hbox_new(FALSE, 8);
	gtk_widget_show(hbox_whitelist);
	gtk_box_pack_start (GTK_BOX (vbox2), hbox_whitelist, TRUE, TRUE, 0);

	whitelist_ab_checkbtn = gtk_check_button_new_with_label(_("Whitelist senders found in address book/folder"));
	gtk_widget_show(whitelist_ab_checkbtn);
	gtk_box_pack_start(GTK_BOX(hbox_whitelist), whitelist_ab_checkbtn, FALSE, FALSE, 0);
	CLAWS_SET_TIP(whitelist_ab_checkbtn,
			_("Messages coming from your address book contacts will be received in the normal folder even if detected as spam"));

	whitelist_ab_folder_combo = combobox_text_new(TRUE, _("Any"), NULL);
	gtk_widget_set_size_request(whitelist_ab_folder_combo, 100, -1);
	gtk_box_pack_start (GTK_BOX (hbox_whitelist), whitelist_ab_folder_combo, TRUE, TRUE, 0);

	whitelist_ab_select_btn = gtk_button_new_with_label(_("Select ..."));
	gtk_widget_show (whitelist_ab_select_btn);
	gtk_box_pack_start (GTK_BOX (hbox_whitelist), whitelist_ab_select_btn, FALSE, FALSE, 0);
	CLAWS_SET_TIP(whitelist_ab_select_btn,
			_("Click this button to select a book or folder in the address book"));

	learn_from_whitelist_chkbtn = gtk_check_button_new_with_label(_("Learn whitelisted emails as ham"));
	CLAWS_SET_TIP(learn_from_whitelist_chkbtn,
			_("If Bsfilter thought an email was spam or unsure, but it was whitelisted, "
			  "learn it as ham."));
	gtk_widget_show(learn_from_whitelist_chkbtn);
	gtk_box_pack_start (GTK_BOX (vbox2), learn_from_whitelist_chkbtn, TRUE, TRUE, 0);

	hbox_bspath = gtk_hbox_new(FALSE, 8);
	gtk_widget_show(hbox_bspath);
	gtk_box_pack_start (GTK_BOX (vbox2), hbox_bspath, FALSE, FALSE, 0);

	bspath_label = gtk_label_new(_("Bsfilter call"));
	gtk_widget_show(bspath_label);
	gtk_box_pack_start(GTK_BOX(hbox_bspath), bspath_label, FALSE, FALSE, 0);

	bspath_entry = gtk_entry_new();
	gtk_widget_show(bspath_entry);
	gtk_box_pack_start(GTK_BOX(hbox_bspath), bspath_entry, FALSE, FALSE, 0);
	CLAWS_SET_TIP(bspath_entry,
			_("Path to bsfilter executable"));

	hbox_mark_as_read = gtk_hbox_new(FALSE, 8);
	gtk_widget_show(hbox_mark_as_read);
	gtk_box_pack_start (GTK_BOX (vbox2), hbox_mark_as_read, TRUE, TRUE, 0);

	mark_as_read_checkbtn = gtk_check_button_new_with_label(_("Mark spam as read"));
	gtk_widget_show(mark_as_read_checkbtn);
	gtk_box_pack_start(GTK_BOX(hbox_mark_as_read), mark_as_read_checkbtn, FALSE, FALSE, 0);

	SET_TOGGLE_SENSITIVITY(save_spam_checkbtn, save_spam_folder_entry);
	SET_TOGGLE_SENSITIVITY(save_spam_checkbtn, save_spam_folder_select);
	SET_TOGGLE_SENSITIVITY(whitelist_ab_checkbtn, whitelist_ab_folder_combo);
	SET_TOGGLE_SENSITIVITY(whitelist_ab_checkbtn, whitelist_ab_select_btn);
	SET_TOGGLE_SENSITIVITY(whitelist_ab_checkbtn, learn_from_whitelist_chkbtn);
	SET_TOGGLE_SENSITIVITY(save_spam_checkbtn, mark_as_read_checkbtn);

	config = bsfilter_get_config();

	g_signal_connect(G_OBJECT(save_spam_folder_select), "clicked",
			G_CALLBACK(foldersel_cb), save_spam_folder_entry);
#ifndef USE_NEW_ADDRBOOK
	g_signal_connect(G_OBJECT (whitelist_ab_select_btn), "clicked",
			 G_CALLBACK(bsfilter_whitelist_ab_select_cb), page);
#else
	gtk_widget_set_sensitive(whitelist_ab_select_btn, FALSE);
#endif

	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(whitelist_ab_checkbtn), config->whitelist_ab);
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(learn_from_whitelist_chkbtn), config->learn_from_whitelist);
	if (config->whitelist_ab_folder != NULL) {
		/* translate "Any" (stored UNtranslated) */
		if (strcasecmp(config->whitelist_ab_folder, "Any") == 0)
			gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((whitelist_ab_folder_combo)))),
					config->whitelist_ab_folder);
		else
		/* backward compatibility (when translated "Any" was stored) */
		if (g_utf8_collate(config->whitelist_ab_folder, _("Any")) == 0)
			gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((whitelist_ab_folder_combo)))),
					config->whitelist_ab_folder);
		else
			gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((whitelist_ab_folder_combo)))),
					config->whitelist_ab_folder);
	}
	if (config->save_folder != NULL)
		gtk_entry_set_text(GTK_ENTRY(save_spam_folder_entry), config->save_folder);
	if (config->bspath != NULL)
		gtk_entry_set_text(GTK_ENTRY(bspath_entry), config->bspath);
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mark_as_read_checkbtn), config->mark_as_read);

	page->max_size = max_size_spinbtn;
	page->process_emails = process_emails_checkbtn;

	page->receive_spam = save_spam_checkbtn;
	page->save_folder = save_spam_folder_entry;
	page->save_folder_select = save_spam_folder_select;

	page->whitelist_ab = whitelist_ab_checkbtn;
	page->whitelist_ab_folder_combo = whitelist_ab_folder_combo;
	page->learn_from_whitelist_chkbtn = learn_from_whitelist_chkbtn;
	page->bspath = bspath_entry;

	page->mark_as_read = mark_as_read_checkbtn;

	page->page.widget = vbox1;
}

static void bsfilter_destroy_widget_func(PrefsPage *_page)
{
	debug_print("Destroying Bsfilter widget\n");
}

static void bsfilter_save_func(PrefsPage *_page)
{
	struct BsfilterPage *page = (struct BsfilterPage *) _page;
	BsfilterConfig *config;

	debug_print("Saving Bsfilter Page\n");

	config = bsfilter_get_config();

	/* process_emails */
	config->process_emails = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->process_emails));

	/* receive_spam */
	config->receive_spam = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->receive_spam));

	/* save_folder */
	g_free(config->save_folder);
	config->save_folder = gtk_editable_get_chars(GTK_EDITABLE(page->save_folder), 0, -1);

	/* whitelist_ab */
	config->whitelist_ab = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->whitelist_ab));
	g_free(config->whitelist_ab_folder);
	config->whitelist_ab_folder = gtk_editable_get_chars(
				GTK_EDITABLE(gtk_bin_get_child(GTK_BIN((page->whitelist_ab_folder_combo)))), 0, -1);
	/* store UNtranslated "Any" */
	if (g_utf8_collate(config->whitelist_ab_folder, _("Any")) == 0) {
		g_free(config->whitelist_ab_folder);
		config->whitelist_ab_folder = g_strdup("Any");
	}

	/* learn_from_whitelist_chkbtn */
	config->learn_from_whitelist = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->learn_from_whitelist_chkbtn));

	/* bspath */
	g_free(config->bspath);
	config->bspath = gtk_editable_get_chars(GTK_EDITABLE(page->bspath), 0, -1);

	/* max_size */
	config->max_size = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->max_size));

	/* mark_as_read */
	config->mark_as_read = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->mark_as_read));

	if (config->process_emails) {
		bsfilter_register_hook();
	} else {
		bsfilter_unregister_hook();
	}

	procmsg_register_spam_learner(bsfilter_learn);
	procmsg_spam_set_folder(config->save_folder, bsfilter_get_spam_folder);

	bsfilter_save_config();
}

typedef struct _BsCbData {
	gchar *message;
	gint total;
	gint done;
} BsCbData;

static gboolean gtk_message_callback(gpointer data)
{
	BsCbData *cbdata = (BsCbData *)data;

	if (cbdata->message)
		statusbar_print_all("%s", cbdata->message);
	else if (cbdata->total == 0) {
		statusbar_pop_all();
	}
	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, gboolean thread_safe)
{
	BsCbData *cbdata = g_new0(BsCbData, 1);
	if (message)
		cbdata->message = g_strdup(message);
	cbdata->total = total;
	cbdata->done = done;
	if (thread_safe)
		g_timeout_add(0, gtk_message_callback, cbdata);
	else
		gtk_message_callback(cbdata);
}

static struct BsfilterPage bsfilter_page;

gint bsfilter_gtk_init(void)
{
	static gchar *path[3];

	path[0] = _("Plugins");
	path[1] = _("Bsfilter");
	path[2] = NULL;

	bsfilter_page.page.path = path;
	bsfilter_page.page.create_widget = bsfilter_create_widget_func;
	bsfilter_page.page.destroy_widget = bsfilter_destroy_widget_func;
	bsfilter_page.page.save_page = bsfilter_save_func;
	bsfilter_page.page.weight = 35.0;

	prefs_gtk_register_page((PrefsPage *) &bsfilter_page);
	bsfilter_set_message_callback(gtk_safe_message_callback);

	debug_print("Bsfilter GTK plugin loaded\n");
	return 0;	
}

void bsfilter_gtk_done(void)
{
        prefs_gtk_unregister_page((PrefsPage *) &bsfilter_page);
}

--- placeholder.txt DELETED ---

--- NEW FILE: Makefile.am ---
EXTRA_DIST = claws.def plugin.def version.rc

if OS_WIN32

LTRCCOMPILE = $(LIBTOOL) --mode=compile --tag=RC $(RC) \
     `echo $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) | \
     sed -e 's/-I/--include-dir /g;s/-D/--define /g'`

%.lo : %.rc
	$(LTRCCOMPILE) -i $< -o $@

plugin_res = version.lo
plugin_res_ldflag = -Wl,.libs/version.o

export_symbols = -export-symbols $(srcdir)/plugin.def

plugin_deps = libclaws.a $(plugin_res) plugin.def

libclaws.a: claws.def
	$(DLLTOOL) --output-lib $@ --def $<

plugin_ldadd = -L. -lclaws

else
plugin_res =
plugin_res_ldflag =
export_symbols =
plugin_deps =
plugin_ldadd =
endif

if PLATFORM_WIN32
no_undefined = -no-undefined
else
no_undefined =
endif

if CYGWIN
cygwin_export_lib = -L$(top_builddir)/src -lclaws-mail
else
cygwin_export_lib = 
endif

plugindir = $(pkglibdir)/plugins

plugin_LTLIBRARIES = bsfilter.la

bsfilter_la_LDFLAGS = \
	$(plugin_res_ldflag) $(no_undefined) $(export_symbols) \
	-avoid-version -module \
	$(GTK_LIBS)

bsfilter_la_DEPENDENCIES = $(plugin_deps)

bsfilter_la_LIBADD = $(plugin_ldadd) $(cygwin_export_lib) \
	$(GTK_LIBS)

INCLUDES = \
	-I$(top_srcdir)/src \
	-I$(top_srcdir)/src/common \
	-I$(top_builddir)/src/common \
	-I$(top_srcdir)/src/gtk

AM_CPPFLAGS = \
	-Wall \
	$(CLAWS_MAIL_CFLAGS) \
	$(GLIB_CFLAGS) \
	$(GTK_CFLAGS) \
	-DLOCALEDIR=\""$(localedir)"\" 

bsfilter_la_SOURCES = \
	bsfilter.c bsfilter.h \
	bsfilter_gtk.c


--- NEW FILE: bsfilter.h ---
/*
 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
 * Copyright (C) 1999-2009 Colin Leroy <colin at colino.net> and 
 * the Claws Mail team
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */

#ifndef BSFILTER_H
#define BSFILTER_H 1

#include <glib.h>
#include "folder.h"

typedef struct _BsfilterConfig BsfilterConfig;

typedef void (*MessageCallback) (gchar *, gint total, gint done, gboolean thread_safe);

struct _BsfilterConfig
{
	gboolean		 process_emails;
	gboolean 		 receive_spam;
	gchar 			*save_folder;
	guint 			 max_size;
	gchar			*bspath;
	gboolean		 whitelist_ab;
	gchar			*whitelist_ab_folder;
	gboolean		 learn_from_whitelist;
	gboolean		 mark_as_read;
};

BsfilterConfig *bsfilter_get_config	      (void);
void		    bsfilter_save_config	      (void);
void 	            bsfilter_set_message_callback (MessageCallback callback);
gint bsfilter_gtk_init(void);
void bsfilter_gtk_done(void);
int bsfilter_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam);
void bsfilter_register_hook(void);
void bsfilter_unregister_hook(void);
FolderItem *bsfilter_get_spam_folder(MsgInfo *msginfo);
#endif

--- NEW FILE: bsfilter.c ---
/*
 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
 * Copyright (C) 1999-2009 Colin Leroy <colin at colino.net> and 
 * the Claws Mail team
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */

#ifdef HAVE_CONFIG_H
#  include "config.h"
#include "claws-features.h"
#endif

#include <glib.h>
#include <glib/gi18n.h>

#include "defs.h"

#include <sys/types.h>
#if HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
#ifdef USE_PTHREAD
#include <pthread.h>
#endif
#include <errno.h>

#include <glib.h>

#include "common/claws.h"
#include "common/version.h"
#include "plugin.h"
#include "common/utils.h"
#include "hooks.h"
#include "procmsg.h"
#include "folder.h"
#include "prefs.h"
#include "prefs_gtk.h"
#include "utils.h"

#include "bsfilter.h"
#include "inc.h"
#include "log.h"
#include "prefs_common.h"
#include "alertpanel.h"
#include "addr_compl.h"

#ifdef HAVE_SYSEXITS_H
#include <sysexits.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#ifdef HAVE_SYS_ERRNO_H
#include <sys/errno.h>
#endif
#ifdef HAVE_TIME_H
#include <time.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif

#define PLUGIN_NAME (_("Bsfilter"))

static guint hook_id = -1;
static MessageCallback message_callback;

static BsfilterConfig config;

static PrefParam param[] = {
	{"process_emails", "TRUE", &config.process_emails, P_BOOL,
	 NULL, NULL, NULL},
	{"receive_spam", "TRUE", &config.receive_spam, P_BOOL,
	 NULL, NULL, NULL},
	{"save_folder", NULL, &config.save_folder, P_STRING,
	 NULL, NULL, NULL},
	{"max_size", "250", &config.max_size, P_INT,
	 NULL, NULL, NULL},
#ifndef G_OS_WIN32
	{"bspath", "bsfilter", &config.bspath, P_STRING,
	 NULL, NULL, NULL},
#else
	{"bspath", "bsfilterw.exe", &config.bspath, P_STRING,
	 NULL, NULL, NULL},
#endif
	{"whitelist_ab", "FALSE", &config.whitelist_ab, P_BOOL,
	 NULL, NULL, NULL},
	{"whitelist_ab_folder", N_("Any"), &config.whitelist_ab_folder, P_STRING,
	 NULL, NULL, NULL},
	{"learn_from_whitelist", "FALSE", &config.learn_from_whitelist, P_BOOL,
	 NULL, NULL, NULL},
	{"mark_as_read", "TRUE", &config.mark_as_read, P_BOOL,
	 NULL, NULL, NULL},

	{NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
};

typedef struct _BsFilterData {
	MailFilteringData *mail_filtering_data;
	gchar **bs_args;
	MsgInfo *msginfo;
	gboolean done;
	int status;
	int whitelisted;
	gboolean in_thread;
} BsFilterData;

static BsFilterData *to_filter_data = NULL;
#ifdef USE_PTHREAD
static gboolean filter_th_done = FALSE;
static pthread_mutex_t list_mutex = PTHREAD_MUTEX_INITIALIZER;
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 bsfilter_do_filter(BsFilterData *data)
{
	int status = 0;
	gchar *file = NULL;
	gboolean whitelisted = FALSE;
	MsgInfo *msginfo = to_filter_data->msginfo;

	if (config.whitelist_ab) {
		gchar *ab_folderpath;

		if (*config.whitelist_ab_folder == '\0' ||
			strcasecmp(config.whitelist_ab_folder, "Any") == 0) {
			/* match the whole addressbook */
			ab_folderpath = NULL;
		} else {
			/* match the specific book/folder of the addressbook */
			ab_folderpath = config.whitelist_ab_folder;
		}

		start_address_completion(ab_folderpath);
	}

	debug_print("Filtering message %d\n", msginfo->msgnum);

	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) {
#ifndef G_OS_WIN32
		gchar *classify = g_strconcat((config.bspath && *config.bspath) ? config.bspath:"bsfilter",
			" --homedir '",get_rc_dir(),"' '", file, "'", NULL);
#else
		gchar *classify = g_strconcat((config.bspath && *config.bspath) ? config.bspath:"bsfilterw.exe",
			" --homedir '",get_rc_dir(),"' '", file, "'", NULL);
#endif
		status = execute_command_line(classify, FALSE);
	}

	if (config.whitelist_ab)
		end_address_completion();

	to_filter_data->status = status; 
	to_filter_data->whitelisted = whitelisted; 
}

#ifdef USE_PTHREAD
static void *bsfilter_filtering_thread(void *data) 
{
	while (!filter_th_done) {
		pthread_mutex_lock(&list_mutex);
		if (to_filter_data == NULL || to_filter_data->done == TRUE) {
			pthread_mutex_unlock(&list_mutex);
			debug_print("thread is waiting for something to filter\n");
			pthread_mutex_lock(&wait_mutex);
			pthread_cond_wait(&wait_cond, &wait_mutex);
			pthread_mutex_unlock(&wait_mutex);
		} else {
			debug_print("thread awaken with something to filter\n");
			to_filter_data->done = FALSE;
			bsfilter_do_filter(to_filter_data);
			pthread_mutex_unlock(&list_mutex);
			to_filter_data->done = TRUE;
			g_usleep(100);
		}
	}
	return NULL;
}

static pthread_t filter_th;
static int filter_th_started = 0;

static void bsfilter_start_thread(void)
{
	filter_th_done = FALSE;
	if (filter_th_started != 0)
		return;
	if (pthread_create(&filter_th, 0, 
			bsfilter_filtering_thread, 
			NULL) != 0) {
		filter_th_started = 0;
		return;
	}
	debug_print("thread created\n");
	filter_th_started = 1;
}

static void bsfilter_stop_thread(void)
{
	void *res;
	while (pthread_mutex_trylock(&list_mutex) != 0) {
		GTK_EVENTS_FLUSH();
		g_usleep(100);
	}
	if (filter_th_started != 0) {
		filter_th_done = TRUE;
		debug_print("waking thread up\n");
		pthread_mutex_lock(&wait_mutex);
		pthread_cond_broadcast(&wait_cond);
		pthread_mutex_unlock(&wait_mutex);
		pthread_join(filter_th, &res);
		filter_th_started = 0;
	}
	pthread_mutex_unlock(&list_mutex);
	debug_print("thread done\n");
}
#endif

static gboolean mail_filtering_hook(gpointer source, gpointer data)
{
	MailFilteringData *mail_filtering_data = (MailFilteringData *) source;
	MsgInfo *msginfo = mail_filtering_data->msginfo;
	static gboolean warned_error = FALSE;
	int status = 0, whitelisted = 0;
#ifndef G_OS_WIN32
	gchar *bs_exec = (config.bspath && *config.bspath) ? config.bspath:"bsfilter";
#else
	gchar *bs_exec = (config.bspath && *config.bspath) ? config.bspath:"bsfilterw.exe";
#endif
	gboolean filtered = FALSE;
	
	if (!config.process_emails) {
		return filtered;
	}
	
	if (msginfo == NULL) {
		g_warning("wrong call to bsfilter mail_filtering_hook");
		return filtered;
	}
		
	/* we have to make sure the mails are cached - or it'll break on IMAP */
	if (message_callback != NULL)
		message_callback(_("Bsfilter: fetching body..."), 0, 0, FALSE);
	if (msginfo) {
		gchar *file = procmsg_get_message_file(msginfo);
		g_free(file);
	}
	if (message_callback != NULL)
		message_callback(NULL, 0, 0, FALSE);

	if (message_callback != NULL)
		message_callback(_("Bsfilter: filtering message..."), 0, 0, FALSE);

#ifdef USE_PTHREAD
	while (pthread_mutex_trylock(&list_mutex) != 0) {
		GTK_EVENTS_FLUSH();
		g_usleep(100);
	}
#endif

	to_filter_data = g_new0(BsFilterData, 1);
	to_filter_data->msginfo = msginfo;
	to_filter_data->mail_filtering_data = mail_filtering_data;
	to_filter_data->done = FALSE;
	to_filter_data->status = -1;
	to_filter_data->whitelisted = 0;
#ifdef USE_PTHREAD
	to_filter_data->in_thread = (filter_th_started != 0);
#else
	to_filter_data->in_thread = FALSE;
#endif

#ifdef USE_PTHREAD
	pthread_mutex_unlock(&list_mutex);
	
	if (filter_th_started != 0) {
		debug_print("waking thread to let it filter things\n");
		pthread_mutex_lock(&wait_mutex);
		pthread_cond_broadcast(&wait_cond);
		pthread_mutex_unlock(&wait_mutex);

		while (!to_filter_data->done) {
			GTK_EVENTS_FLUSH();
			g_usleep(100);
		}
	}

	while (pthread_mutex_trylock(&list_mutex) != 0) {
		GTK_EVENTS_FLUSH();
		g_usleep(100);

	}
	if (filter_th_started == 0)
		bsfilter_do_filter(to_filter_data);
#else
	bsfilter_do_filter(to_filter_data);	
#endif

	status = to_filter_data->status;
	whitelisted = to_filter_data->whitelisted;

	g_free(to_filter_data);
	to_filter_data = NULL;
#ifdef USE_PTHREAD
	pthread_mutex_unlock(&list_mutex);
#endif

	if (status == 1) {
		procmsg_msginfo_unset_flags(msginfo, MSG_SPAM, 0);
		debug_print("unflagging ham: %d\n", msginfo->msgnum);
		filtered = FALSE;
	} else {
		if (!whitelisted || (whitelisted && !config.learn_from_whitelist)) {
			procmsg_msginfo_set_flags(msginfo, MSG_SPAM, 0);
			debug_print("flagging spam: %d\n", msginfo->msgnum);
			filtered = TRUE;
		}
		if (whitelisted && config.learn_from_whitelist) {
			bsfilter_learn(msginfo, NULL, FALSE);
			procmsg_msginfo_unset_flags(msginfo, MSG_SPAM, 0);
			debug_print("unflagging ham: %d\n", msginfo->msgnum);
			filtered = FALSE;
		}
		if (MSG_IS_SPAM(msginfo->flags) && config.receive_spam) {
			if (config.receive_spam && config.mark_as_read)
				procmsg_msginfo_unset_flags(msginfo, (MSG_NEW|MSG_UNREAD), 0);
			if (!config.receive_spam)
				folder_item_remove_msg(msginfo->folder, msginfo->msgnum);
			filtered = TRUE;
		}
	}
		
	if (status < 0 || status > 2) { /* I/O or other errors */
		gchar *msg = NULL;
		
		if (status == 3)
			msg =  g_strdup_printf(_("The Bsfilter plugin couldn't filter "
					   "a message. The probable cause of the "
					   "error is that it didn't learn from any mail.\n"
					   "Use \"/Mark/Mark as spam\" and \"/Mark/Mark as "
					   "ham\" to train Bsfilter with a few hundred "
					   "spam and ham messages."));
		else
			msg =  g_strdup_printf(_("The Bsfilter plugin couldn't filter "
					   "a message. The command `%s` couldn't be run."), 
					   bs_exec);
		if (!prefs_common.no_recv_err_panel) {
			if (!warned_error) {
				alertpanel_error("%s", msg);
			}
			warned_error = TRUE;
		} else {
			log_error(LOG_PROTOCOL, "%s\n", msg);
		}
		g_free(msg);
	}

	if (status == 0) {
		if (config.receive_spam && MSG_IS_SPAM(msginfo->flags)) {
			FolderItem *save_folder = NULL;

			if ((!config.save_folder) ||
			    (config.save_folder[0] == '\0') ||
			    ((save_folder = folder_find_item_from_identifier(config.save_folder)) == NULL)) {
			 	if (mail_filtering_data->account && mail_filtering_data->account->set_trash_folder) {
					save_folder = folder_find_item_from_identifier(
						mail_filtering_data->account->trash_folder);
					if (save_folder)
						debug_print("found trash folder from account's advanced settings\n");
				}
				if (save_folder == NULL && mail_filtering_data->account &&
				    mail_filtering_data->account->folder) {
				    	save_folder = mail_filtering_data->account->folder->trash;
					if (save_folder)
						debug_print("found trash folder from account's trash\n");
				}
				if (save_folder == NULL && mail_filtering_data->account &&
				    !mail_filtering_data->account->folder)  {
					if (mail_filtering_data->account->inbox) {
						FolderItem *item = folder_find_item_from_identifier(
							mail_filtering_data->account->inbox);
						if (item && item->folder->trash) {
							save_folder = item->folder->trash;
							debug_print("found trash folder from account's inbox\n");
						}
					} 
					if (!save_folder && mail_filtering_data->account->local_inbox) {
						FolderItem *item = folder_find_item_from_identifier(
							mail_filtering_data->account->local_inbox);
						if (item && item->folder->trash) {
							save_folder = item->folder->trash;
							debug_print("found trash folder from account's local_inbox\n");
						}
					}
				}
				if (save_folder == NULL) {
					debug_print("using default trash folder\n");
					save_folder = folder_get_default_trash();
				}
			}
			if (save_folder) {
				msginfo->filter_op = IS_MOVE;
				msginfo->to_filter_folder = save_folder;
			}
		}
	} 
	if (message_callback != NULL)
		message_callback(NULL, 0, 0, FALSE);
	
	return filtered;
}

BsfilterConfig *bsfilter_get_config(void)
{
	return &config;
}

int bsfilter_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam)
{
	gchar *cmd = NULL;
	gchar *file = NULL;
#ifndef G_OS_WIN32
	gchar *bs_exec = (config.bspath && *config.bspath) ? config.bspath:"bsfilter";
#else
	gchar *bs_exec = (config.bspath && *config.bspath) ? config.bspath:"bsfilterw.exe";
#endif
	gint status = 0;
	gboolean free_list = FALSE;
	GSList *cur = NULL;

	if (msginfo == NULL && msglist == NULL) {
		return -1;
	}
	if (msginfo != NULL && msglist == NULL) {
		msglist = g_slist_append(NULL, msginfo);
		free_list = TRUE;
	}
	for (cur = msglist; cur; cur = cur->next) {
		msginfo = (MsgInfo *)cur->data;
		file = procmsg_get_message_file(msginfo);
		if (file == NULL) {
			return -1;
		} else {
			if (message_callback != NULL)
				message_callback(_("Bsfilter: learning from message..."), 0, 0, FALSE);
			if (spam)
				/* learn as spam */
				cmd = g_strdup_printf("%s --homedir '%s' -su '%s'", bs_exec, get_rc_dir(), file);
			else 
				/* learn as ham */
				cmd = g_strdup_printf("%s --homedir '%s' -cu '%s'", bs_exec, get_rc_dir(), file);
				
			debug_print("%s\n", cmd);
			if ((status = execute_command_line(cmd, FALSE)) != 0)
				log_error(LOG_PROTOCOL, _("Learning failed; `%s` returned with status %d."),
						cmd, status);
			g_free(cmd);
			g_free(file);
			if (message_callback != NULL)
				message_callback(NULL, 0, 0, FALSE);
		}
	}
	if (free_list)
		g_slist_free(msglist);

	return 0;
}

void bsfilter_save_config(void)
{
	PrefFile *pfile;
	gchar *rcpath;

	debug_print("Saving Bsfilter Page\n");

	rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
	pfile = prefs_write_open(rcpath);
	g_free(rcpath);
	if (!pfile || (prefs_set_block_label(pfile, "Bsfilter") < 0))
		return;

	if (prefs_write_param(param, pfile->fp) < 0) {
		g_warning("Failed to write Bsfilter configuration to file\n");
		prefs_file_close_revert(pfile);
		return;
	}
        if (fprintf(pfile->fp, "\n") < 0) {
		FILE_OP_ERROR(rcpath, "fprintf");
		prefs_file_close_revert(pfile);
	} else
	        prefs_file_close(pfile);
}

void bsfilter_set_message_callback(MessageCallback callback)
{
	message_callback = callback;
}

gint plugin_init(gchar **error)
{
	gchar *rcpath;
	hook_id = -1;

	if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
				VERSION_NUMERIC, PLUGIN_NAME, error))
		return -1;

	prefs_set_default(param);
	rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
	prefs_read_config(param, "Bsfilter", rcpath, NULL);
	g_free(rcpath);

	bsfilter_gtk_init();
		
	debug_print("Bsfilter plugin loaded\n");

#ifdef USE_PTHREAD
	bsfilter_start_thread();
#endif

	if (config.process_emails) {
		bsfilter_register_hook();
	}

	procmsg_register_spam_learner(bsfilter_learn);
	procmsg_spam_set_folder(config.save_folder, bsfilter_get_spam_folder);

	return 0;
	
}

FolderItem *bsfilter_get_spam_folder(MsgInfo *msginfo)
{
	FolderItem *item = folder_find_item_from_identifier(config.save_folder);

	if (item || msginfo == NULL || msginfo->folder == NULL)
		return item;

	if (msginfo->folder->folder &&
	    msginfo->folder->folder->account && 
	    msginfo->folder->folder->account->set_trash_folder) {
		item = folder_find_item_from_identifier(
			msginfo->folder->folder->account->trash_folder);
	}

	if (item == NULL && 
	    msginfo->folder->folder &&
	    msginfo->folder->folder->trash)
		item = msginfo->folder->folder->trash;
		
	if (item == NULL)
		item = folder_get_default_trash();
		
	debug_print("bs spam dir: %s\n", folder_item_get_path(item));
	return item;
}

gboolean plugin_done(void)
{
	if (hook_id != -1) {
		bsfilter_unregister_hook();
	}
#ifdef USE_PTHREAD
	bsfilter_stop_thread();
#endif
	g_free(config.save_folder);
	bsfilter_gtk_done();
	procmsg_unregister_spam_learner(bsfilter_learn);
	procmsg_spam_set_folder(NULL, NULL);
	debug_print("Bsfilter plugin unloaded\n");
	return TRUE;
}

const gchar *plugin_name(void)
{
	return PLUGIN_NAME;
}

const gchar *plugin_desc(void)
{
	return _("This plugin can check all messages that are received from an "
	         "IMAP, LOCAL or POP account for spam using Bsfilter. "
		 "You will need Bsfilter installed locally.\n"
	         "\n"
		 "Before Bsfilter can recognize spam messages, you have to "
		 "train it by marking a few hundred spam and ham messages "
		 "with the use of \"/Mark/Mark as spam\" and \"/Mark/Mark as "
		 "ham\".\n"
	         "\n"
	         "When a message is identified as spam it can be deleted or "
	         "saved in a specially designated folder.\n"
	         "\n"
		 "Options can be found in /Configuration/Preferences/Plugins/Bsfilter");
}

const gchar *plugin_type(void)
{
	return "GTK2";
}

const gchar *plugin_licence(void)
{
	return "GPL3+";
}

const gchar *plugin_version(void)
{
	return VERSION;
}

struct PluginFeature *plugin_provides(void)
{
	static struct PluginFeature features[] = 
		{ {PLUGIN_FILTERING, N_("Spam detection")},
		  {PLUGIN_FILTERING, N_("Spam learning")},
		  {PLUGIN_NOTHING, NULL}};
	return features;
}

void bsfilter_register_hook(void)
{
	if (hook_id == -1)
		hook_id = hooks_register_hook(MAIL_FILTERING_HOOKLIST, mail_filtering_hook, NULL);
	if (hook_id == -1) {
		g_warning("Failed to register mail filtering hook");
		config.process_emails = FALSE;
	}
}

void bsfilter_unregister_hook(void)
{
	if (hook_id != -1) {
		hooks_unregister_hook(MAIL_FILTERING_HOOKLIST, hook_id);
	}
	hook_id = -1;
}



More information about the Commits mailing list