2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2018 the Claws Mail Team
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 3 of the License, or
8 * (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "claws-features.h"
27 #include <glib/gi18n.h>
29 #include "gtk/gtkutils.h"
31 #include "common/claws.h"
32 #include "common/version.h"
34 #include "common/utils.h"
37 #include "prefs_gtk.h"
38 #include "foldersel.h"
39 #include "spamassassin.h"
40 #include "statusbar.h"
42 #include "addressbook.h"
46 #define SA_MAX_SIZE_KB (SPAMC_MAX_MESSAGE_LEN / 1024)
48 struct SpamAssassinPage
52 GtkWidget
*enable_sa_checkbtn
;
53 GtkWidget
*transport_optmenu
;
54 GtkWidget
*transport_label
;
60 GtkWidget
*process_emails
;
61 GtkWidget
*receive_spam
;
62 GtkWidget
*save_folder
;
63 GtkWidget
*save_folder_select
;
67 GtkWidget
*mark_as_read
;
68 GtkWidget
*whitelist_ab
;
69 GtkWidget
*whitelist_ab_folder_combo
;
71 SpamAssassinTransport trans
;
77 SpamAssassinTransport transport
;
92 struct Transport transports
[] = {
93 /*{ N_("Disabled"), SPAMASSASSIN_DISABLED, PAGE_DISABLED, 0 },*/
94 { N_("Localhost"), SPAMASSASSIN_TRANSPORT_LOCALHOST
, PAGE_NETWORK
, 0 },
95 { N_("TCP"), SPAMASSASSIN_TRANSPORT_TCP
, PAGE_NETWORK
, NETWORK_HOSTNAME
},
97 { N_("Unix Socket"), SPAMASSASSIN_TRANSPORT_UNIX
, PAGE_UNIX
, 0 },
101 #ifndef USE_ALT_ADDRBOOK
102 static void spamassassin_whitelist_ab_select_cb(GtkWidget
*widget
, gpointer data
)
104 struct SpamAssassinPage
*page
= (struct SpamAssassinPage
*) data
;
105 const gchar
*folderpath
= NULL
;
106 gchar
*new_path
= NULL
;
108 folderpath
= gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((page
->whitelist_ab_folder_combo
)))));
109 new_path
= addressbook_folder_selection(folderpath
);
111 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((page
->whitelist_ab_folder_combo
)))), new_path
);
117 static void foldersel_cb(GtkWidget
*widget
, gpointer data
)
119 struct SpamAssassinPage
*page
= (struct SpamAssassinPage
*) data
;
124 item
= foldersel_folder_sel(NULL
, FOLDER_SEL_MOVE
, NULL
, FALSE
,
125 _("Select folder to save spam to"));
126 if (item
&& (item_id
= folder_item_get_identifier(item
)) != NULL
) {
127 gtk_editable_delete_text(GTK_EDITABLE(page
->save_folder
), 0, -1);
128 gtk_editable_insert_text(GTK_EDITABLE(page
->save_folder
), item_id
, strlen(item_id
), &newpos
);
133 static void show_transport(struct SpamAssassinPage
*page
, struct Transport
*transport
)
135 page
->trans
= transport
->transport
;
137 switch (transport
->page
) {
140 gtk_widget_show(page->hostname);
141 gtk_widget_show(page->colon);
142 gtk_widget_show(page->port);
143 gtk_widget_hide(page->socket);
144 gtk_widget_set_sensitive(page->username, FALSE);
145 gtk_widget_set_sensitive(page->hostname, FALSE);
146 gtk_widget_set_sensitive(page->colon, FALSE);
147 gtk_widget_set_sensitive(page->port, FALSE);
148 gtk_widget_set_sensitive(page->max_size, FALSE);
149 gtk_widget_set_sensitive(page->timeout, FALSE);
150 gtk_widget_set_sensitive(page->process_emails, FALSE);
151 gtk_widget_set_sensitive(page->receive_spam, FALSE);
152 gtk_widget_set_sensitive(page->save_folder, FALSE);
153 gtk_widget_set_sensitive(page->save_folder_select, FALSE);
157 gtk_widget_hide(page
->hostname
);
158 gtk_widget_hide(page
->colon
);
159 gtk_widget_hide(page
->port
);
160 gtk_widget_show(page
->socket
);
161 gtk_widget_set_sensitive(page
->username
, TRUE
);
162 gtk_widget_set_sensitive(page
->socket
, TRUE
);
163 gtk_widget_set_sensitive(page
->max_size
, TRUE
);
164 gtk_widget_set_sensitive(page
->timeout
, TRUE
);
165 gtk_widget_set_sensitive(page
->process_emails
, TRUE
);
166 gtk_widget_set_sensitive(page
->receive_spam
, TRUE
);
167 gtk_widget_set_sensitive(page
->save_folder
, TRUE
);
168 gtk_widget_set_sensitive(page
->save_folder_select
, TRUE
);
171 gtk_widget_show(page
->hostname
);
172 gtk_widget_show(page
->colon
);
173 gtk_widget_show(page
->port
);
174 gtk_widget_hide(page
->socket
);
175 gtk_widget_set_sensitive(page
->username
, TRUE
);
176 gtk_widget_set_sensitive(page
->max_size
, TRUE
);
177 gtk_widget_set_sensitive(page
->timeout
, TRUE
);
178 gtk_widget_set_sensitive(page
->process_emails
, TRUE
);
179 gtk_widget_set_sensitive(page
->receive_spam
, TRUE
);
180 gtk_widget_set_sensitive(page
->save_folder
, TRUE
);
181 gtk_widget_set_sensitive(page
->save_folder_select
, TRUE
);
182 if (transport
->pageflags
& NETWORK_HOSTNAME
) {
183 gtk_widget_set_sensitive(page
->hostname
, TRUE
);
184 gtk_widget_set_sensitive(page
->colon
, TRUE
);
185 gtk_widget_set_sensitive(page
->port
, TRUE
);
187 gtk_widget_set_sensitive(page
->hostname
, FALSE
);
188 gtk_widget_set_sensitive(page
->colon
, FALSE
);
189 gtk_widget_set_sensitive(page
->port
, TRUE
);
197 static void transport_sel_cb(GtkMenuItem
*menuitem
, gpointer data
)
199 struct SpamAssassinPage
*page
= (struct SpamAssassinPage
*) data
;
200 struct Transport
*transport
;
204 cm_return_if_fail(gtk_combo_box_get_active_iter(
205 GTK_COMBO_BOX(page
->transport_optmenu
), &iter
));
207 model
= gtk_combo_box_get_model(GTK_COMBO_BOX(page
->transport_optmenu
));
208 gtk_tree_model_get(model
, &iter
, 1, &transport
, -1);
210 show_transport(page
, transport
);
213 static void spamassassin_create_widget_func(PrefsPage
* _page
,
217 struct SpamAssassinPage
*page
= (struct SpamAssassinPage
*) _page
;
218 SpamAssassinConfig
*config
;
221 GtkWidget
*vbox1
, *vbox2
;
222 GtkWidget
*frame_transport
, *table_transport
, *vbox_transport
;
223 GtkWidget
*hbox_spamd
, *hbox_compress
, *hbox_max_size
;
224 GtkWidget
*hbox_timeout
, *hbox_process_emails
, *hbox_save_spam
;
225 GtkWidget
*hbox_mark_as_read
, *hbox_whitelist
;
226 GtkWidget
*whitelist_ab_checkbtn
;
227 GtkWidget
*whitelist_ab_folder_combo
;
228 GtkWidget
*whitelist_ab_select_btn
;
230 GtkWidget
*enable_sa_checkbtn
;
232 GtkWidget
*transport_label
;
233 GtkWidget
*transport_optmenu
;
235 GtkWidget
*user_label
;
236 GtkWidget
*user_entry
;
238 GtkWidget
*spamd_label
;
239 GtkWidget
*spamd_hostname_entry
;
240 GtkWidget
*spamd_colon_label
;
241 GtkAdjustment
*spamd_port_spinbtn_adj
;
242 GtkWidget
*spamd_port_spinbtn
;
243 GtkWidget
*spamd_socket_entry
;
245 GtkWidget
*compress_checkbtn
;
247 GtkWidget
*max_size_label
;
248 GtkAdjustment
*max_size_spinbtn_adj
;
249 GtkWidget
*max_size_spinbtn
;
250 GtkWidget
*max_size_kb_label
;
252 GtkWidget
*timeout_label
;
253 GtkAdjustment
*timeout_spinbtn_adj
;
254 GtkWidget
*timeout_spinbtn
;
255 GtkWidget
*timeout_seconds_label
;
257 GtkWidget
*process_emails_checkbtn
;
259 GtkWidget
*save_spam_checkbtn
;
260 GtkWidget
*save_spam_folder_entry
;
261 GtkWidget
*save_spam_folder_select
;
263 GtkWidget
*mark_as_read_checkbtn
;
266 GtkCellRenderer
*renderer
;
269 vbox1
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, VSPACING
);
270 gtk_widget_show (vbox1
);
271 gtk_container_set_border_width (GTK_CONTAINER (vbox1
), VBOX_BORDER
);
273 vbox2
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 4);
274 gtk_widget_show (vbox2
);
275 gtk_box_pack_start (GTK_BOX (vbox1
), vbox2
, FALSE
, FALSE
, 0);
277 enable_sa_checkbtn
= gtk_check_button_new_with_label(_("Enable SpamAssassin plugin"));
278 gtk_widget_show(enable_sa_checkbtn
);
279 gtk_box_pack_start(GTK_BOX(vbox2
), enable_sa_checkbtn
, TRUE
, TRUE
, 0);
281 vbox_transport
= gtkut_get_options_frame(vbox2
, &frame_transport
, _("Transport"));
283 table_transport
= gtk_grid_new();
284 gtk_widget_show (table_transport
);
285 gtk_box_pack_start(GTK_BOX(vbox_transport
), table_transport
, TRUE
, TRUE
, 0);
286 gtk_grid_set_row_spacing(GTK_GRID(table_transport
), 4);
287 gtk_grid_set_column_spacing(GTK_GRID(table_transport
), 8);
289 transport_label
= gtk_label_new(_("Type of transport"));
290 gtk_widget_show(transport_label
);
291 gtk_label_set_justify(GTK_LABEL(transport_label
), GTK_JUSTIFY_RIGHT
);
292 gtk_label_set_xalign(GTK_LABEL(transport_label
), 1.0);
293 gtk_grid_attach(GTK_GRID(table_transport
), transport_label
, 0, 0, 1, 1);
295 store
= gtk_list_store_new(2, G_TYPE_STRING
, G_TYPE_POINTER
);
296 transport_optmenu
= gtk_combo_box_new_with_model(GTK_TREE_MODEL(store
));
297 renderer
= gtk_cell_renderer_text_new();
298 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(transport_optmenu
),
300 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(transport_optmenu
),
301 renderer
, "text", 0, NULL
);
302 gtk_widget_show(transport_optmenu
);
304 gtk_grid_attach(GTK_GRID(table_transport
), transport_optmenu
, 1, 0, 1, 1);
306 user_label
= gtk_label_new(_("User"));
307 gtk_widget_show(user_label
);
308 gtk_label_set_justify(GTK_LABEL(user_label
), GTK_JUSTIFY_RIGHT
);
309 gtk_label_set_xalign(GTK_LABEL(user_label
), 1.0);
310 gtk_grid_attach(GTK_GRID(table_transport
), user_label
, 0, 1, 1, 1);
312 user_entry
= gtk_entry_new();
313 gtk_widget_show(user_entry
);
314 gtk_grid_attach(GTK_GRID(table_transport
), user_entry
, 1, 1, 1, 1);
315 gtk_widget_set_hexpand(user_entry
, TRUE
);
316 gtk_widget_set_halign(user_entry
, GTK_ALIGN_FILL
);
317 CLAWS_SET_TIP(user_entry
, _("User to use with spamd server"));
319 spamd_label
= gtk_label_new(_("spamd"));
320 gtk_widget_show(spamd_label
);
321 gtk_label_set_justify(GTK_LABEL(spamd_label
), GTK_JUSTIFY_RIGHT
);
322 gtk_label_set_xalign(GTK_LABEL(spamd_label
), 1.0);
323 gtk_grid_attach(GTK_GRID(table_transport
), spamd_label
, 0, 2, 1, 1);
325 hbox_spamd
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
326 gtk_widget_show(hbox_spamd
);
327 gtk_grid_attach(GTK_GRID(table_transport
), hbox_spamd
, 1, 2, 1, 1);
328 gtk_widget_set_hexpand(hbox_spamd
, TRUE
);
329 gtk_widget_set_halign(hbox_spamd
, GTK_ALIGN_FILL
);
331 spamd_hostname_entry
= gtk_entry_new();
332 gtk_widget_show(spamd_hostname_entry
);
333 gtk_box_pack_start(GTK_BOX(hbox_spamd
), spamd_hostname_entry
, TRUE
, TRUE
, 0);
334 CLAWS_SET_TIP(spamd_hostname_entry
,
335 _("Hostname or IP address of spamd server"));
337 spamd_colon_label
= gtk_label_new(":");
338 gtk_widget_show(spamd_colon_label
);
339 gtk_box_pack_start(GTK_BOX(hbox_spamd
), spamd_colon_label
, FALSE
, FALSE
, 0);
341 spamd_port_spinbtn_adj
= GTK_ADJUSTMENT(gtk_adjustment_new(783, 1, 65535, 1, 10, 0));
342 spamd_port_spinbtn
= gtk_spin_button_new(GTK_ADJUSTMENT(spamd_port_spinbtn_adj
), 1, 0);
343 gtk_widget_show(spamd_port_spinbtn
);
344 gtk_box_pack_start(GTK_BOX(hbox_spamd
), spamd_port_spinbtn
, FALSE
, FALSE
, 0);
345 CLAWS_SET_TIP(spamd_port_spinbtn
,
346 _("Port of spamd server"));
347 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(spamd_port_spinbtn
), TRUE
);
349 spamd_socket_entry
= gtk_entry_new();
350 gtk_widget_show(spamd_socket_entry
);
351 gtk_box_pack_start(GTK_BOX(hbox_spamd
), spamd_socket_entry
, TRUE
, TRUE
, 0);
352 CLAWS_SET_TIP(spamd_socket_entry
, _("Path of Unix socket"));
354 hbox_compress
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
355 gtk_widget_show(hbox_compress
);
356 gtk_box_pack_start (GTK_BOX (vbox2
), hbox_compress
, TRUE
, TRUE
, 0);
358 compress_checkbtn
= gtk_check_button_new_with_label(
359 _("Use compression"));
360 gtk_widget_show(compress_checkbtn
);
361 gtk_box_pack_start(GTK_BOX(hbox_compress
), compress_checkbtn
, TRUE
, TRUE
, 0);
362 CLAWS_SET_TIP(compress_checkbtn
,
363 _("Enable compression if spamd uses it, otherwise disable it."));
365 hbox_max_size
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
366 gtk_widget_show(hbox_max_size
);
367 gtk_box_pack_start (GTK_BOX (vbox2
), hbox_max_size
, TRUE
, TRUE
, 0);
369 max_size_label
= gtk_label_new(_("Maximum size"));
370 gtk_widget_show(max_size_label
);
371 gtk_box_pack_start(GTK_BOX(hbox_max_size
), max_size_label
, FALSE
, FALSE
, 0);
373 max_size_spinbtn_adj
= GTK_ADJUSTMENT(gtk_adjustment_new(250, 0, SA_MAX_SIZE_KB
, 10, 10, 0));
374 max_size_spinbtn
= gtk_spin_button_new(GTK_ADJUSTMENT(max_size_spinbtn_adj
), 1, 0);
375 gtk_widget_show(max_size_spinbtn
);
376 gtk_box_pack_start(GTK_BOX(hbox_max_size
), max_size_spinbtn
, FALSE
, FALSE
, 0);
377 CLAWS_SET_TIP(max_size_spinbtn
,
378 _("Messages larger than this will not be checked"));
379 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(max_size_spinbtn
), TRUE
);
381 max_size_kb_label
= gtk_label_new(_("KiB"));
382 gtk_widget_show(max_size_kb_label
);
383 gtk_box_pack_start(GTK_BOX(hbox_max_size
), max_size_kb_label
, FALSE
, FALSE
, 0);
385 hbox_timeout
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
386 gtk_widget_show(hbox_timeout
);
387 gtk_box_pack_start (GTK_BOX (vbox2
), hbox_timeout
, TRUE
, TRUE
, 0);
389 timeout_label
= gtk_label_new(_("Timeout (secs)"));
390 gtk_widget_show(timeout_label
);
391 gtk_box_pack_start(GTK_BOX(hbox_timeout
), timeout_label
, FALSE
, FALSE
, 0);
393 timeout_spinbtn_adj
= GTK_ADJUSTMENT(gtk_adjustment_new(60, 0, 10000, 10, 10, 0));
394 timeout_spinbtn
= gtk_spin_button_new(GTK_ADJUSTMENT(timeout_spinbtn_adj
), 1, 0);
395 gtk_widget_show(timeout_spinbtn
);
396 gtk_box_pack_start(GTK_BOX(hbox_timeout
), timeout_spinbtn
, FALSE
, FALSE
, 0);
397 CLAWS_SET_TIP(timeout_spinbtn
,
398 _("Maximum time allowed for checking. If the check takes longer "
399 "it will be aborted."));
400 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(timeout_spinbtn
), TRUE
);
402 timeout_seconds_label
= gtk_label_new(_("seconds"));
403 gtk_widget_show(timeout_seconds_label
);
404 gtk_box_pack_start(GTK_BOX(hbox_timeout
), timeout_seconds_label
, FALSE
, FALSE
, 0);
406 hbox_process_emails
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
407 gtk_widget_show(hbox_process_emails
);
408 gtk_box_pack_start (GTK_BOX (vbox2
), hbox_process_emails
, TRUE
, TRUE
, 0);
410 process_emails_checkbtn
= gtk_check_button_new_with_label(
411 _("Process messages on receiving"));
412 gtk_widget_show(process_emails_checkbtn
);
413 gtk_box_pack_start(GTK_BOX(hbox_process_emails
), process_emails_checkbtn
, TRUE
, TRUE
, 0);
415 hbox_save_spam
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
416 gtk_widget_show(hbox_save_spam
);
417 gtk_box_pack_start (GTK_BOX (vbox2
), hbox_save_spam
, TRUE
, TRUE
, 0);
419 save_spam_checkbtn
= gtk_check_button_new_with_label(_("Save spam in"));
420 gtk_widget_show(save_spam_checkbtn
);
421 gtk_box_pack_start(GTK_BOX(hbox_save_spam
), save_spam_checkbtn
, FALSE
, FALSE
, 0);
423 save_spam_folder_entry
= gtk_entry_new();
424 gtk_widget_show (save_spam_folder_entry
);
425 gtk_box_pack_start (GTK_BOX (hbox_save_spam
), save_spam_folder_entry
, TRUE
, TRUE
, 0);
426 CLAWS_SET_TIP(save_spam_folder_entry
,
427 _("Folder for storing identified spam. Leave empty to use the trash folder."));
429 save_spam_folder_select
= gtkut_get_browse_directory_btn(_("_Browse"));
430 gtk_widget_show (save_spam_folder_select
);
431 gtk_box_pack_start (GTK_BOX (hbox_save_spam
), save_spam_folder_select
, FALSE
, FALSE
, 0);
432 CLAWS_SET_TIP(save_spam_folder_select
,
433 _("Click this button to select a folder for storing spam"));
435 hbox_mark_as_read
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
436 gtk_widget_show(hbox_mark_as_read
);
437 gtk_box_pack_start (GTK_BOX (vbox2
), hbox_mark_as_read
, TRUE
, TRUE
, 0);
439 mark_as_read_checkbtn
= gtk_check_button_new_with_label(
440 _("Mark spam as read"));
441 gtk_widget_show(mark_as_read_checkbtn
);
442 gtk_box_pack_start(GTK_BOX(hbox_mark_as_read
), mark_as_read_checkbtn
, TRUE
, TRUE
, 0);
444 hbox_whitelist
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
445 gtk_widget_show(hbox_whitelist
);
446 gtk_box_pack_start (GTK_BOX (vbox2
), hbox_whitelist
, TRUE
, TRUE
, 0);
448 whitelist_ab_checkbtn
= gtk_check_button_new_with_label(_("Whitelist senders found in address book/folder"));
449 gtk_widget_show(whitelist_ab_checkbtn
);
450 gtk_box_pack_start(GTK_BOX(hbox_whitelist
), whitelist_ab_checkbtn
, FALSE
, FALSE
, 0);
451 CLAWS_SET_TIP(whitelist_ab_checkbtn
,
452 _("Messages coming from your address book contacts will be received in the normal folder even if detected as spam"));
454 whitelist_ab_folder_combo
= combobox_text_new(TRUE
, _("Any"), NULL
);
455 gtk_widget_set_size_request(whitelist_ab_folder_combo
, 100, -1);
456 gtk_box_pack_start (GTK_BOX (hbox_whitelist
), whitelist_ab_folder_combo
, TRUE
, TRUE
, 0);
458 whitelist_ab_select_btn
= gtk_button_new_with_label(_("Select..."));
459 gtk_widget_show (whitelist_ab_select_btn
);
460 gtk_box_pack_start (GTK_BOX (hbox_whitelist
), whitelist_ab_select_btn
, FALSE
, FALSE
, 0);
461 CLAWS_SET_TIP(whitelist_ab_select_btn
,
462 _("Click this button to select a book or folder in the address book"));
464 SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn
, frame_transport
);
465 SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn
, hbox_compress
);
466 SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn
, hbox_max_size
);
467 SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn
, hbox_timeout
);
468 SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn
, hbox_save_spam
);
469 SET_TOGGLE_SENSITIVITY(save_spam_checkbtn
, save_spam_folder_entry
);
470 SET_TOGGLE_SENSITIVITY(save_spam_checkbtn
, save_spam_folder_select
);
471 SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn
, hbox_process_emails
);
472 SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn
, mark_as_read_checkbtn
);
473 SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn
, hbox_whitelist
);
474 SET_TOGGLE_SENSITIVITY(whitelist_ab_checkbtn
, whitelist_ab_folder_combo
);
475 #ifndef USE_ALT_ADDRBOOK
476 SET_TOGGLE_SENSITIVITY(whitelist_ab_checkbtn
, whitelist_ab_select_btn
);
478 config
= spamassassin_get_config();
480 g_signal_connect(G_OBJECT(save_spam_folder_select
), "clicked",
481 G_CALLBACK(foldersel_cb
), page
);
482 #ifndef USE_ALT_ADDRBOOK
483 g_signal_connect(G_OBJECT (whitelist_ab_select_btn
), "clicked",
484 G_CALLBACK(spamassassin_whitelist_ab_select_cb
), page
);
486 gtk_widget_set_sensitive(GTK_WIDGET(whitelist_ab_select_btn
), FALSE
);
489 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_sa_checkbtn
), config
->enable
);
490 if (config
->username
!= NULL
)
491 gtk_entry_set_text(GTK_ENTRY(user_entry
), config
->username
);
492 if (config
->hostname
!= NULL
)
493 gtk_entry_set_text(GTK_ENTRY(spamd_hostname_entry
), config
->hostname
);
494 if (config
->socket
!= NULL
)
495 gtk_entry_set_text(GTK_ENTRY(spamd_socket_entry
), config
->socket
);
496 if (config
->whitelist_ab_folder
!= NULL
) {
497 /* translate "Any" (stored UNtranslated) */
498 if (strcasecmp(config
->whitelist_ab_folder
, "Any") == 0)
499 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((whitelist_ab_folder_combo
)))),
500 config
->whitelist_ab_folder
);
502 /* backward compatibility (when translated "Any" was stored) */
503 if (g_utf8_collate(config
->whitelist_ab_folder
, _("Any")) == 0)
504 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((whitelist_ab_folder_combo
)))),
505 config
->whitelist_ab_folder
);
507 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((whitelist_ab_folder_combo
)))),
508 config
->whitelist_ab_folder
);
510 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spamd_port_spinbtn
), (float) config
->port
);
511 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compress_checkbtn
), config
->compress
);
512 gtk_spin_button_set_value(GTK_SPIN_BUTTON(max_size_spinbtn
), (float) config
->max_size
);
513 gtk_spin_button_set_value(GTK_SPIN_BUTTON(timeout_spinbtn
), (float) config
->timeout
);
514 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(process_emails_checkbtn
), config
->process_emails
);
515 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(save_spam_checkbtn
), config
->receive_spam
);
516 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(whitelist_ab_checkbtn
), config
->whitelist_ab
);
517 if (config
->save_folder
!= NULL
)
518 gtk_entry_set_text(GTK_ENTRY(save_spam_folder_entry
), config
->save_folder
);
519 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mark_as_read_checkbtn
), config
->mark_as_read
);
521 page
->enable_sa_checkbtn
= enable_sa_checkbtn
;
522 page
->transport_label
= transport_label
;
523 page
->transport_optmenu
= transport_optmenu
;
524 page
->username
= user_entry
;
525 page
->hostname
= spamd_hostname_entry
;
526 page
->colon
= spamd_colon_label
;
527 page
->port
= spamd_port_spinbtn
;
528 page
->socket
= spamd_socket_entry
;
529 page
->compress
= compress_checkbtn
;
530 page
->max_size
= max_size_spinbtn
;
531 page
->timeout
= timeout_spinbtn
;
532 page
->process_emails
= process_emails_checkbtn
;
533 page
->receive_spam
= save_spam_checkbtn
;
534 page
->save_folder
= save_spam_folder_entry
;
535 page
->save_folder_select
= save_spam_folder_select
;
536 page
->mark_as_read
= mark_as_read_checkbtn
;
537 page
->whitelist_ab
= whitelist_ab_checkbtn
;
538 page
->whitelist_ab_folder_combo
= whitelist_ab_folder_combo
;
541 for (i
= 0; i
< (sizeof(transports
) / sizeof(struct Transport
)); i
++) {
543 gtk_list_store_append(store
, &iter
);
544 gtk_list_store_set(store
, &iter
,
545 0, gettext(transports
[i
].name
),
546 1, &transports
[i
], -1);
547 if (config
->transport
== transports
[i
].transport
) {
548 show_transport(page
, &transports
[i
]);
550 } else if (config
->transport
== SPAMASSASSIN_DISABLED
551 && transports
[i
].transport
== SPAMASSASSIN_TRANSPORT_LOCALHOST
) {
552 show_transport(page
, &transports
[i
]);
554 /* and disable via new way */
555 config
->enable
= FALSE
;
556 gtk_toggle_button_set_active(
557 GTK_TOGGLE_BUTTON(enable_sa_checkbtn
),
561 gtk_combo_box_set_active(GTK_COMBO_BOX(transport_optmenu
), active
);
562 g_signal_connect(G_OBJECT(transport_optmenu
), "changed",
563 G_CALLBACK(transport_sel_cb
), page
);
565 page
->page
.widget
= vbox1
;
568 static void spamassassin_destroy_widget_func(PrefsPage
*_page
)
570 debug_print("Destroying SpamAssassin widget\n");
573 static void spamassassin_save_func(PrefsPage
*_page
)
575 struct SpamAssassinPage
*page
= (struct SpamAssassinPage
*) _page
;
576 SpamAssassinConfig
*config
;
578 debug_print("Saving SpamAssassin Page\n");
580 config
= spamassassin_get_config();
583 config
->enable
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page
->enable_sa_checkbtn
));
584 config
->transport
= page
->trans
;
587 g_free(config
->username
);
588 config
->username
= gtk_editable_get_chars(GTK_EDITABLE(page
->username
), 0, -1);
589 spamassassin_check_username();
592 g_free(config
->hostname
);
593 config
->hostname
= gtk_editable_get_chars(GTK_EDITABLE(page
->hostname
), 0, -1);
596 config
->port
= gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page
->port
));
599 g_free(config
->socket
);
600 config
->socket
= gtk_editable_get_chars(GTK_EDITABLE(page
->socket
), 0, -1);
603 config
->process_emails
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page
->process_emails
));
606 config
->receive_spam
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page
->receive_spam
));
609 g_free(config
->save_folder
);
610 config
->save_folder
= gtk_editable_get_chars(GTK_EDITABLE(page
->save_folder
), 0, -1);
613 config
->max_size
= gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page
->max_size
));
616 config
->timeout
= gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page
->timeout
));
619 config
->compress
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page
->compress
));
622 config
->mark_as_read
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page
->mark_as_read
));
625 config
->whitelist_ab
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page
->whitelist_ab
));
626 g_free(config
->whitelist_ab_folder
);
627 config
->whitelist_ab_folder
= gtk_editable_get_chars(
628 GTK_EDITABLE(gtk_bin_get_child(GTK_BIN((page
->whitelist_ab_folder_combo
)))), 0, -1);
629 /* store UNtranslated "Any" */
630 if (g_utf8_collate(config
->whitelist_ab_folder
, _("Any")) == 0) {
631 g_free(config
->whitelist_ab_folder
);
632 config
->whitelist_ab_folder
= g_strdup("Any");
635 if (config
->process_emails
) {
636 spamassassin_register_hook();
638 spamassassin_unregister_hook();
641 if (!config
->enable
) {
642 procmsg_unregister_spam_learner(spamassassin_learn
);
643 procmsg_spam_set_folder(NULL
, NULL
);
645 if (config
->transport
== SPAMASSASSIN_TRANSPORT_TCP
)
646 debug_print("enabling learner with a remote spamassassin server requires spamc/spamd 3.1.x\n");
647 procmsg_register_spam_learner(spamassassin_learn
);
648 procmsg_spam_set_folder(config
->save_folder
, spamassassin_get_spam_folder
);
651 spamassassin_save_config();
654 static void gtk_message_callback(gchar
*message
)
656 statusbar_print_all("%s", message
);
659 static struct SpamAssassinPage spamassassin_page
;
661 gint
spamassassin_gtk_init(void)
663 static gchar
*path
[3];
665 path
[0] = _("Plugins");
666 path
[1] = _("SpamAssassin");
669 spamassassin_page
.page
.path
= path
;
670 spamassassin_page
.page
.create_widget
= spamassassin_create_widget_func
;
671 spamassassin_page
.page
.destroy_widget
= spamassassin_destroy_widget_func
;
672 spamassassin_page
.page
.save_page
= spamassassin_save_func
;
673 spamassassin_page
.page
.weight
= 35.0;
675 prefs_gtk_register_page((PrefsPage
*) &spamassassin_page
);
676 spamassassin_set_message_callback(gtk_message_callback
);
678 debug_print("SpamAssassin GTK plugin loaded\n");
682 void spamassassin_gtk_done(void)
684 prefs_gtk_unregister_page((PrefsPage
*) &spamassassin_page
);