512a85ae281ff2f218f4b54c7036ab32d02299fb
[claws.git] / src / plugins / spamassassin / spamassassin_gtk.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws Team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <glib.h>
27 #include <glib/gi18n.h>
28 #include <gtk/gtk.h>
29 #include <gtk/gtkutils.h>
30
31 #include "common/sylpheed.h"
32 #include "common/version.h"
33 #include "plugin.h"
34 #include "common/utils.h"
35 #include "prefs.h"
36 #include "folder.h"
37 #include "prefs_gtk.h"
38 #include "foldersel.h"
39 #include "spamassassin.h"
40 #include "statusbar.h"
41 #include "menu.h"
42
43 struct SpamAssassinPage
44 {
45         PrefsPage page;
46
47         GtkWidget *enable_sa_checkbtn;
48         GtkWidget *transport_optmenu;
49         GtkWidget *transport_label;
50         GtkWidget *username;
51         GtkWidget *hostname;
52         GtkWidget *colon;
53         GtkWidget *port;
54         GtkWidget *socket;
55         GtkWidget *process_emails;
56         GtkWidget *receive_spam;
57         GtkWidget *save_folder;
58         GtkWidget *save_folder_select;
59         GtkWidget *max_size;
60         GtkWidget *timeout;
61
62         SpamAssassinTransport   trans;
63 };
64
65 struct Transport
66 {
67         gchar                   *name;
68         SpamAssassinTransport    transport;
69         guint                    page;
70         guint                    pageflags;
71 };
72
73 enum {
74         PAGE_DISABLED = 0,
75         PAGE_NETWORK  = 1,
76         PAGE_UNIX     = 2,
77 };
78
79 enum {
80         NETWORK_HOSTNAME = 1,
81 };
82
83 struct Transport transports[] = {
84         /*{ N_("Disabled"),     SPAMASSASSIN_DISABLED,                  PAGE_DISABLED, 0 },*/
85         { N_("Localhost"),      SPAMASSASSIN_TRANSPORT_LOCALHOST,       PAGE_NETWORK, 0 },
86         { N_("TCP"),            SPAMASSASSIN_TRANSPORT_TCP,             PAGE_NETWORK, NETWORK_HOSTNAME },
87         { N_("Unix Socket"),    SPAMASSASSIN_TRANSPORT_UNIX,            PAGE_UNIX,    0 },
88 };
89
90 static void foldersel_cb(GtkWidget *widget, gpointer data)
91 {
92         struct SpamAssassinPage *page = (struct SpamAssassinPage *) data;
93         FolderItem *item;
94         gchar *item_id;
95         gint newpos = 0;
96         
97         item = foldersel_folder_sel(NULL, FOLDER_SEL_MOVE, NULL);
98         if (item && (item_id = folder_item_get_identifier(item)) != NULL) {
99                 gtk_editable_delete_text(GTK_EDITABLE(page->save_folder), 0, -1);
100                 gtk_editable_insert_text(GTK_EDITABLE(page->save_folder), item_id, strlen(item_id), &newpos);
101                 g_free(item_id);
102         }
103 }
104
105 static void show_transport(struct SpamAssassinPage *page, struct Transport *transport)
106 {
107         page->trans = transport->transport;
108
109         switch (transport->page) {
110                 /*
111         case PAGE_DISABLED:
112                 gtk_widget_show(page->hostname);
113                 gtk_widget_show(page->colon);
114                 gtk_widget_show(page->port);
115                 gtk_widget_hide(page->socket);
116                 gtk_widget_set_sensitive(page->username, FALSE);
117                 gtk_widget_set_sensitive(page->hostname, FALSE);
118                 gtk_widget_set_sensitive(page->colon, FALSE);
119                 gtk_widget_set_sensitive(page->port, FALSE);
120                 gtk_widget_set_sensitive(page->max_size, FALSE);
121                 gtk_widget_set_sensitive(page->timeout, FALSE);
122                 gtk_widget_set_sensitive(page->process_emails, FALSE);
123                 gtk_widget_set_sensitive(page->receive_spam, FALSE);
124                 gtk_widget_set_sensitive(page->save_folder, FALSE);
125                 gtk_widget_set_sensitive(page->save_folder_select, FALSE);
126                 break;
127                 */
128         case PAGE_UNIX:
129                 gtk_widget_hide(page->hostname);
130                 gtk_widget_hide(page->colon);
131                 gtk_widget_hide(page->port);
132                 gtk_widget_show(page->socket);
133                 gtk_widget_set_sensitive(page->username, TRUE);
134                 gtk_widget_set_sensitive(page->socket, TRUE);
135                 gtk_widget_set_sensitive(page->max_size, TRUE);
136                 gtk_widget_set_sensitive(page->timeout, TRUE);
137                 gtk_widget_set_sensitive(page->process_emails, TRUE);
138                 gtk_widget_set_sensitive(page->receive_spam, TRUE);
139                 gtk_widget_set_sensitive(page->save_folder, TRUE);
140                 gtk_widget_set_sensitive(page->save_folder_select, TRUE);
141                 break;
142         case PAGE_NETWORK:
143                 gtk_widget_show(page->hostname);
144                 gtk_widget_show(page->colon);
145                 gtk_widget_show(page->port);
146                 gtk_widget_hide(page->socket);
147                 gtk_widget_set_sensitive(page->username, TRUE);
148                 gtk_widget_set_sensitive(page->max_size, TRUE);
149                 gtk_widget_set_sensitive(page->timeout, TRUE);
150                 gtk_widget_set_sensitive(page->process_emails, TRUE);
151                 gtk_widget_set_sensitive(page->receive_spam, TRUE);
152                 gtk_widget_set_sensitive(page->save_folder, TRUE);
153                 gtk_widget_set_sensitive(page->save_folder_select, TRUE);
154                 if (transport->pageflags & NETWORK_HOSTNAME) {
155                         gtk_widget_set_sensitive(page->hostname, TRUE);
156                         gtk_widget_set_sensitive(page->colon, TRUE);
157                         gtk_widget_set_sensitive(page->port, TRUE);
158                 } else {
159                         gtk_widget_set_sensitive(page->hostname, FALSE);
160                         gtk_widget_set_sensitive(page->colon, FALSE);
161                         gtk_widget_set_sensitive(page->port, TRUE);
162                 }
163                 break;
164         default:
165                 break;
166         }
167 }
168
169 static void transport_sel_cb(GtkMenuItem *menuitem, gpointer data)
170 {
171         struct SpamAssassinPage *page = (struct SpamAssassinPage *) data;
172         struct Transport *transport;
173
174         transport = (struct Transport *) g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID);
175         show_transport(page, transport);
176 }
177
178 static void spamassassin_create_widget_func(PrefsPage * _page,
179                                             GtkWindow * window,
180                                             gpointer data)
181 {
182         struct SpamAssassinPage *page = (struct SpamAssassinPage *) _page;
183         SpamAssassinConfig *config;
184         guint i, active;
185
186         GtkWidget *vbox1, *vbox2;
187         GtkWidget *frame_transport, *table_transport, *vbox_transport;
188         GtkWidget *hbox_spamd, *hbox_max_size, *hbox_timeout;
189         GtkWidget *hbox_process_emails, *hbox_save_spam;
190
191         GtkWidget *enable_sa_checkbtn;
192
193         GtkWidget *transport_label;
194         GtkWidget *transport_optmenu;
195         GtkWidget *transport_menu;
196
197         GtkWidget *user_label;
198         GtkWidget *user_entry;
199
200         GtkWidget *spamd_label;
201         GtkWidget *spamd_hostname_entry;
202         GtkWidget *spamd_colon_label;
203         GtkObject *spamd_port_spinbtn_adj;
204         GtkWidget *spamd_port_spinbtn;
205         GtkWidget *spamd_socket_entry;
206
207         GtkWidget *max_size_label;
208         GtkObject *max_size_spinbtn_adj;
209         GtkWidget *max_size_spinbtn;
210         GtkWidget *max_size_kb_label;
211
212         GtkWidget *timeout_label;
213         GtkObject *timeout_spinbtn_adj;
214         GtkWidget *timeout_spinbtn;
215         GtkWidget *timeout_secondes_label;
216
217         GtkWidget *process_emails_checkbtn;
218
219         GtkWidget *save_spam_checkbtn;
220         GtkWidget *save_spam_folder_entry;
221         GtkWidget *save_spam_folder_select;
222
223         GtkTooltips *tooltips;
224
225         tooltips = gtk_tooltips_new();
226
227         vbox1 = gtk_vbox_new (FALSE, VSPACING);
228         gtk_widget_show (vbox1);
229         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
230
231         vbox2 = gtk_vbox_new (FALSE, 4);
232         gtk_widget_show (vbox2);
233         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
234
235         enable_sa_checkbtn = gtk_check_button_new_with_label(_("Enable spam scanning"));
236         gtk_widget_show(enable_sa_checkbtn);
237         gtk_box_pack_start(GTK_BOX(vbox2), enable_sa_checkbtn, TRUE, TRUE, 0);
238         gtk_tooltips_set_tip(tooltips, enable_sa_checkbtn,
239                         _("Enable spam scanning on message(s) receiving"), NULL);
240         /* FIXME : english should be better renamed  */
241
242         /* FIXME : 'Transport' frame : english should ? be better renamed */
243         PACK_FRAME(vbox2, frame_transport, _("Transport"));
244         vbox_transport = gtk_vbox_new (FALSE, VSPACING_NARROW);
245         gtk_widget_show (vbox_transport);
246         gtk_container_add (GTK_CONTAINER (frame_transport), vbox_transport);
247         gtk_container_set_border_width (GTK_CONTAINER (vbox_transport), 8);
248
249         table_transport = gtk_table_new (3, 3, FALSE);
250         gtk_widget_show (table_transport);
251         gtk_box_pack_start(GTK_BOX(vbox_transport), table_transport, TRUE, TRUE, 0);
252         gtk_table_set_row_spacings (GTK_TABLE (table_transport), 4);
253         gtk_table_set_col_spacings (GTK_TABLE (table_transport), 8);
254
255         /* FIXME : 'Type of transport' : english should be better renamed */
256         transport_label = gtk_label_new(_("Type of transport"));
257         gtk_widget_show(transport_label);
258         gtk_table_attach (GTK_TABLE (table_transport), transport_label, 0, 1, 0, 1,
259                         (GtkAttachOptions) (GTK_FILL),
260                         (GtkAttachOptions) (0), 0, 0);
261         gtk_label_set_justify(GTK_LABEL(transport_label), GTK_JUSTIFY_RIGHT);
262         gtk_misc_set_alignment(GTK_MISC(transport_label), 1, 0.5);
263
264         transport_optmenu = gtk_option_menu_new();
265         gtk_widget_show(transport_optmenu);
266
267         gtk_table_attach (GTK_TABLE (table_transport), transport_optmenu, 1, 2, 0, 1,
268                         (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
269                         (GtkAttachOptions) (0), 0, 0);
270         transport_menu = gtk_menu_new();
271
272         user_label = gtk_label_new(_("User"));
273         gtk_widget_show(user_label);
274         gtk_table_attach (GTK_TABLE (table_transport), user_label, 0, 1, 1, 2,
275                         (GtkAttachOptions) (GTK_FILL),
276                         (GtkAttachOptions) (0), 0, 0);
277         gtk_label_set_justify(GTK_LABEL(user_label), GTK_JUSTIFY_RIGHT);
278         gtk_misc_set_alignment(GTK_MISC(user_label), 1, 0.5);
279
280         user_entry = gtk_entry_new();
281         gtk_widget_show(user_entry);
282         gtk_table_attach (GTK_TABLE (table_transport), user_entry, 1, 2, 1, 2,
283                         (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
284                         (GtkAttachOptions) (0), 0, 0);
285         gtk_tooltips_set_tip(tooltips, user_entry, _("User to use with spamd server"),
286                         NULL);
287
288         spamd_label = gtk_label_new(_("spamd"));
289         gtk_widget_show(spamd_label);
290         gtk_table_attach (GTK_TABLE (table_transport), spamd_label, 0, 1, 2, 3,
291                         (GtkAttachOptions) (GTK_FILL),
292                         (GtkAttachOptions) (0), 0, 0);
293         gtk_label_set_justify(GTK_LABEL(spamd_label), GTK_JUSTIFY_RIGHT);
294         gtk_misc_set_alignment(GTK_MISC(spamd_label), 1, 0.5);
295
296         hbox_spamd = gtk_hbox_new(FALSE, 8);
297         gtk_widget_show(hbox_spamd);
298         gtk_table_attach (GTK_TABLE (table_transport), hbox_spamd, 1, 2, 2, 3,
299                         (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
300                         (GtkAttachOptions) (0), 0, 0);
301
302         spamd_hostname_entry = gtk_entry_new();
303         gtk_widget_show(spamd_hostname_entry);
304         gtk_box_pack_start(GTK_BOX(hbox_spamd), spamd_hostname_entry, TRUE, TRUE, 0);
305         gtk_tooltips_set_tip(tooltips, spamd_hostname_entry,
306                         _("Hostname or IP address of spamd server"), NULL);
307
308         spamd_colon_label = gtk_label_new(_(":"));
309         gtk_widget_show(spamd_colon_label);
310         gtk_box_pack_start(GTK_BOX(hbox_spamd), spamd_colon_label, FALSE, FALSE, 0);
311
312         spamd_port_spinbtn_adj = gtk_adjustment_new(783, 1, 65535, 1, 10, 10);
313         spamd_port_spinbtn = gtk_spin_button_new(GTK_ADJUSTMENT(spamd_port_spinbtn_adj), 1, 0);
314         gtk_widget_show(spamd_port_spinbtn);
315         gtk_box_pack_start(GTK_BOX(hbox_spamd), spamd_port_spinbtn, FALSE, FALSE, 0);
316         gtk_tooltips_set_tip(tooltips, spamd_port_spinbtn,
317                         _("Port of spamd server"), NULL);
318         gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(spamd_port_spinbtn), TRUE);
319
320         spamd_socket_entry = gtk_entry_new();
321         gtk_widget_show(spamd_socket_entry);
322         gtk_box_pack_start(GTK_BOX(hbox_spamd), spamd_socket_entry, TRUE, TRUE, 0);
323         gtk_tooltips_set_tip(tooltips, spamd_socket_entry, _("Path of Unix socket"),
324                         NULL);
325
326         hbox_max_size = gtk_hbox_new(FALSE, 8);
327         gtk_widget_show(hbox_max_size);
328         gtk_box_pack_start (GTK_BOX (vbox2), hbox_max_size, TRUE, TRUE, 0);
329
330         max_size_label = gtk_label_new(_("Maximum Size"));
331         gtk_widget_show(max_size_label);
332         gtk_box_pack_start(GTK_BOX(hbox_max_size), max_size_label, FALSE, FALSE, 0);
333
334         max_size_spinbtn_adj = gtk_adjustment_new(250, 0, 10000, 10, 10, 10);
335         max_size_spinbtn = gtk_spin_button_new(GTK_ADJUSTMENT(max_size_spinbtn_adj), 1, 0);
336         gtk_widget_show(max_size_spinbtn);
337         gtk_box_pack_start(GTK_BOX(hbox_max_size), max_size_spinbtn, FALSE, FALSE, 0);
338         gtk_tooltips_set_tip(tooltips, max_size_spinbtn,
339                         _("Don't check emails bigger than"), NULL);
340         gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(max_size_spinbtn), TRUE);
341
342         max_size_kb_label = gtk_label_new(_("kB"));
343         gtk_widget_show(max_size_kb_label);
344         gtk_box_pack_start(GTK_BOX(hbox_max_size), max_size_kb_label, FALSE, FALSE, 0);
345
346         hbox_timeout = gtk_hbox_new(FALSE, 8);
347         gtk_widget_show(hbox_timeout);
348         gtk_box_pack_start (GTK_BOX (vbox2), hbox_timeout, TRUE, TRUE, 0);
349
350         timeout_label = gtk_label_new(_("Timeout"));
351         gtk_widget_show(timeout_label);
352         gtk_box_pack_start(GTK_BOX(hbox_timeout), timeout_label, FALSE, FALSE, 0);
353
354         timeout_spinbtn_adj = gtk_adjustment_new(60, 0, 10000, 10, 10, 10);
355         timeout_spinbtn = gtk_spin_button_new(GTK_ADJUSTMENT(timeout_spinbtn_adj), 1, 0);
356         gtk_widget_show(timeout_spinbtn);
357         gtk_box_pack_start(GTK_BOX(hbox_timeout), timeout_spinbtn, FALSE, FALSE, 0);
358         gtk_tooltips_set_tip(tooltips, timeout_spinbtn,
359                         _("Time allowed for checking. If the check takes longer "
360                                 "the check will be aborted and the message will "
361                                 "be handled as not spam."),
362                         NULL);
363         gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(timeout_spinbtn), TRUE);
364
365         timeout_secondes_label = gtk_label_new(_("seconds"));
366         gtk_widget_show(timeout_secondes_label);
367         gtk_box_pack_start(GTK_BOX(hbox_timeout), timeout_secondes_label, FALSE, FALSE, 0);
368
369         hbox_process_emails = gtk_hbox_new(FALSE, 8);
370         gtk_widget_show(hbox_process_emails);
371         gtk_box_pack_start (GTK_BOX (vbox2), hbox_process_emails, TRUE, TRUE, 0);
372
373         process_emails_checkbtn = gtk_check_button_new_with_label(
374                         _("Process messages on receiving"));
375         gtk_widget_show(process_emails_checkbtn);
376         gtk_box_pack_start(GTK_BOX(hbox_process_emails), process_emails_checkbtn, TRUE, TRUE, 0);
377         gtk_tooltips_set_tip(tooltips, process_emails_checkbtn,
378                         _("Process emails upon incorporation"), NULL);
379
380         hbox_save_spam = gtk_hbox_new(FALSE, 8);
381         gtk_widget_show(hbox_save_spam);
382         gtk_box_pack_start (GTK_BOX (vbox2), hbox_save_spam, TRUE, TRUE, 0);
383
384         save_spam_checkbtn = gtk_check_button_new_with_label(_("Save spam in"));
385         gtk_widget_show(save_spam_checkbtn);
386         gtk_box_pack_start(GTK_BOX(hbox_save_spam), save_spam_checkbtn, FALSE, FALSE, 0);
387
388         gtk_tooltips_set_tip(tooltips, save_spam_checkbtn,
389                         _("Save identified spam"), NULL);
390
391         save_spam_folder_entry = gtk_entry_new();
392         gtk_widget_show (save_spam_folder_entry);
393         gtk_box_pack_start (GTK_BOX (hbox_save_spam), save_spam_folder_entry, TRUE, TRUE, 0);
394         gtk_tooltips_set_tip(tooltips, save_spam_folder_entry,
395                         _("Folder for storing identified spam. Leave empty to use the default trash folder"),
396                         NULL);
397
398         save_spam_folder_select = gtkut_get_browse_directory_btn(_("_Browse"));
399         gtk_widget_show (save_spam_folder_select);
400         gtk_box_pack_start (GTK_BOX (hbox_save_spam), save_spam_folder_select, FALSE, FALSE, 0);
401         gtk_tooltips_set_tip(tooltips, save_spam_folder_select,
402                         _("Click this button to select a folder for storing spam"),
403                         NULL);
404
405         SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn, frame_transport);
406         SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn, hbox_max_size);
407         SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn, hbox_timeout);
408         SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn, hbox_save_spam);
409         SET_TOGGLE_SENSITIVITY(save_spam_checkbtn, save_spam_folder_entry);
410         SET_TOGGLE_SENSITIVITY(save_spam_checkbtn, save_spam_folder_select);
411         SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn, hbox_process_emails);
412
413         config = spamassassin_get_config();
414
415         g_signal_connect(G_OBJECT(save_spam_folder_select), "released",
416                         G_CALLBACK(foldersel_cb), page);
417
418         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_sa_checkbtn), config->enable);
419         if (config->username != NULL)
420                 gtk_entry_set_text(GTK_ENTRY(user_entry), config->username);
421         if (config->hostname != NULL)
422                 gtk_entry_set_text(GTK_ENTRY(spamd_hostname_entry), config->hostname);
423         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spamd_port_spinbtn), (float) config->port);
424         gtk_spin_button_set_value(GTK_SPIN_BUTTON(max_size_spinbtn), (float) config->max_size);
425         gtk_spin_button_set_value(GTK_SPIN_BUTTON(timeout_spinbtn), (float) config->timeout);
426         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(process_emails_checkbtn), config->process_emails);
427         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(save_spam_checkbtn), config->receive_spam);
428         if (config->save_folder != NULL)
429                 gtk_entry_set_text(GTK_ENTRY(save_spam_folder_entry), config->save_folder);
430
431         page->enable_sa_checkbtn = enable_sa_checkbtn;
432         page->transport_label = transport_label;
433         page->transport_optmenu = transport_optmenu;
434         page->username = user_entry;
435         page->hostname = spamd_hostname_entry;
436         page->colon = spamd_colon_label;
437         page->port = spamd_port_spinbtn;
438         page->socket = spamd_socket_entry;
439         page->max_size = max_size_spinbtn;
440         page->timeout = timeout_spinbtn;
441         page->process_emails = process_emails_checkbtn;
442         page->receive_spam = save_spam_checkbtn;
443         page->save_folder = save_spam_folder_entry;
444         page->save_folder_select = save_spam_folder_select;
445
446         active = 0;
447         for (i = 0; i < (sizeof(transports) / sizeof(struct Transport)); i++) {
448                 GtkWidget *menuitem;
449
450                 menuitem = gtk_menu_item_new_with_label(gettext(transports[i].name));
451                 g_object_set_data(G_OBJECT(menuitem), MENU_VAL_ID, &transports[i]);
452                 g_signal_connect(G_OBJECT(menuitem), "activate",
453                                 G_CALLBACK(transport_sel_cb), page);
454                 gtk_widget_show(menuitem);
455                 gtk_menu_append(GTK_MENU(transport_menu), menuitem);
456
457                 if (config->transport == transports[i].transport) {
458                         show_transport(page, &transports[i]);
459                         active = i;
460                 }
461         }
462         gtk_option_menu_set_menu(GTK_OPTION_MENU(transport_optmenu), transport_menu);
463         gtk_option_menu_set_history(GTK_OPTION_MENU(transport_optmenu), active);
464
465         page->page.widget = vbox1;
466 }
467
468 static void spamassassin_destroy_widget_func(PrefsPage *_page)
469 {
470         debug_print("Destroying SpamAssassin widget\n");
471 }
472
473 static void spamassassin_save_func(PrefsPage *_page)
474 {
475         struct SpamAssassinPage *page = (struct SpamAssassinPage *) _page;
476         SpamAssassinConfig *config;
477
478         debug_print("Saving SpamAssassin Page\n");
479
480         config = spamassassin_get_config();
481
482         /* enable */
483         config->enable = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_sa_checkbtn));
484         config->transport = page->trans;
485
486         /* username */
487         g_free(config->username);
488         config->username = gtk_editable_get_chars(GTK_EDITABLE(page->username), 0, -1);
489         spamassassin_check_username();
490
491         /* hostname */
492         g_free(config->hostname);
493         config->hostname = gtk_editable_get_chars(GTK_EDITABLE(page->hostname), 0, -1);
494
495         /* port */
496         config->port = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->port));
497
498         /* hostname */
499         g_free(config->socket);
500         config->socket = gtk_editable_get_chars(GTK_EDITABLE(page->socket), 0, -1);
501
502         /* process_emails */
503         config->process_emails = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->process_emails));
504
505         /* receive_spam */
506         config->receive_spam = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->receive_spam));
507
508         /* save_folder */
509         g_free(config->save_folder);
510         config->save_folder = gtk_editable_get_chars(GTK_EDITABLE(page->save_folder), 0, -1);
511
512         /* max_size */
513         config->max_size = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->max_size));
514
515         /* timeout */
516         config->timeout = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->timeout));
517
518         if (config->process_emails) {
519                 spamassassin_register_hook();
520         } else {
521                 spamassassin_unregister_hook();
522         }
523
524         if (!config->enable) {
525                 procmsg_unregister_spam_learner(spamassassin_learn);
526                 procmsg_spam_set_folder(NULL);
527         } else {
528                 if (config->transport == SPAMASSASSIN_TRANSPORT_TCP)
529                         debug_print("enabling learner with a remote spamassassin server requires spamc/spamd 3.1.x\n");
530                 procmsg_register_spam_learner(spamassassin_learn);
531                 procmsg_spam_set_folder(config->save_folder);
532         }
533
534         spamassassin_save_config();
535 }
536
537 static void gtk_message_callback(gchar *message)
538 {
539         statusbar_print_all(message);
540 }
541
542 static struct SpamAssassinPage spamassassin_page;
543
544 gint spamassassin_gtk_init(void)
545 {
546         static gchar *path[3];
547
548         path[0] = _("Plugins");
549         path[1] = _("SpamAssassin");
550         path[2] = NULL;
551
552         spamassassin_page.page.path = path;
553         spamassassin_page.page.create_widget = spamassassin_create_widget_func;
554         spamassassin_page.page.destroy_widget = spamassassin_destroy_widget_func;
555         spamassassin_page.page.save_page = spamassassin_save_func;
556         spamassassin_page.page.weight = 35.0;
557
558         prefs_gtk_register_page((PrefsPage *) &spamassassin_page);
559         spamassassin_set_message_callback(gtk_message_callback);
560
561         debug_print("SpamAssassin GTK plugin loaded\n");
562         return 0;       
563 }
564
565 void spamassassin_gtk_done(void)
566 {
567         prefs_gtk_unregister_page((PrefsPage *) &spamassassin_page);
568 }