+2002-12-31 [christoph] 0.8.8claws30
+
+ * src/mainwindow.c
+ * src/gtk/Makefile.am
+ * src/gtk/prefswindow.c ** NEW **
+ * src/gtk/prefswindow.h ** NEW **
+ add new prefs window
+
+ * src/common/plugin.c
+ don't try to load empty config lines
+
+ * src/plugins/spamassassin/Makefile.am
+ * src/plugins/spamassassin/spamassassin.c
+ * src/plugins/spamassassin/spamassassin.h ** NEW **
+ * src/plugins/spamassassin/spamassassin_gtk.c ** NEW **
+ GTK config for SpamAssassin Plugin using
+ the new prefs window
+
2002-12-31 [paul] 0.8.8claws29
* po/POTFILES.in
MICRO_VERSION=8
INTERFACE_AGE=0
BINARY_AGE=0
-EXTRA_VERSION=claws29
+EXTRA_VERSION=claws30
VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
dnl set $target
while (fgets(buf, sizeof(buf), pfile->fp) != NULL) {
if (buf[0] == '[')
break;
-
+
g_strstrip(buf);
- if (plugin_load(buf, &error) < 0) {
- debug_print("plugin loading error: %s\n", error);
+ if ((buf[0] != '\0') && (plugin_load(buf, &error) < 0)) {
+ g_warning("plugin loading error: %s\n", error);
g_free(error);
}
}
gtkstext.c gtkstext.h \
manage_window.c manage_window.h \
menu.c menu.h \
+ prefswindow.c prefswindow.h \
sslcertwindow.c sslcertwindow.h
INCLUDES = \
--- /dev/null
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2002 Hiroyuki Yamamoto and the Sylpheed-Claws 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <string.h>
+#include <gtk/gtk.h>
+
+#include "intl.h"
+#include "prefswindow.h"
+#include "../gtkutils.h"
+
+GSList *prefs_pages = NULL;
+
+typedef struct _PrefsWindow PrefsWindow;
+
+struct _PrefsWindow
+{
+ GtkWidget *window;
+ GtkWidget *table1;
+ GtkWidget *scrolledwindow1;
+ GtkWidget *ctree;
+ GtkWidget *table2;
+ GtkWidget *pagelabel;
+ GtkWidget *labelframe;
+ GtkWidget *frame;
+ GtkWidget *page_widget;
+ GtkWidget *confirm_area;
+ GtkWidget *ok_btn;
+ GtkWidget *cancel_btn;
+ GtkWidget *apply_btn;
+};
+
+void prefswindow_register_new_page(PrefsPage *page)
+{
+ prefs_pages = g_slist_append(prefs_pages, page);
+}
+
+static gboolean ctree_select_row(GtkCTree *ctree, GList *node, gint column, gpointer user_data)
+{
+ PrefsPage *page;
+ PrefsWindow *prefswindow = (PrefsWindow *) user_data;
+ gchar *labeltext;
+
+ page = (PrefsPage *) gtk_ctree_node_get_row_data(GTK_CTREE(ctree), GTK_CTREE_NODE(node));
+
+ if (prefswindow->page_widget != NULL)
+ gtk_container_remove(GTK_CONTAINER(prefswindow->table2), prefswindow->page_widget);
+
+ if (page == NULL) {
+ GtkWidget *widget;
+
+ widget = gtk_label_new("");
+
+ gtk_label_set_text(GTK_LABEL(prefswindow->pagelabel), "");
+ gtk_table_attach(GTK_TABLE(prefswindow->table2), widget, 0, 1, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0);
+ prefswindow->page_widget = widget;
+ return FALSE;
+ }
+
+ if (!page->page_open) {
+ page->create_widget(page);
+ gtk_widget_ref(page->widget);
+ gtk_widget_show_all(page->widget);
+ page->page_open = TRUE;
+ }
+
+ labeltext = (gchar *) strrchr(page->path, '/');
+ if (labeltext == NULL)
+ labeltext = page->path;
+ else
+ labeltext = labeltext + 1;
+ gtk_label_set_text(GTK_LABEL(prefswindow->pagelabel), labeltext);
+
+ prefswindow->page_widget = page->widget;
+ gtk_table_attach(GTK_TABLE(prefswindow->table2), prefswindow->page_widget, 0, 1, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 8, 8);
+
+ return FALSE;
+}
+
+static void save_all_pages()
+{
+ GSList *cur;
+
+ for (cur = prefs_pages; cur != NULL; cur = g_slist_next(cur)) {
+ PrefsPage *page = (PrefsPage *) cur->data;
+
+ if (page->page_open) {
+ page->save_page(page);
+ }
+ }
+}
+
+static void close_all_pages()
+{
+ GSList *cur;
+
+ for (cur = prefs_pages; cur != NULL; cur = g_slist_next(cur)) {
+ PrefsPage *page = (PrefsPage *) cur->data;
+
+ if (page->page_open) {
+ gtk_widget_unref(page->widget);
+ page->destroy_widget(page);
+ page->page_open = FALSE;
+ }
+ }
+}
+
+static void apply_button_released(GtkButton *button, gpointer user_data)
+{
+ save_all_pages();
+}
+
+static void ok_button_released(GtkButton *button, gpointer user_data)
+{
+ PrefsWindow *prefswindow = (PrefsWindow *) user_data;
+
+ save_all_pages();
+ gtk_widget_destroy(prefswindow->window);
+ close_all_pages();
+ g_free(prefswindow);
+}
+
+static void cancel_button_released(GtkButton *button, gpointer user_data)
+{
+ PrefsWindow *prefswindow = (PrefsWindow *) user_data;
+
+ gtk_widget_destroy(prefswindow->window);
+ close_all_pages();
+ g_free(prefswindow);
+}
+
+struct name_search
+{
+ gchar *text;
+ GtkCTreeNode *node;
+};
+
+static gboolean find_child_by_name(GtkCTree *ctree, GtkCTreeNode *node, struct name_search *name_search)
+{
+ gchar *text = NULL;
+
+ text = GTK_CELL_TEXT(GTK_CTREE_ROW(node)->row.cell[0])->text;
+ if (text == NULL)
+ return FALSE;
+
+ if (strcmp(text, name_search->text) == 0)
+ name_search->node = node;
+
+ return FALSE;
+}
+
+void prefswindow_create()
+{
+ static gchar *titles [] = {"Pages"};
+ GSList *cur;
+ gint optsize;
+ PrefsWindow *prefswindow;
+
+ prefswindow = g_new0(PrefsWindow, 1);
+
+ prefswindow->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size(GTK_WINDOW(prefswindow->window), 400, 200);
+ gtk_container_set_border_width(GTK_CONTAINER(prefswindow->window), 4);
+
+ prefswindow->table1 = gtk_table_new(2, 2, FALSE);
+ gtk_container_add(GTK_CONTAINER(prefswindow->window), prefswindow->table1);
+
+ prefswindow->scrolledwindow1 = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(prefswindow->scrolledwindow1), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
+ gtk_table_attach(GTK_TABLE(prefswindow->table1), prefswindow->scrolledwindow1, 0, 1, 0, 1, GTK_FILL, GTK_FILL | GTK_EXPAND, 2, 2);
+
+ prefswindow->ctree = gtk_ctree_new_with_titles(1, 0, titles);
+ gtk_container_add(GTK_CONTAINER(prefswindow->scrolledwindow1), prefswindow->ctree);
+
+ prefswindow->frame = gtk_frame_new(NULL);
+ gtk_frame_set_shadow_type(GTK_FRAME(prefswindow->frame), GTK_SHADOW_IN);
+ gtk_table_attach(GTK_TABLE(prefswindow->table1), prefswindow->frame, 1, 2, 0, 1, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 2, 2);
+
+ prefswindow->table2 = gtk_table_new(1, 2, FALSE);
+ gtk_container_add(GTK_CONTAINER(prefswindow->frame), prefswindow->table2);
+
+ prefswindow->labelframe = gtk_frame_new(NULL);
+ gtk_frame_set_shadow_type(GTK_FRAME(prefswindow->labelframe), GTK_SHADOW_OUT);
+ gtk_table_attach(GTK_TABLE(prefswindow->table2), prefswindow->labelframe, 0, 1, 0, 1, GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
+
+ prefswindow->pagelabel = gtk_label_new("");
+ gtk_label_set_justify(GTK_LABEL(prefswindow->pagelabel), GTK_JUSTIFY_LEFT);
+ gtk_misc_set_alignment(GTK_MISC(prefswindow->pagelabel), 0, 0.0);
+ gtk_container_add(GTK_CONTAINER(prefswindow->labelframe), prefswindow->pagelabel);
+
+ prefswindow->page_widget = gtk_label_new("");
+ gtk_table_attach(GTK_TABLE(prefswindow->table2), prefswindow->page_widget, 0, 1, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 8, 8);
+
+ /* actually we should create a tree here */
+ for (cur = prefs_pages; cur != NULL; cur = g_slist_next(cur)) {
+ PrefsPage *page = (PrefsPage *)cur->data;
+ GtkCTreeNode *node = NULL;
+ gchar *text[2], **split, *part;
+ int i;
+ struct name_search name_search;
+
+ split = g_strsplit(page->path, "/", 0);
+ for (i = 0; split[i] != NULL; i++) {
+ part = split[i];
+ name_search.text = part;
+ name_search.node = NULL;
+
+ gtk_ctree_post_recursive_to_depth(GTK_CTREE(prefswindow->ctree), node, node != NULL ? GTK_CTREE_ROW(node)->level + 1 : 1, GTK_CTREE_FUNC(find_child_by_name), &name_search);
+
+ if (name_search.node) {
+ node = name_search.node;
+ } else {
+ text[0] = part;
+ node = gtk_ctree_insert_node(GTK_CTREE(prefswindow->ctree), node, NULL, text, 0, NULL, NULL, NULL, NULL, FALSE, TRUE);
+ }
+ }
+ g_strfreev(split);
+ gtk_ctree_node_set_row_data(GTK_CTREE(prefswindow->ctree), node, page);
+ }
+ gtk_signal_connect(GTK_OBJECT(prefswindow->ctree), "tree-select-row", GTK_SIGNAL_FUNC(ctree_select_row), prefswindow);
+
+ gtk_clist_set_selection_mode(GTK_CLIST(prefswindow->ctree), GTK_SELECTION_BROWSE);
+ gtk_clist_column_titles_passive(GTK_CLIST(prefswindow->ctree));
+ optsize = gtk_clist_optimal_column_width(GTK_CLIST(prefswindow->ctree), 0);
+ gtk_clist_set_column_resizeable(GTK_CLIST(prefswindow->ctree), 0, TRUE);
+ gtk_clist_set_column_auto_resize(GTK_CLIST(prefswindow->ctree), 0, FALSE);
+ gtk_clist_set_column_width(GTK_CLIST(prefswindow->ctree), 0, optsize);
+ gtk_clist_set_column_min_width(GTK_CLIST(prefswindow->ctree), 0, optsize);
+ gtk_clist_set_column_max_width(GTK_CLIST(prefswindow->ctree), 0, optsize);
+
+ gtkut_button_set_create(&prefswindow->confirm_area,
+ &prefswindow->ok_btn, _("OK"),
+ &prefswindow->cancel_btn, _("Cancel"),
+ &prefswindow->apply_btn, _("Apply"));
+
+ gtk_table_attach(GTK_TABLE(prefswindow->table1), prefswindow->confirm_area, 0, 2, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL, 2, 2);
+
+ gtk_signal_connect(GTK_OBJECT(prefswindow->ok_btn), "released", GTK_SIGNAL_FUNC(ok_button_released), prefswindow);
+ gtk_signal_connect(GTK_OBJECT(prefswindow->cancel_btn), "released", GTK_SIGNAL_FUNC(cancel_button_released), prefswindow);
+ gtk_signal_connect(GTK_OBJECT(prefswindow->apply_btn), "released", GTK_SIGNAL_FUNC(apply_button_released), prefswindow);
+
+ gtk_widget_show_all(prefswindow->window);
+}
+
+void prefswindow_destroy_all_pages()
+{
+ GSList *cur;
+
+ for (cur = prefs_pages; cur != NULL; cur = g_slist_next(cur)) {
+ PrefsPage *page = (PrefsPage *) cur->data;
+
+ page->destroy_page(page);
+ }
+}
--- /dev/null
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2002 Hiroyuki Yamamoto and the Sylpheed-Claws 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef PREFSWINDOW_H
+#define PREFSWINDOW_H 1
+
+#include <glib.h>
+#include <gtk/gtk.h>
+
+typedef struct _PrefsPage PrefsPage;
+
+typedef void (*PrefsCreateWidgetFunc) (PrefsPage *);
+typedef void (*PrefsDestroyWidgetFunc) (PrefsPage *);
+typedef void (*PrefsSavePageFunc) (PrefsPage *);
+typedef void (*PrefsDestroyPageFunc) (PrefsPage *);
+
+struct _PrefsPage
+{
+ gchar *path;
+ gboolean page_open;
+ GtkWidget *widget;
+
+ PrefsCreateWidgetFunc create_widget;
+ PrefsDestroyWidgetFunc destroy_widget;
+ PrefsSavePageFunc save_page;
+ PrefsDestroyPageFunc destroy_page;
+};
+
+void prefswindow_register_new_page (PrefsPage *);
+void prefswindow_create ();
+void prefswindow_destroy_all_pages ();
+
+#endif
#include "selective_download.h"
#include "ssl_manager.h"
#include "sslcertwindow.h"
+#include "prefswindow.h"
#define AC_LABEL_WIDTH 240
static void account_menu_cb (GtkMenuItem *menuitem,
gpointer data);
+static void prefs_open_cb (GtkMenuItem *menuitem,
+ gpointer data);
+
static void online_switch_clicked(GtkButton *btn,
gpointer data);
NULL, account_edit_open, 0, NULL},
{N_("/_Configuration/C_hange current account"),
NULL, NULL, 0, "<Branch>"},
+ {N_("/_Configuration/---"), NULL, NULL, 0, "<Separator>"},
+ {N_("/_Configuration/Preferences..."), NULL, prefs_open_cb, 0, NULL},
{N_("/_Help"), NULL, NULL, 0, "<Branch>"},
{N_("/_Help/_Manual (Local)"), NULL, manual_open_cb, MANUAL_MANUAL_LOCAL, NULL},
main_window_reflect_prefs_all();
}
+static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
+{
+ prefswindow_create();
+}
+
static void manual_open_cb(MainWindow *mainwin, guint action,
GtkWidget *widget)
{
plugindir = $(pkglibdir)/plugins
-plugin_LTLIBRARIES = spamassassin.la
+plugin_LTLIBRARIES = spamassassin.la spamassassin_gtk.la
spamassassin_la_SOURCES = \
- spamassassin.c \
+ spamassassin.c spamassassin.h \
libspamc.c libspamc.h \
utils.c utils.h
-avoid-version -module \
$(GTK_LIBS)
+spamassassin_gtk_la_SOURCES = \
+ spamassassin_gtk.c spamassassin.h
+
+spamassassin_gtk_la_LDFLAGS = \
+ -avoid-version -module \
+ $(GTK_LIBS)
+
INCLUDES = \
-I../.. \
-I../../common \
EXTRA_DIST = \
README
-
# include "config.h"
#endif
+#include "defs.h"
+
#include <glib.h>
#if HAVE_LOCALE_H
#include "inc.h"
#include "procmsg.h"
#include "folder.h"
+#include "prefs.h"
+#include "prefs_gtk.h"
#include "libspamc.h"
+#include "spamassassin.h"
#ifdef HAVE_SYSEXITS_H
#include <sysexits.h>
#endif
static gint hook_id;
-static int max_size;
static int flags = SPAMC_RAW_MODE | SPAMC_SAFE_FALLBACK | SPAMC_CHECK_ONLY;
-static gchar *hostname = NULL;
-static int port;
+
+gboolean spamassassin_enable;
+gchar *spamassassin_hostname;
+int spamassassin_port;
+int spamassassin_max_size;
+gboolean spamassassin_receive_spam;
+gchar *spamassassin_save_folder;
+
+static PrefParam param[] = {
+ {"enable", "FALSE", &spamassassin_enable, P_BOOL,
+ NULL, NULL, NULL},
+ {"hostname", "localhost", &spamassassin_hostname, P_STRING,
+ NULL, NULL, NULL},
+ {"port", "783", &spamassassin_port, P_USHORT,
+ NULL, NULL, NULL},
+ {"max_size", "250", &spamassassin_max_size, P_USHORT,
+ NULL, NULL, NULL},
+ {"receive_spam", "250", &spamassassin_receive_spam, P_BOOL,
+ NULL, NULL, NULL},
+ {"save_folder", NULL, &spamassassin_save_folder, P_STRING,
+ NULL, NULL, NULL},
+
+ {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
+};
static gboolean mail_filtering_hook(gpointer source, gpointer data)
{
int ret;
gchar *username = NULL, *oldlocale = NULL;
struct sockaddr addr;
-
+
+ if (!spamassassin_enable)
+ return FALSE;
+
debug_print("Filtering message %d\n", msginfo->msgnum);
oldlocale = g_strdup(setlocale(LC_ALL, NULL));
- if (oldlocale == NULL)
+ if (oldlocale == NULL) {
+ debug_print("failed to get locale");
goto CATCH;
+ }
setlocale(LC_ALL, "C");
- ret = lookup_host(hostname, port, &addr);
- if (ret != EX_OK)
+ ret = lookup_host(spamassassin_hostname, spamassassin_port, &addr);
+ if (ret != EX_OK) {
+ debug_print("failed to look up spamd host");
goto CATCH;
+ }
m.type = MESSAGE_NONE;
- m.max_len = max_size;
+ m.max_len = spamassassin_max_size * 1024;
username = g_get_user_name();
- if (username == NULL)
+ if (username == NULL) {
+ debug_print("failed to get username");
goto CATCH;
+ }
fp = procmsg_open_message(msginfo);
- if (fp == NULL)
+ if (fp == NULL) {
+ debug_print("failed to open message file");
goto CATCH;
+ }
ret = message_read(fileno(fp), flags, &m);
- if (ret != EX_OK)
+ if (ret != EX_OK) {
+ debug_print("failed to read message");
goto CATCH;
+ }
ret = message_filter(&addr, username, flags, &m);
if ((ret == EX_OK) && (m.is_spam == EX_ISSPAM))
}
if (is_spam) {
- debug_print("Message is spam\n");
+ if (spamassassin_receive_spam) {
+ FolderItem *save_folder;
+
+ debug_print("message is spam\n");
+
+ if ((!spamassassin_save_folder) ||
+ (spamassassin_save_folder[0] == '\0') ||
+ ((save_folder = folder_find_item_from_identifier(spamassassin_save_folder)) == NULL))
+ save_folder = folder_get_default_trash();
+
+ procmsg_msginfo_unset_flags(msginfo, ~0, 0);
+ folder_item_move_msg(save_folder, msginfo);
+ } else {
+ folder_item_remove_msg(msginfo->folder, msginfo->msgnum);
+ }
- folder_item_move_msg(folder_get_default_trash(), msginfo);
return TRUE;
}
return FALSE;
}
-static void spamassassin_read_config()
+void spamassassin_save_config()
{
- max_size = 250*1024;
- hostname = "127.0.0.1";
- port = 783;
+ PrefFile *pfile;
+ gchar *rcpath;
+
+ debug_print("Saving SpamAssassin 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, "SpamAssassin") < 0))
+ return;
+
+ if (prefs_write_param(param, pfile->fp) < 0) {
+ g_warning("failed to write SpamAssassin configuration to file\n");
+ prefs_file_close_revert(pfile);
+ return;
+ }
+ fprintf(pfile->fp, "\n");
+
+ prefs_file_close(pfile);
}
gint plugin_init(gchar **error)
return -1;
}
- spamassassin_read_config();
+ prefs_set_default(param);
+ prefs_read_config(param, "SpamAssassin", COMMON_RC);
debug_print("Spamassassin plugin loaded\n");
void plugin_done()
{
hooks_unregister_hook(MAIL_FILTERING_HOOKLIST, hook_id);
+ g_free(spamassassin_hostname);
debug_print("Spamassassin plugin unloaded\n");
}
const gchar *plugin_name()
{
- return "Spamassassin Plugin";
+ return "SpamAssassin";
}
const gchar *plugin_desc()
{
- return "Check incoming mails for spam with spamassassin";
+ return "Check incoming mails for spam with SpamAssassin";
}
--- /dev/null
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2002 Hiroyuki Yamamoto and the Sylpheed-Claws 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef SPAMASSASSIN_H
+#define SPAMASSASSIN_H 1
+
+#include <glib.h>
+
+extern gboolean spamassassin_enable;
+extern gchar *spamassassin_hostname;
+extern int spamassassin_port;
+extern int spamassassin_max_size;
+extern gboolean spamassassin_receive_spam;
+extern gchar *spamassassin_save_folder;
+
+void spamassassin_save_config();
+
+#endif
--- /dev/null
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2002 Hiroyuki Yamamoto and the Sylpheed-Claws 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "defs.h"
+
+#include <glib.h>
+#include <gtk/gtk.h>
+
+#include "intl.h"
+#include "plugin.h"
+#include "common/utils.h"
+#include "prefs.h"
+#include "prefswindow.h"
+#include "spamassassin.h"
+
+struct SpamAssassinPage
+{
+ PrefsPage page;
+
+ GtkWidget *enable;
+ GtkWidget *hostname;
+ GtkWidget *port;
+ GtkWidget *max_size;
+ GtkWidget *receive_spam;
+ GtkWidget *save_folder;
+};
+
+static void spamassassin_create_widget_func(PrefsPage * _page)
+{
+ struct SpamAssassinPage *page = (struct SpamAssassinPage *) _page;
+
+ /* ------------------ code made by glade -------------------- */
+ GtkWidget *table1;
+ GtkWidget *label3;
+ GtkWidget *label4;
+ GtkWidget *label6;
+ GtkWidget *label8;
+ GtkWidget *label9;
+ GtkWidget *hbox1;
+ GtkWidget *hostname;
+ GtkWidget *label5;
+ GtkObject *port_adj;
+ GtkWidget *port;
+ GtkWidget *enable;
+ GtkWidget *receive_spam;
+ GtkWidget *label10;
+ GtkObject *max_size_adj;
+ GtkWidget *max_size;
+ GtkWidget *save_folder;
+ GtkWidget *button4;
+ GtkWidget *label11;
+
+ table1 = gtk_table_new(6, 3, FALSE);
+ gtk_widget_show(table1);
+ gtk_container_set_border_width(GTK_CONTAINER(table1), 8);
+ gtk_table_set_row_spacings(GTK_TABLE(table1), 4);
+ gtk_table_set_col_spacings(GTK_TABLE(table1), 8);
+
+ label3 = gtk_label_new(_("Enable SpamAssassin Filtering"));
+ gtk_widget_show(label3);
+ gtk_table_attach(GTK_TABLE(table1), label3, 0, 1, 0, 1,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment(GTK_MISC(label3), 0, 0.5);
+
+ label4 = gtk_label_new(_("SpamAssassin Server (spamd)"));
+ gtk_widget_show(label4);
+ gtk_table_attach(GTK_TABLE(table1), label4, 0, 1, 1, 2,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment(GTK_MISC(label4), 0, 0.5);
+
+ label6 = gtk_label_new(_("Maximum Message Size"));
+ gtk_widget_show(label6);
+ gtk_table_attach(GTK_TABLE(table1), label6, 0, 1, 2, 3,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment(GTK_MISC(label6), 0, 0.5);
+
+ label8 = gtk_label_new(_("Folder for saved Spam"));
+ gtk_widget_show(label8);
+ gtk_table_attach(GTK_TABLE(table1), label8, 0, 1, 4, 5,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_label_set_justify(GTK_LABEL(label8), GTK_JUSTIFY_LEFT);
+ gtk_misc_set_alignment(GTK_MISC(label8), 0, 0.5);
+
+ label9 = gtk_label_new(_("Receive Spam"));
+ gtk_widget_show(label9);
+ gtk_table_attach(GTK_TABLE(table1), label9, 0, 1, 3, 4,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment(GTK_MISC(label9), 0, 0.5);
+
+ hbox1 = gtk_hbox_new(FALSE, 0);
+ gtk_widget_show(hbox1);
+ gtk_table_attach(GTK_TABLE(table1), hbox1, 1, 2, 1, 2,
+ (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+ (GtkAttachOptions) (GTK_FILL), 0, 0);
+
+ hostname = gtk_entry_new();
+ gtk_widget_show(hostname);
+ gtk_box_pack_start(GTK_BOX(hbox1), hostname, TRUE, TRUE, 0);
+
+ label5 = gtk_label_new(_(":"));
+ gtk_widget_show(label5);
+ gtk_box_pack_start(GTK_BOX(hbox1), label5, FALSE, FALSE, 0);
+ gtk_misc_set_padding(GTK_MISC(label5), 8, 0);
+
+ port_adj = gtk_adjustment_new(783, 1, 65535, 1, 10, 10);
+ port =
+ gtk_spin_button_new(GTK_ADJUSTMENT(port_adj), 1, 0);
+ gtk_widget_show(port);
+ gtk_box_pack_start(GTK_BOX(hbox1), port, FALSE, TRUE, 0);
+ gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(port), TRUE);
+
+ enable = gtk_check_button_new_with_label("");
+ gtk_widget_show(enable);
+ gtk_table_attach(GTK_TABLE(table1), enable, 1, 2, 0, 1,
+ (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ receive_spam = gtk_check_button_new_with_label("");
+ gtk_widget_show(receive_spam);
+ gtk_table_attach(GTK_TABLE(table1), receive_spam, 1, 2, 3, 4,
+ (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ label10 =
+ gtk_label_new(_
+ ("Leave empty to use the default trash folder"));
+ gtk_widget_show(label10);
+ gtk_table_attach(GTK_TABLE(table1), label10, 1, 2, 5, 6,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_label_set_justify(GTK_LABEL(label10), GTK_JUSTIFY_RIGHT);
+ gtk_misc_set_alignment(GTK_MISC(label10), 1, 0.5);
+
+ max_size_adj = gtk_adjustment_new(250, 0, 10000, 10, 10, 10);
+ max_size = gtk_spin_button_new(GTK_ADJUSTMENT(max_size_adj), 1, 0);
+ gtk_widget_show(max_size);
+ gtk_table_attach(GTK_TABLE(table1), max_size, 1, 2, 2, 3,
+ (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ save_folder = gtk_entry_new();
+ gtk_widget_show(save_folder);
+ gtk_table_attach(GTK_TABLE(table1), save_folder, 1, 2, 4, 5,
+ (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ button4 = gtk_button_new_with_label(_("..."));
+ gtk_widget_show(button4);
+ gtk_table_attach(GTK_TABLE(table1), button4, 2, 3, 4, 5,
+ (GtkAttachOptions) (GTK_SHRINK | GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ label11 = gtk_label_new(_("kB"));
+ gtk_widget_show(label11);
+ gtk_table_attach(GTK_TABLE(table1), label11, 2, 3, 2, 3,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment(GTK_MISC(label11), 0, 0.5);
+ /* --------------------------------------------------------- */
+
+ gtk_widget_set_sensitive(button4, FALSE);
+
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable), spamassassin_enable);
+ gtk_entry_set_text(GTK_ENTRY(hostname), spamassassin_hostname);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(port), (float) spamassassin_port);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(max_size), (float) spamassassin_max_size);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(receive_spam), spamassassin_receive_spam);
+ gtk_entry_set_text(GTK_ENTRY(save_folder), spamassassin_save_folder);
+
+ page->enable = enable;
+ page->hostname = hostname;
+ page->port = port;
+ page->max_size = max_size;
+ page->receive_spam = receive_spam;
+ page->save_folder = save_folder;
+
+ page->page.widget = table1;
+}
+
+static void spamassassin_destroy_widget_func(PrefsPage *_page)
+{
+ debug_print("Destroying SpamAssassin widget\n");
+}
+
+static void spamassassin_save_func(PrefsPage *_page)
+{
+ struct SpamAssassinPage *page = (struct SpamAssassinPage *) _page;
+ gchar *tmp;
+
+ debug_print("Saving SpamAssassin Page\n");
+
+ spamassassin_enable = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable));
+ if (spamassassin_hostname)
+ g_free(spamassassin_hostname);
+ spamassassin_hostname = gtk_editable_get_chars(GTK_EDITABLE(page->hostname), 0, -1);
+ tmp = gtk_editable_get_chars(GTK_EDITABLE(page->port), 0, -1);
+ spamassassin_port = atoi(tmp);
+ g_free(tmp);
+ spamassassin_max_size = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->max_size));
+ spamassassin_receive_spam = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->receive_spam));
+ if (spamassassin_save_folder)
+ g_free(spamassassin_save_folder);
+ spamassassin_save_folder = gtk_editable_get_chars(GTK_EDITABLE(page->save_folder), 0, -1);
+
+ spamassassin_save_config();
+}
+
+static void spamassassin_destroy_func(PrefsPage *_page)
+{
+ debug_print("Destroying SpamAssassin Page\n");
+ g_free(_page);
+}
+
+gint plugin_init(gchar **error)
+{
+ struct SpamAssassinPage *page;
+
+ page = g_new0(struct SpamAssassinPage, 1);
+ page->page.path = _("Filtering/SpamAssassin");
+ page->page.create_widget = spamassassin_create_widget_func;
+ page->page.destroy_widget = spamassassin_destroy_widget_func;
+ page->page.save_page = spamassassin_save_func;
+ page->page.destroy_page = spamassassin_destroy_func;
+ prefswindow_register_new_page((PrefsPage *) page);
+
+ debug_print("SpamAssassin GTK plugin loaded\n");
+
+ return 0;
+}
+
+void plugin_done()
+{
+ debug_print("SpamAssassin GTK plugin unloaded\n");
+}
+
+const gchar *plugin_name()
+{
+ return "SpamAssassin GTK";
+}
+
+const gchar *plugin_desc()
+{
+ return "";
+}