2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2003 Hiroyuki Yamamoto and the Sylpheed-Claws 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 2 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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include "common/sylpheed.h"
30 #include "common/version.h"
33 #include "common/utils.h"
36 #include "prefs_gtk.h"
37 #include "foldersel.h"
38 #include "spamassassin.h"
40 struct SpamAssassinPage
47 GtkWidget *receive_spam;
48 GtkWidget *save_folder;
53 static void foldersel_cb(GtkWidget *widget, gpointer data)
55 struct SpamAssassinPage *page = (struct SpamAssassinPage *) data;
60 item = foldersel_folder_sel(NULL, FOLDER_SEL_MOVE, NULL);
61 if (item && (item_id = folder_item_get_identifier(item)) != NULL) {
62 gtk_editable_delete_text(GTK_EDITABLE(page->save_folder), 0, -1);
63 gtk_editable_insert_text(GTK_EDITABLE(page->save_folder), item_id, strlen(item_id), &newpos);
68 static void spamassassin_create_widget_func(PrefsPage * _page,
72 struct SpamAssassinPage *page = (struct SpamAssassinPage *) _page;
73 SpamAssassinConfig *config;
89 GtkWidget *receive_spam;
91 GtkWidget *save_folder;
95 GtkObject *max_size_adj;
101 GtkObject *timeout_adj;
103 GtkTooltips *tooltips;
105 tooltips = gtk_tooltips_new();
107 table1 = gtk_table_new(6, 3, FALSE);
108 gtk_widget_show(table1);
109 gtk_container_set_border_width(GTK_CONTAINER(table1), 8);
110 gtk_table_set_row_spacings(GTK_TABLE(table1), 4);
111 gtk_table_set_col_spacings(GTK_TABLE(table1), 8);
113 label3 = gtk_label_new(_("Enable"));
114 gtk_widget_show(label3);
115 gtk_table_attach(GTK_TABLE(table1), label3, 0, 1, 0, 1,
116 (GtkAttachOptions) (GTK_FILL),
117 (GtkAttachOptions) (0), 0, 0);
118 gtk_misc_set_alignment(GTK_MISC(label3), 0, 0.5);
120 label4 = gtk_label_new(_("spamd "));
121 gtk_widget_show(label4);
122 gtk_table_attach(GTK_TABLE(table1), label4, 0, 1, 1, 2,
123 (GtkAttachOptions) (GTK_FILL),
124 (GtkAttachOptions) (0), 0, 0);
125 gtk_misc_set_alignment(GTK_MISC(label4), 0, 0.5);
127 hbox1 = gtk_hbox_new(FALSE, 0);
128 gtk_widget_show(hbox1);
129 gtk_table_attach(GTK_TABLE(table1), hbox1, 1, 2, 1, 2,
130 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
131 (GtkAttachOptions) (GTK_FILL), 0, 0);
133 hostname = gtk_entry_new();
134 gtk_widget_show(hostname);
135 gtk_box_pack_start(GTK_BOX(hbox1), hostname, TRUE, TRUE, 0);
136 gtk_tooltips_set_tip(tooltips, hostname,
137 _("Hostname or IP address of spamd server"),
140 label5 = gtk_label_new(_(":"));
141 gtk_widget_show(label5);
142 gtk_box_pack_start(GTK_BOX(hbox1), label5, FALSE, FALSE, 0);
143 gtk_misc_set_padding(GTK_MISC(label5), 8, 0);
145 port_adj = gtk_adjustment_new(783, 1, 65535, 1, 10, 10);
146 port = gtk_spin_button_new(GTK_ADJUSTMENT(port_adj), 1, 0);
147 gtk_widget_show(port);
148 gtk_box_pack_end(GTK_BOX(hbox1), port, FALSE, TRUE, 0);
149 gtk_widget_set_usize(port, 64, -2);
150 gtk_tooltips_set_tip(tooltips, port, _("Port of spamd server"),
152 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(port), TRUE);
154 enable = gtk_check_button_new_with_label("");
155 gtk_widget_show(enable);
156 gtk_table_attach(GTK_TABLE(table1), enable, 1, 2, 0, 1,
157 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
158 (GtkAttachOptions) (0), 0, 0);
159 gtk_tooltips_set_tip(tooltips, enable,
160 _("Enable SpamAssassin filtering"), NULL);
162 label9 = gtk_label_new(_("Save Spam"));
163 gtk_widget_show(label9);
164 gtk_table_attach(GTK_TABLE(table1), label9, 0, 1, 2, 3,
165 (GtkAttachOptions) (GTK_FILL),
166 (GtkAttachOptions) (0), 0, 0);
167 gtk_misc_set_alignment(GTK_MISC(label9), 0, 0.5);
169 receive_spam = gtk_check_button_new_with_label("");
170 gtk_widget_show(receive_spam);
171 gtk_table_attach(GTK_TABLE(table1), receive_spam, 1, 2, 2, 3,
172 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
173 (GtkAttachOptions) (0), 0, 0);
174 gtk_tooltips_set_tip(tooltips, receive_spam,
176 ("Save mails that where identified as spam to a folder"),
179 label8 = gtk_label_new(_("Save Folder"));
180 gtk_widget_show(label8);
181 gtk_table_attach(GTK_TABLE(table1), label8, 0, 1, 3, 4,
182 (GtkAttachOptions) (GTK_FILL),
183 (GtkAttachOptions) (0), 0, 0);
184 gtk_label_set_justify(GTK_LABEL(label8), GTK_JUSTIFY_LEFT);
185 gtk_misc_set_alignment(GTK_MISC(label8), 0, 0.5);
187 save_folder = gtk_entry_new();
188 gtk_widget_show(save_folder);
189 gtk_table_attach(GTK_TABLE(table1), save_folder, 1, 2, 3, 4,
190 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
191 (GtkAttachOptions) (0), 0, 0);
192 gtk_tooltips_set_tip(tooltips, save_folder,
194 ("Folder that will be used to save spam. Leave empty to use the default trash folder"),
197 button4 = gtk_button_new_with_label(_("..."));
198 gtk_widget_show(button4);
199 gtk_table_attach(GTK_TABLE(table1), button4, 2, 3, 3, 4,
200 (GtkAttachOptions) (GTK_SHRINK | GTK_FILL),
201 (GtkAttachOptions) (0), 0, 0);
203 label6 = gtk_label_new(_("Maximum Size"));
204 gtk_widget_show(label6);
205 gtk_table_attach(GTK_TABLE(table1), label6, 0, 1, 4, 5,
206 (GtkAttachOptions) (GTK_FILL),
207 (GtkAttachOptions) (0), 0, 0);
208 gtk_misc_set_alignment(GTK_MISC(label6), 0, 0.5);
210 hbox3 = gtk_hbox_new(FALSE, 0);
211 gtk_widget_show(hbox3);
212 gtk_table_attach(GTK_TABLE(table1), hbox3, 1, 2, 4, 5,
213 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
214 (GtkAttachOptions) (GTK_FILL), 0, 0);
216 max_size_adj = gtk_adjustment_new(250, 0, 10000, 10, 10, 10);
217 max_size = gtk_spin_button_new(GTK_ADJUSTMENT(max_size_adj), 1, 0);
218 gtk_widget_show(max_size);
219 gtk_box_pack_end(GTK_BOX(hbox3), max_size, FALSE, TRUE, 0);
220 gtk_widget_set_usize(max_size, 64, -2);
221 gtk_tooltips_set_tip(tooltips, max_size,
223 ("Maximum size a message is allowed to have to be checked"),
225 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(max_size), TRUE);
227 label11 = gtk_label_new(_("kB"));
228 gtk_widget_show(label11);
229 gtk_table_attach(GTK_TABLE(table1), label11, 2, 3, 4, 5,
230 (GtkAttachOptions) (GTK_FILL),
231 (GtkAttachOptions) (0), 0, 0);
232 gtk_misc_set_alignment(GTK_MISC(label11), 0, 0.5);
234 label12 = gtk_label_new(_("Timeout"));
235 gtk_widget_show(label12);
236 gtk_table_attach(GTK_TABLE(table1), label12, 0, 1, 5, 6,
237 (GtkAttachOptions) (GTK_FILL),
238 (GtkAttachOptions) (0), 0, 0);
239 gtk_misc_set_alignment(GTK_MISC(label12), 0, 0.5);
241 label13 = gtk_label_new(_("s"));
242 gtk_widget_show(label13);
243 gtk_table_attach(GTK_TABLE(table1), label13, 2, 3, 5, 6,
244 (GtkAttachOptions) (GTK_FILL),
245 (GtkAttachOptions) (0), 0, 0);
246 gtk_misc_set_alignment(GTK_MISC(label13), 0, 0.5);
248 hbox4 = gtk_hbox_new(FALSE, 0);
249 gtk_widget_show(hbox4);
250 gtk_table_attach(GTK_TABLE(table1), hbox4, 1, 2, 5, 6,
251 (GtkAttachOptions) (GTK_FILL),
252 (GtkAttachOptions) (GTK_FILL), 0, 0);
254 timeout_adj = gtk_adjustment_new(30, 5, 300, 1, 1, 1);
255 timeout = gtk_spin_button_new(GTK_ADJUSTMENT(timeout_adj), 1, 0);
256 gtk_widget_show(timeout);
257 gtk_box_pack_end(GTK_BOX(hbox4), timeout, FALSE, TRUE, 0);
258 gtk_widget_set_usize(timeout, 64, -2);
259 gtk_tooltips_set_tip(tooltips, timeout,
261 ("Maximum time allowed for the spam check. After the time the check will be aborted and the message delivered as none spam."),
263 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(timeout), TRUE);
268 config = spamassassin_get_config();
270 gtk_signal_connect(GTK_OBJECT(button4), "released", GTK_SIGNAL_FUNC(foldersel_cb), page);
272 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable), config->enable);
273 if (config->hostname != NULL)
274 gtk_entry_set_text(GTK_ENTRY(hostname), config->hostname);
275 gtk_spin_button_set_value(GTK_SPIN_BUTTON(port), (float) config->port);
276 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(receive_spam), config->receive_spam);
277 if (config->save_folder != NULL)
278 gtk_entry_set_text(GTK_ENTRY(save_folder), config->save_folder);
279 gtk_spin_button_set_value(GTK_SPIN_BUTTON(max_size), (float) config->max_size);
280 gtk_spin_button_set_value(GTK_SPIN_BUTTON(timeout), (float) config->timeout);
282 page->enable = enable;
283 page->hostname = hostname;
285 page->receive_spam = receive_spam;
286 page->save_folder = save_folder;
287 page->max_size = max_size;
288 page->timeout = timeout;
290 page->page.widget = table1;
293 static void spamassassin_destroy_widget_func(PrefsPage *_page)
295 debug_print("Destroying SpamAssassin widget\n");
298 static void spamassassin_save_func(PrefsPage *_page)
300 struct SpamAssassinPage *page = (struct SpamAssassinPage *) _page;
301 SpamAssassinConfig *config;
303 debug_print("Saving SpamAssassin Page\n");
305 config = spamassassin_get_config();
308 config->enable = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable));
311 g_free(config->hostname);
312 config->hostname = gtk_editable_get_chars(GTK_EDITABLE(page->hostname), 0, -1);
315 config->port = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->port));
318 config->receive_spam = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->receive_spam));
321 g_free(config->save_folder);
322 config->save_folder = gtk_editable_get_chars(GTK_EDITABLE(page->save_folder), 0, -1);
325 config->max_size = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->max_size));
328 config->timeout = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->timeout));
330 spamassassin_save_config();
333 static struct SpamAssassinPage spamassassin_page;
335 gint plugin_init(gchar **error)
337 if ((sylpheed_get_version() > VERSION_NUMERIC)) {
338 *error = g_strdup("Your sylpheed version is newer than the version the plugin was built with");
342 if ((sylpheed_get_version() < MAKE_NUMERIC_VERSION(0, 9, 3, 86))) {
343 *error = g_strdup("Your sylpheed version is too old");
347 spamassassin_page.page.path = _("Filtering/SpamAssassin");
348 spamassassin_page.page.create_widget = spamassassin_create_widget_func;
349 spamassassin_page.page.destroy_widget = spamassassin_destroy_widget_func;
350 spamassassin_page.page.save_page = spamassassin_save_func;
351 spamassassin_page.page.weight = 35.0;
353 prefs_gtk_register_page((PrefsPage *) &spamassassin_page);
355 debug_print("SpamAssassin GTK plugin loaded\n");
359 void plugin_done(void)
361 prefs_gtk_unregister_page((PrefsPage *) &spamassassin_page);
363 debug_print("SpamAssassin GTK plugin unloaded\n");
366 const gchar *plugin_name(void)
368 return _("SpamAssassin GTK");
371 const gchar *plugin_desc(void)
373 return _("This plugin provides a Preferences page for the SpamAssassin "
376 "You will find the options in the Other Preferences window "
377 "under Filtering/SpamAssassin.\n"
379 "With this plugin you can enable the filtering, change the "
380 "SpamAssassin server host and port, set the maximum size of "
381 "messages to be checked, (if the message is larger it will "
382 "not be checked), configure whether spam mail should be received "
383 "(default: Yes) and select the folder where spam mail will be "
387 const gchar *plugin_type(void)