44523075b02d15cebf5e746fc1c01657fc97c87b
[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 *transport;
48 /*      GtkWidget *transport_notebook;*/
49         GtkWidget *username;
50         GtkWidget *hostname;
51         GtkWidget *label2;
52         GtkWidget *label3;
53         GtkWidget *label4;
54         GtkWidget *label5;
55         GtkWidget *label6;
56         GtkWidget *label7;
57         GtkWidget *colon;
58         GtkWidget *port;
59         GtkWidget *socket;
60         GtkWidget *process_emails;
61         GtkWidget *receive_spam;
62         GtkWidget *save_folder;
63         GtkWidget *save_folder_select;
64         GtkWidget *max_size;
65         GtkWidget *timeout;
66
67         SpamAssassinTransport   trans;
68 };
69
70 struct Transport
71 {
72         gchar                   *name;
73         SpamAssassinTransport    transport;
74         guint                    page;
75         guint                    pageflags;
76 };
77
78 enum {
79         PAGE_DISABLED = 0,
80         PAGE_NETWORK  = 1,
81         PAGE_UNIX     = 2,
82 };
83
84 enum {
85         NETWORK_HOSTNAME = 1,
86 };
87
88 struct Transport transports[] = {
89         { N_("Disabled"),       SPAMASSASSIN_DISABLED,                  PAGE_DISABLED, 0 },
90         { N_("Localhost"),      SPAMASSASSIN_TRANSPORT_LOCALHOST,       PAGE_NETWORK, 0 },
91         { N_("TCP"),            SPAMASSASSIN_TRANSPORT_TCP,             PAGE_NETWORK, NETWORK_HOSTNAME },
92         { N_("Unix Socket"),    SPAMASSASSIN_TRANSPORT_UNIX,            PAGE_UNIX,    0 },
93 };
94
95 static void foldersel_cb(GtkWidget *widget, gpointer data)
96 {
97         struct SpamAssassinPage *page = (struct SpamAssassinPage *) data;
98         FolderItem *item;
99         gchar *item_id;
100         gint newpos = 0;
101         
102         item = foldersel_folder_sel(NULL, FOLDER_SEL_MOVE, NULL);
103         if (item && (item_id = folder_item_get_identifier(item)) != NULL) {
104                 gtk_editable_delete_text(GTK_EDITABLE(page->save_folder), 0, -1);
105                 gtk_editable_insert_text(GTK_EDITABLE(page->save_folder), item_id, strlen(item_id), &newpos);
106                 g_free(item_id);
107         }
108 }
109
110 static void show_transport(struct SpamAssassinPage *page, struct Transport *transport)
111 {
112         page->trans = transport->transport;
113
114         switch (transport->page) {
115         case PAGE_DISABLED:
116                 gtk_widget_show(page->hostname);
117                 gtk_widget_show(page->colon);
118                 gtk_widget_show(page->port);
119                 gtk_widget_hide(page->socket);
120                 gtk_widget_set_sensitive(page->label2, FALSE);
121                 gtk_widget_set_sensitive(page->label3, FALSE);
122                 gtk_widget_set_sensitive(page->label4, FALSE);
123                 gtk_widget_set_sensitive(page->label5, FALSE);
124                 gtk_widget_set_sensitive(page->label6, FALSE);
125                 gtk_widget_set_sensitive(page->label7, FALSE);
126                 gtk_widget_set_sensitive(page->username, FALSE);
127                 gtk_widget_set_sensitive(page->hostname, FALSE);
128                 gtk_widget_set_sensitive(page->colon, FALSE);
129                 gtk_widget_set_sensitive(page->port, FALSE);
130                 gtk_widget_set_sensitive(page->max_size, FALSE);
131                 gtk_widget_set_sensitive(page->timeout, FALSE);
132                 gtk_widget_set_sensitive(page->process_emails, FALSE);
133                 gtk_widget_set_sensitive(page->receive_spam, FALSE);
134                 gtk_widget_set_sensitive(page->save_folder, FALSE);
135                 gtk_widget_set_sensitive(page->save_folder_select, FALSE);
136                 break;
137         case PAGE_UNIX:
138                 gtk_widget_hide(page->hostname);
139                 gtk_widget_hide(page->colon);
140                 gtk_widget_hide(page->port);
141                 gtk_widget_show(page->socket);
142                 gtk_widget_set_sensitive(page->label2, TRUE);
143                 gtk_widget_set_sensitive(page->label3, TRUE);
144                 gtk_widget_set_sensitive(page->label4, TRUE);
145                 gtk_widget_set_sensitive(page->label5, TRUE);
146                 gtk_widget_set_sensitive(page->label6, TRUE);
147                 gtk_widget_set_sensitive(page->label7, TRUE);
148                 gtk_widget_set_sensitive(page->username, TRUE);
149                 gtk_widget_set_sensitive(page->socket, TRUE);
150                 gtk_widget_set_sensitive(page->max_size, TRUE);
151                 gtk_widget_set_sensitive(page->timeout, TRUE);
152                 gtk_widget_set_sensitive(page->process_emails, TRUE);
153                 gtk_widget_set_sensitive(page->receive_spam, TRUE);
154                 gtk_widget_set_sensitive(page->save_folder, TRUE);
155                 gtk_widget_set_sensitive(page->save_folder_select, TRUE);
156                 break;
157         case PAGE_NETWORK:
158                 gtk_widget_show(page->hostname);
159                 gtk_widget_show(page->colon);
160                 gtk_widget_show(page->port);
161                 gtk_widget_hide(page->socket);
162                 gtk_widget_set_sensitive(page->label2, TRUE);
163                 gtk_widget_set_sensitive(page->label3, TRUE);
164                 gtk_widget_set_sensitive(page->label4, TRUE);
165                 gtk_widget_set_sensitive(page->label5, TRUE);
166                 gtk_widget_set_sensitive(page->label6, TRUE);
167                 gtk_widget_set_sensitive(page->label7, TRUE);
168                 gtk_widget_set_sensitive(page->username, TRUE);
169                 gtk_widget_set_sensitive(page->max_size, TRUE);
170                 gtk_widget_set_sensitive(page->timeout, TRUE);
171                 gtk_widget_set_sensitive(page->process_emails, TRUE);
172                 gtk_widget_set_sensitive(page->receive_spam, TRUE);
173                 gtk_widget_set_sensitive(page->save_folder, TRUE);
174                 gtk_widget_set_sensitive(page->save_folder_select, TRUE);
175                 if (transport->pageflags & NETWORK_HOSTNAME) {
176                         gtk_widget_set_sensitive(page->hostname, TRUE);
177                         gtk_widget_set_sensitive(page->colon, TRUE);
178                         gtk_widget_set_sensitive(page->port, TRUE);
179                 } else {
180                         gtk_widget_set_sensitive(page->hostname, FALSE);
181                         gtk_widget_set_sensitive(page->colon, FALSE);
182                         gtk_widget_set_sensitive(page->port, TRUE);
183                 }
184                 break;
185         default:
186                 break;
187         }
188 /*      gtk_notebook_set_current_page(GTK_NOTEBOOK(page->transport_notebook), transport->page);*/
189 }
190
191 static void transport_sel_cb(GtkMenuItem *menuitem, gpointer data)
192 {
193         struct SpamAssassinPage *page = (struct SpamAssassinPage *) data;
194         struct Transport *transport;
195
196         transport = (struct Transport *) g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID);
197         show_transport(page, transport);
198 }
199
200 static void spamassassin_create_widget_func(PrefsPage * _page,
201                                             GtkWindow * window,
202                                             gpointer data)
203 {
204         struct SpamAssassinPage *page = (struct SpamAssassinPage *) _page;
205         SpamAssassinConfig *config;
206         guint i, active;
207
208         GtkWidget *table;
209         GtkWidget *label;
210         GtkWidget *label2;
211         GtkWidget *label3;
212         GtkWidget *label4;
213         GtkWidget *label5;
214         GtkWidget *label6;
215         GtkWidget *label7;
216         GtkWidget *hbox1;
217         GtkWidget *hbox4;
218         GtkWidget *transport;
219         GtkWidget *transport_menu;
220 /*      GtkWidget *transport_notebook;*/
221         GtkWidget *spamd_hbox;
222         GtkWidget *username;
223         GtkWidget *hostname;
224         GtkWidget *colon;
225         GtkObject *port_adj;
226         GtkWidget *port;
227         GtkWidget *socket;
228         GtkWidget *hbox6;
229         GtkObject *timeout_adj;
230         GtkWidget *timeout;
231         GtkWidget *receive_spam;
232         GtkWidget *hbox3;
233         GtkObject *max_size_adj;
234         GtkWidget *max_size;
235         GtkWidget *hbox2;
236         GtkWidget *save_folder;
237         GtkWidget *save_folder_select;
238         GtkWidget *hbox5;
239         GtkWidget *process_emails;
240         GtkTooltips *tooltips;
241
242         tooltips = gtk_tooltips_new();
243
244         table = gtk_table_new(10, 3, FALSE);
245         gtk_widget_show(table);
246         gtk_container_set_border_width(GTK_CONTAINER(table), 8);
247         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
248         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
249
250         hbox4 = gtk_hbox_new(FALSE, 8);
251         gtk_widget_show(hbox4);
252         gtk_table_attach(GTK_TABLE(table), hbox4, 0, 1, 0, 1,
253                          (GtkAttachOptions) (GTK_FILL),
254                          (GtkAttachOptions) (GTK_FILL), 0, 0);
255
256         label = gtk_label_new(_("Transport"));
257         gtk_widget_show(label);
258         gtk_box_pack_start(GTK_BOX(hbox4), label, FALSE, FALSE, 0);
259
260         transport = gtk_option_menu_new();
261         gtk_widget_show(transport);
262         gtk_box_pack_end(GTK_BOX(hbox4), transport, FALSE, FALSE, 0);
263         transport_menu = gtk_menu_new();
264
265 /*      transport_notebook = gtk_notebook_new();
266         gtk_widget_show(transport_notebook);
267         gtk_table_attach(GTK_TABLE(table), transport_notebook, 1, 2, 1, 2,
268                          (GtkAttachOptions) (GTK_FILL),
269                          (GtkAttachOptions) (GTK_FILL), 0, 0);
270         GTK_WIDGET_UNSET_FLAGS(transport_notebook, GTK_CAN_FOCUS);
271         gtk_notebook_set_show_tabs(GTK_NOTEBOOK(transport_notebook),
272                                    FALSE);
273         gtk_notebook_set_show_border(GTK_NOTEBOOK(transport_notebook),
274                                      FALSE);
275 */
276
277         hbox1 = gtk_hbox_new(FALSE, 8);
278         gtk_widget_show(hbox1);
279         gtk_table_attach(GTK_TABLE(table), hbox1, 0, 1, 1, 2,
280                          (GtkAttachOptions) (GTK_FILL),
281                          (GtkAttachOptions) (GTK_FILL), 0, 0);
282
283         label2 = gtk_label_new(_("User"));
284         gtk_widget_show(label2);
285         gtk_box_pack_start(GTK_BOX(hbox1), label2, FALSE, FALSE, 0);
286
287         username = gtk_entry_new();
288         gtk_widget_show(username);
289         gtk_box_pack_end(GTK_BOX(hbox1), username, FALSE, FALSE, 0);
290         gtk_tooltips_set_tip(tooltips, username, _("User to use with spamd server"),
291                              NULL);
292
293         spamd_hbox = gtk_hbox_new (FALSE, 8);
294         gtk_widget_show (spamd_hbox);
295         gtk_table_attach (GTK_TABLE (table), spamd_hbox, 0, 1, 2, 3,
296                           (GtkAttachOptions) (GTK_FILL),
297                           (GtkAttachOptions) (GTK_FILL), 0, 0);
298
299         label3 = gtk_label_new(_("spamd"));
300         gtk_widget_show(label3);
301         gtk_box_pack_start(GTK_BOX(spamd_hbox), label3, FALSE, FALSE, 0);
302
303         port_adj = gtk_adjustment_new(783, 1, 65535, 1, 10, 10);
304         port = gtk_spin_button_new(GTK_ADJUSTMENT(port_adj), 1, 0);
305         gtk_widget_show(port);
306         gtk_box_pack_end(GTK_BOX(spamd_hbox), port, FALSE, FALSE, 0);
307         gtk_tooltips_set_tip(tooltips, port, _("Port of spamd server"),
308                              NULL);
309         gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(port), TRUE);
310
311         colon = gtk_label_new(_(":"));
312         gtk_widget_show(colon);
313         gtk_box_pack_end(GTK_BOX(spamd_hbox), colon, FALSE, FALSE, 0);
314
315         hostname = gtk_entry_new();
316         gtk_widget_show(hostname);
317         gtk_box_pack_end(GTK_BOX(spamd_hbox), hostname, FALSE, FALSE, 0);
318         gtk_tooltips_set_tip(tooltips, hostname,
319                              _("Hostname or IP address of spamd server"),
320                              NULL);
321
322         socket = gtk_entry_new();
323         gtk_widget_show(socket);
324         gtk_box_pack_end(GTK_BOX(spamd_hbox), socket, FALSE, FALSE, 0);
325         gtk_tooltips_set_tip(tooltips, socket, _("Path of Unix socket"),
326                              NULL);
327
328         hbox3 = gtk_hbox_new (FALSE, 8);
329         gtk_widget_show (hbox3);
330         gtk_table_attach (GTK_TABLE (table), hbox3, 0, 1, 3, 4,
331                           (GtkAttachOptions) (GTK_FILL),
332                           (GtkAttachOptions) (GTK_FILL), 0, 0);
333
334         label4 = gtk_label_new(_("Maximum size"));
335         gtk_widget_show(label4);
336         gtk_box_pack_start(GTK_BOX(hbox3), label4, FALSE, FALSE, 0);
337
338         max_size_adj = gtk_adjustment_new(250, 0, 10000, 10, 10, 10);
339         max_size = gtk_spin_button_new(GTK_ADJUSTMENT(max_size_adj), 1, 0);
340         gtk_widget_show(max_size);
341         gtk_box_pack_end(GTK_BOX(hbox3), max_size, FALSE, FALSE, 0);
342         gtk_tooltips_set_tip(tooltips, max_size,
343                         _("Messages larger than this will not be checked"),
344                         NULL);
345         gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(max_size), TRUE);
346
347         label5 = gtk_label_new(_("kB"));
348         gtk_widget_show(label5);
349         gtk_table_attach(GTK_TABLE(table), label5, 1, 2, 3, 4,
350                          (GtkAttachOptions) (GTK_FILL),
351                          (GtkAttachOptions) (GTK_FILL), 0, 0);
352
353         hbox6 = gtk_hbox_new(FALSE, 8);
354         gtk_widget_show(hbox6);
355         gtk_table_attach(GTK_TABLE(table), hbox6, 0, 1, 4, 5,
356                          (GtkAttachOptions) (GTK_FILL),
357                          (GtkAttachOptions) (GTK_FILL), 0, 0);
358
359         label6 = gtk_label_new(_("Timeout"));
360         gtk_widget_show(label6);
361         gtk_box_pack_start(GTK_BOX(hbox6), label6, FALSE, FALSE, 0);
362
363         timeout_adj = gtk_adjustment_new(60, 0, 10000, 10, 10, 10);
364         timeout = gtk_spin_button_new(GTK_ADJUSTMENT(timeout_adj), 1, 0);
365         gtk_widget_show(timeout);
366         gtk_box_pack_end(GTK_BOX(hbox6), timeout, FALSE, FALSE, 0);
367         gtk_tooltips_set_tip(tooltips, timeout,
368                 _("Time allowed for checking. If the check takes longer the check will be aborted and the message will be handled as not spam."),
369                 NULL);
370         gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(timeout), TRUE);
371
372         label7 = gtk_label_new(_("s"));
373         gtk_widget_show(label7);
374         gtk_table_attach(GTK_TABLE(table), label7, 1, 2, 4, 5,
375                          (GtkAttachOptions) (GTK_FILL),
376                          (GtkAttachOptions) (GTK_FILL), 0, 0);
377
378         process_emails = gtk_check_button_new_with_label(_("Process messages on receiving"));
379         gtk_widget_show(process_emails);
380         gtk_table_attach(GTK_TABLE(table), process_emails, 0, 1, 5, 6,
381                          (GtkAttachOptions) (GTK_FILL),
382                          (GtkAttachOptions) (0), 0, 0);
383
384         hbox5 = gtk_hbox_new (FALSE, 8);
385         gtk_widget_show (hbox5);
386         gtk_table_attach (GTK_TABLE (table), hbox5, 0, 1, 6, 7,
387                           (GtkAttachOptions) (GTK_FILL),
388                           (GtkAttachOptions) (GTK_FILL), 0, 0);
389         SET_TOGGLE_SENSITIVITY (process_emails, hbox5);
390
391         hbox2 = gtk_hbox_new (FALSE, 8);
392         gtk_widget_show (hbox2);
393         gtk_table_attach (GTK_TABLE (table), hbox2, 0, 1, 6, 7,
394                           (GtkAttachOptions) (GTK_FILL),
395                           (GtkAttachOptions) (GTK_FILL), 0, 0);
396
397         receive_spam = gtk_check_button_new_with_label(_("Save spam in"));
398         gtk_widget_show(receive_spam);
399         gtk_box_pack_start (GTK_BOX (hbox2), receive_spam, FALSE, FALSE, 0);
400
401         save_folder = gtk_entry_new ();
402         gtk_widget_show (save_folder);
403         gtk_box_pack_start (GTK_BOX (hbox2), save_folder, TRUE, FALSE, 0);
404         gtk_tooltips_set_tip(tooltips, save_folder,
405                              _("Folder for storing identified spam. Leave empty to use the default trash folder"),
406                              NULL);
407         SET_TOGGLE_SENSITIVITY (receive_spam, save_folder);
408
409         save_folder_select = gtkut_get_browse_directory_btn(_("_Browse"));
410         gtk_widget_show (save_folder_select);
411         gtk_box_pack_end (GTK_BOX (hbox2), save_folder_select, FALSE, FALSE, 0);
412         gtk_tooltips_set_tip(tooltips, save_folder_select,
413                              _("Click this button to select a folder for storing spam"),
414                              NULL);
415         SET_TOGGLE_SENSITIVITY (receive_spam, save_folder_select);
416
417         config = spamassassin_get_config();
418
419         g_signal_connect(G_OBJECT(save_folder_select), "released",
420                          G_CALLBACK(foldersel_cb), page);
421
422         if (config->username != NULL)
423                 gtk_entry_set_text(GTK_ENTRY(username), config->username);
424         if (config->hostname != NULL)
425                 gtk_entry_set_text(GTK_ENTRY(hostname), config->hostname);
426         gtk_spin_button_set_value(GTK_SPIN_BUTTON(port), (float) config->port);
427         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(process_emails), config->process_emails);
428         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(receive_spam), config->receive_spam);
429         if (config->save_folder != NULL)
430                 gtk_entry_set_text(GTK_ENTRY(save_folder), config->save_folder);
431         gtk_spin_button_set_value(GTK_SPIN_BUTTON(max_size), (float) config->max_size);
432         gtk_spin_button_set_value(GTK_SPIN_BUTTON(timeout), (float) config->timeout);
433         
434         page->transport = transport;
435 /*      page->transport_notebook = transport_notebook;*/
436         page->username = username;
437         page->hostname = hostname;
438         page->label2 = label2;
439         page->label3 = label3;
440         page->label4 = label4;
441         page->label5 = label5;
442         page->label6 = label6;
443         page->label7 = label7;
444         page->colon = colon;
445         page->port = port;
446         page->socket = socket;
447         page->process_emails = process_emails;
448         page->receive_spam = receive_spam;
449         page->save_folder = save_folder;
450         page->save_folder_select = save_folder_select;
451         page->max_size = max_size;
452         page->timeout = timeout;
453
454         active = 0;
455         for (i = 0; i < (sizeof(transports) / sizeof(struct Transport)); i++) {
456                 GtkWidget *menuitem;
457
458                 menuitem = gtk_menu_item_new_with_label(gettext(transports[i].name));
459                 g_object_set_data(G_OBJECT(menuitem), MENU_VAL_ID, &transports[i]);
460                 g_signal_connect(G_OBJECT(menuitem), "activate",
461                                  G_CALLBACK(transport_sel_cb), page);
462                 gtk_widget_show(menuitem);
463                 gtk_menu_append(GTK_MENU(transport_menu), menuitem);
464
465                 if (config->transport == transports[i].transport) {
466                         show_transport(page, &transports[i]);
467                         active = i;
468                 }
469         }
470         gtk_option_menu_set_menu(GTK_OPTION_MENU(transport), transport_menu);
471         gtk_option_menu_set_history(GTK_OPTION_MENU(transport), active);
472
473         page->page.widget = table;
474 }
475
476 static void spamassassin_destroy_widget_func(PrefsPage *_page)
477 {
478         debug_print("Destroying SpamAssassin widget\n");
479 }
480
481 static void spamassassin_save_func(PrefsPage *_page)
482 {
483         struct SpamAssassinPage *page = (struct SpamAssassinPage *) _page;
484         SpamAssassinConfig *config;
485
486         debug_print("Saving SpamAssassin Page\n");
487
488         config = spamassassin_get_config();
489
490         /* enable */
491         config->transport = page->trans;
492
493         /* username */
494         g_free(config->username);
495         config->username = gtk_editable_get_chars(GTK_EDITABLE(page->username), 0, -1);
496         spamassassin_check_username();
497
498         /* hostname */
499         g_free(config->hostname);
500         config->hostname = gtk_editable_get_chars(GTK_EDITABLE(page->hostname), 0, -1);
501
502         /* port */
503         config->port = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->port));
504
505         /* hostname */
506         g_free(config->socket);
507         config->socket = gtk_editable_get_chars(GTK_EDITABLE(page->socket), 0, -1);
508
509         /* process_emails */
510         config->process_emails = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->process_emails));
511
512         /* receive_spam */
513         config->receive_spam = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->receive_spam));
514
515         /* save_folder */
516         g_free(config->save_folder);
517         config->save_folder = gtk_editable_get_chars(GTK_EDITABLE(page->save_folder), 0, -1);
518
519         /* max_size */
520         config->max_size = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->max_size));
521
522         /* timeout */
523         config->timeout = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->timeout));
524
525         if (config->process_emails) {
526                 spamassassin_register_hook();
527         } else {
528                 spamassassin_unregister_hook();
529         }
530
531         if (config->transport == SPAMASSASSIN_DISABLED) {
532                 procmsg_unregister_spam_learner(spamassassin_learn);
533                 procmsg_spam_set_folder(NULL);
534         } else {
535                 if (config->transport == SPAMASSASSIN_TRANSPORT_TCP)
536                         debug_print("enabling learner with a remote spamassassin server requires spamc/spamd 3.1.x\n");
537                 procmsg_register_spam_learner(spamassassin_learn);
538                 procmsg_spam_set_folder(config->save_folder);
539         }
540         spamassassin_save_config();
541 }
542
543 static void gtk_message_callback(gchar *message)
544 {
545         statusbar_print_all(message);
546 }
547
548 static struct SpamAssassinPage spamassassin_page;
549
550 gint spamassassin_gtk_init(void)
551 {
552         static gchar *path[3];
553
554         path[0] = _("Plugins");
555         path[1] = _("SpamAssassin");
556         path[2] = NULL;
557
558         spamassassin_page.page.path = path;
559         spamassassin_page.page.create_widget = spamassassin_create_widget_func;
560         spamassassin_page.page.destroy_widget = spamassassin_destroy_widget_func;
561         spamassassin_page.page.save_page = spamassassin_save_func;
562         spamassassin_page.page.weight = 35.0;
563
564         prefs_gtk_register_page((PrefsPage *) &spamassassin_page);
565         spamassassin_set_message_callback(gtk_message_callback);
566
567         debug_print("SpamAssassin GTK plugin loaded\n");
568         return 0;       
569 }
570
571 void spamassassin_gtk_done(void)
572 {
573         prefs_gtk_unregister_page((PrefsPage *) &spamassassin_page);
574 }