2007-01-13 [colin] 2.7.0cvs21
[claws.git] / src / plugins / spamassassin / spamassassin_gtk.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail 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/claws.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_seconds_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 SpamAssassin plugin"));
236         gtk_widget_show(enable_sa_checkbtn);
237         gtk_box_pack_start(GTK_BOX(vbox2), enable_sa_checkbtn, TRUE, TRUE, 0);
238
239         vbox_transport = gtkut_get_options_frame(vbox2, &frame_transport, _("Transport"));
240
241         table_transport = gtk_table_new (3, 3, FALSE);
242         gtk_widget_show (table_transport);
243         gtk_box_pack_start(GTK_BOX(vbox_transport), table_transport, TRUE, TRUE, 0);
244         gtk_table_set_row_spacings (GTK_TABLE (table_transport), 4);
245         gtk_table_set_col_spacings (GTK_TABLE (table_transport), 8);
246
247         transport_label = gtk_label_new(_("Type of transport"));
248         gtk_widget_show(transport_label);
249         gtk_table_attach (GTK_TABLE (table_transport), transport_label, 0, 1, 0, 1,
250                         (GtkAttachOptions) (GTK_FILL),
251                         (GtkAttachOptions) (0), 0, 0);
252         gtk_label_set_justify(GTK_LABEL(transport_label), GTK_JUSTIFY_RIGHT);
253         gtk_misc_set_alignment(GTK_MISC(transport_label), 1, 0.5);
254
255         transport_optmenu = gtk_option_menu_new();
256         gtk_widget_show(transport_optmenu);
257
258         gtk_table_attach (GTK_TABLE (table_transport), transport_optmenu, 1, 2, 0, 1,
259                         (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
260                         (GtkAttachOptions) (0), 0, 0);
261         transport_menu = gtk_menu_new();
262
263         user_label = gtk_label_new(_("User"));
264         gtk_widget_show(user_label);
265         gtk_table_attach (GTK_TABLE (table_transport), user_label, 0, 1, 1, 2,
266                         (GtkAttachOptions) (GTK_FILL),
267                         (GtkAttachOptions) (0), 0, 0);
268         gtk_label_set_justify(GTK_LABEL(user_label), GTK_JUSTIFY_RIGHT);
269         gtk_misc_set_alignment(GTK_MISC(user_label), 1, 0.5);
270
271         user_entry = gtk_entry_new();
272         gtk_widget_show(user_entry);
273         gtk_table_attach (GTK_TABLE (table_transport), user_entry, 1, 2, 1, 2,
274                         (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
275                         (GtkAttachOptions) (0), 0, 0);
276         gtk_tooltips_set_tip(tooltips, user_entry, _("User to use with spamd server"),
277                         NULL);
278
279         spamd_label = gtk_label_new(_("spamd"));
280         gtk_widget_show(spamd_label);
281         gtk_table_attach (GTK_TABLE (table_transport), spamd_label, 0, 1, 2, 3,
282                         (GtkAttachOptions) (GTK_FILL),
283                         (GtkAttachOptions) (0), 0, 0);
284         gtk_label_set_justify(GTK_LABEL(spamd_label), GTK_JUSTIFY_RIGHT);
285         gtk_misc_set_alignment(GTK_MISC(spamd_label), 1, 0.5);
286
287         hbox_spamd = gtk_hbox_new(FALSE, 8);
288         gtk_widget_show(hbox_spamd);
289         gtk_table_attach (GTK_TABLE (table_transport), hbox_spamd, 1, 2, 2, 3,
290                         (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
291                         (GtkAttachOptions) (0), 0, 0);
292
293         spamd_hostname_entry = gtk_entry_new();
294         gtk_widget_show(spamd_hostname_entry);
295         gtk_box_pack_start(GTK_BOX(hbox_spamd), spamd_hostname_entry, TRUE, TRUE, 0);
296         gtk_tooltips_set_tip(tooltips, spamd_hostname_entry,
297                         _("Hostname or IP address of spamd server"), NULL);
298
299         spamd_colon_label = gtk_label_new(":");
300         gtk_widget_show(spamd_colon_label);
301         gtk_box_pack_start(GTK_BOX(hbox_spamd), spamd_colon_label, FALSE, FALSE, 0);
302
303         spamd_port_spinbtn_adj = gtk_adjustment_new(783, 1, 65535, 1, 10, 10);
304         spamd_port_spinbtn = gtk_spin_button_new(GTK_ADJUSTMENT(spamd_port_spinbtn_adj), 1, 0);
305         gtk_widget_show(spamd_port_spinbtn);
306         gtk_box_pack_start(GTK_BOX(hbox_spamd), spamd_port_spinbtn, FALSE, FALSE, 0);
307         gtk_tooltips_set_tip(tooltips, spamd_port_spinbtn,
308                         _("Port of spamd server"), NULL);
309         gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(spamd_port_spinbtn), TRUE);
310
311         spamd_socket_entry = gtk_entry_new();
312         gtk_widget_show(spamd_socket_entry);
313         gtk_box_pack_start(GTK_BOX(hbox_spamd), spamd_socket_entry, TRUE, TRUE, 0);
314         gtk_tooltips_set_tip(tooltips, spamd_socket_entry, _("Path of Unix socket"),
315                         NULL);
316
317         hbox_max_size = gtk_hbox_new(FALSE, 8);
318         gtk_widget_show(hbox_max_size);
319         gtk_box_pack_start (GTK_BOX (vbox2), hbox_max_size, TRUE, TRUE, 0);
320
321         max_size_label = gtk_label_new(_("Maximum size"));
322         gtk_widget_show(max_size_label);
323         gtk_box_pack_start(GTK_BOX(hbox_max_size), max_size_label, FALSE, FALSE, 0);
324
325         max_size_spinbtn_adj = gtk_adjustment_new(250, 0, 10000, 10, 10, 10);
326         max_size_spinbtn = gtk_spin_button_new(GTK_ADJUSTMENT(max_size_spinbtn_adj), 1, 0);
327         gtk_widget_show(max_size_spinbtn);
328         gtk_box_pack_start(GTK_BOX(hbox_max_size), max_size_spinbtn, FALSE, FALSE, 0);
329         gtk_tooltips_set_tip(tooltips, max_size_spinbtn,
330                         _("Messages larger than this will not be checked"), NULL);
331         gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(max_size_spinbtn), TRUE);
332
333         max_size_kb_label = gtk_label_new(_("kB"));
334         gtk_widget_show(max_size_kb_label);
335         gtk_box_pack_start(GTK_BOX(hbox_max_size), max_size_kb_label, FALSE, FALSE, 0);
336
337         hbox_timeout = gtk_hbox_new(FALSE, 8);
338         gtk_widget_show(hbox_timeout);
339         gtk_box_pack_start (GTK_BOX (vbox2), hbox_timeout, TRUE, TRUE, 0);
340
341         timeout_label = gtk_label_new(_("Timeout"));
342         gtk_widget_show(timeout_label);
343         gtk_box_pack_start(GTK_BOX(hbox_timeout), timeout_label, FALSE, FALSE, 0);
344
345         timeout_spinbtn_adj = gtk_adjustment_new(60, 0, 10000, 10, 10, 10);
346         timeout_spinbtn = gtk_spin_button_new(GTK_ADJUSTMENT(timeout_spinbtn_adj), 1, 0);
347         gtk_widget_show(timeout_spinbtn);
348         gtk_box_pack_start(GTK_BOX(hbox_timeout), timeout_spinbtn, FALSE, FALSE, 0);
349         gtk_tooltips_set_tip(tooltips, timeout_spinbtn,
350                         _("Maximum time allowed for checking. If the check takes longer "
351                                 "it will be aborted."),
352                         NULL);
353         gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(timeout_spinbtn), TRUE);
354
355         timeout_seconds_label = gtk_label_new(_("seconds"));
356         gtk_widget_show(timeout_seconds_label);
357         gtk_box_pack_start(GTK_BOX(hbox_timeout), timeout_seconds_label, FALSE, FALSE, 0);
358
359         hbox_process_emails = gtk_hbox_new(FALSE, 8);
360         gtk_widget_show(hbox_process_emails);
361         gtk_box_pack_start (GTK_BOX (vbox2), hbox_process_emails, TRUE, TRUE, 0);
362
363         process_emails_checkbtn = gtk_check_button_new_with_label(
364                         _("Process messages on receiving"));
365         gtk_widget_show(process_emails_checkbtn);
366         gtk_box_pack_start(GTK_BOX(hbox_process_emails), process_emails_checkbtn, TRUE, TRUE, 0);
367
368         hbox_save_spam = gtk_hbox_new(FALSE, 8);
369         gtk_widget_show(hbox_save_spam);
370         gtk_box_pack_start (GTK_BOX (vbox2), hbox_save_spam, TRUE, TRUE, 0);
371
372         save_spam_checkbtn = gtk_check_button_new_with_label(_("Save spam in"));
373         gtk_widget_show(save_spam_checkbtn);
374         gtk_box_pack_start(GTK_BOX(hbox_save_spam), save_spam_checkbtn, FALSE, FALSE, 0);
375
376         save_spam_folder_entry = gtk_entry_new();
377         gtk_widget_show (save_spam_folder_entry);
378         gtk_box_pack_start (GTK_BOX (hbox_save_spam), save_spam_folder_entry, TRUE, TRUE, 0);
379         gtk_tooltips_set_tip(tooltips, save_spam_folder_entry,
380                         _("Folder for storing identified spam. Leave empty to use the default trash folder"),
381                         NULL);
382
383         save_spam_folder_select = gtkut_get_browse_directory_btn(_("_Browse"));
384         gtk_widget_show (save_spam_folder_select);
385         gtk_box_pack_start (GTK_BOX (hbox_save_spam), save_spam_folder_select, FALSE, FALSE, 0);
386         gtk_tooltips_set_tip(tooltips, save_spam_folder_select,
387                         _("Click this button to select a folder for storing spam"),
388                         NULL);
389
390         SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn, frame_transport);
391         SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn, hbox_max_size);
392         SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn, hbox_timeout);
393         SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn, hbox_save_spam);
394         SET_TOGGLE_SENSITIVITY(save_spam_checkbtn, save_spam_folder_entry);
395         SET_TOGGLE_SENSITIVITY(save_spam_checkbtn, save_spam_folder_select);
396         SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn, hbox_process_emails);
397
398         config = spamassassin_get_config();
399
400         g_signal_connect(G_OBJECT(save_spam_folder_select), "clicked",
401                         G_CALLBACK(foldersel_cb), page);
402
403         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_sa_checkbtn), config->enable);
404         if (config->username != NULL)
405                 gtk_entry_set_text(GTK_ENTRY(user_entry), config->username);
406         if (config->hostname != NULL)
407                 gtk_entry_set_text(GTK_ENTRY(spamd_hostname_entry), config->hostname);
408         if (config->socket != NULL)
409                 gtk_entry_set_text(GTK_ENTRY(spamd_socket_entry), config->socket);
410         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spamd_port_spinbtn), (float) config->port);
411         gtk_spin_button_set_value(GTK_SPIN_BUTTON(max_size_spinbtn), (float) config->max_size);
412         gtk_spin_button_set_value(GTK_SPIN_BUTTON(timeout_spinbtn), (float) config->timeout);
413         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(process_emails_checkbtn), config->process_emails);
414         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(save_spam_checkbtn), config->receive_spam);
415         if (config->save_folder != NULL)
416                 gtk_entry_set_text(GTK_ENTRY(save_spam_folder_entry), config->save_folder);
417
418         page->enable_sa_checkbtn = enable_sa_checkbtn;
419         page->transport_label = transport_label;
420         page->transport_optmenu = transport_optmenu;
421         page->username = user_entry;
422         page->hostname = spamd_hostname_entry;
423         page->colon = spamd_colon_label;
424         page->port = spamd_port_spinbtn;
425         page->socket = spamd_socket_entry;
426         page->max_size = max_size_spinbtn;
427         page->timeout = timeout_spinbtn;
428         page->process_emails = process_emails_checkbtn;
429         page->receive_spam = save_spam_checkbtn;
430         page->save_folder = save_spam_folder_entry;
431         page->save_folder_select = save_spam_folder_select;
432
433         active = 0;
434         for (i = 0; i < (sizeof(transports) / sizeof(struct Transport)); i++) {
435                 GtkWidget *menuitem;
436
437                 menuitem = gtk_menu_item_new_with_label(gettext(transports[i].name));
438                 g_object_set_data(G_OBJECT(menuitem), MENU_VAL_ID, &transports[i]);
439                 g_signal_connect(G_OBJECT(menuitem), "activate",
440                                 G_CALLBACK(transport_sel_cb), page);
441                 gtk_widget_show(menuitem);
442                 gtk_menu_append(GTK_MENU(transport_menu), menuitem);
443
444                 if (config->transport == transports[i].transport) {
445                         show_transport(page, &transports[i]);
446                         active = i;
447                 } else if (config->transport == SPAMASSASSIN_DISABLED 
448                         && transports[i].transport == SPAMASSASSIN_TRANSPORT_LOCALHOST) {
449                         show_transport(page, &transports[i]);
450                         active = i;
451                         /* and disable via new way */
452                         config->enable = FALSE;
453                         gtk_toggle_button_set_active(
454                                 GTK_TOGGLE_BUTTON(enable_sa_checkbtn), 
455                                 config->enable);
456                 }
457         }
458         gtk_option_menu_set_menu(GTK_OPTION_MENU(transport_optmenu), transport_menu);
459         gtk_option_menu_set_history(GTK_OPTION_MENU(transport_optmenu), active);
460
461         page->page.widget = vbox1;
462 }
463
464 static void spamassassin_destroy_widget_func(PrefsPage *_page)
465 {
466         debug_print("Destroying SpamAssassin widget\n");
467 }
468
469 static void spamassassin_save_func(PrefsPage *_page)
470 {
471         struct SpamAssassinPage *page = (struct SpamAssassinPage *) _page;
472         SpamAssassinConfig *config;
473
474         debug_print("Saving SpamAssassin Page\n");
475
476         config = spamassassin_get_config();
477
478         /* enable */
479         config->enable = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_sa_checkbtn));
480         config->transport = page->trans;
481
482         /* username */
483         g_free(config->username);
484         config->username = gtk_editable_get_chars(GTK_EDITABLE(page->username), 0, -1);
485         spamassassin_check_username();
486
487         /* hostname */
488         g_free(config->hostname);
489         config->hostname = gtk_editable_get_chars(GTK_EDITABLE(page->hostname), 0, -1);
490
491         /* port */
492         config->port = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->port));
493
494         /* hostname */
495         g_free(config->socket);
496         config->socket = gtk_editable_get_chars(GTK_EDITABLE(page->socket), 0, -1);
497
498         /* process_emails */
499         config->process_emails = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->process_emails));
500
501         /* receive_spam */
502         config->receive_spam = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->receive_spam));
503
504         /* save_folder */
505         g_free(config->save_folder);
506         config->save_folder = gtk_editable_get_chars(GTK_EDITABLE(page->save_folder), 0, -1);
507
508         /* max_size */
509         config->max_size = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->max_size));
510
511         /* timeout */
512         config->timeout = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->timeout));
513
514         if (config->process_emails) {
515                 spamassassin_register_hook();
516         } else {
517                 spamassassin_unregister_hook();
518         }
519
520         if (!config->enable) {
521                 procmsg_unregister_spam_learner(spamassassin_learn);
522                 procmsg_spam_set_folder(NULL);
523         } else {
524                 if (config->transport == SPAMASSASSIN_TRANSPORT_TCP)
525                         debug_print("enabling learner with a remote spamassassin server requires spamc/spamd 3.1.x\n");
526                 procmsg_register_spam_learner(spamassassin_learn);
527                 procmsg_spam_set_folder(config->save_folder);
528         }
529
530         spamassassin_save_config();
531 }
532
533 static void gtk_message_callback(gchar *message)
534 {
535         statusbar_print_all(message);
536 }
537
538 static struct SpamAssassinPage spamassassin_page;
539
540 gint spamassassin_gtk_init(void)
541 {
542         static gchar *path[3];
543
544         path[0] = _("Plugins");
545         path[1] = _("SpamAssassin");
546         path[2] = NULL;
547
548         spamassassin_page.page.path = path;
549         spamassassin_page.page.create_widget = spamassassin_create_widget_func;
550         spamassassin_page.page.destroy_widget = spamassassin_destroy_widget_func;
551         spamassassin_page.page.save_page = spamassassin_save_func;
552         spamassassin_page.page.weight = 35.0;
553
554         prefs_gtk_register_page((PrefsPage *) &spamassassin_page);
555         spamassassin_set_message_callback(gtk_message_callback);
556
557         debug_print("SpamAssassin GTK plugin loaded\n");
558         return 0;       
559 }
560
561 void spamassassin_gtk_done(void)
562 {
563         prefs_gtk_unregister_page((PrefsPage *) &spamassassin_page);
564 }