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.
31 #include "common/utils.h"
34 #include "prefs_gtk.h"
35 #include "foldersel.h"
36 #include "spamassassin.h"
38 struct SpamAssassinPage
46 GtkWidget *receive_spam;
47 GtkWidget *save_folder;
50 static void foldersel_cb(GtkWidget *widget, gpointer data)
52 struct SpamAssassinPage *page = (struct SpamAssassinPage *) data;
57 item = foldersel_folder_sel(NULL, FOLDER_SEL_MOVE, NULL);
58 if (item && (item_id = folder_item_get_identifier(item)) != NULL) {
59 gtk_editable_delete_text(GTK_EDITABLE(page->save_folder), 0, -1);
60 gtk_editable_insert_text(GTK_EDITABLE(page->save_folder), item_id, strlen(item_id), &newpos);
65 static void spamassassin_create_widget_func(PrefsPage * _page, GtkWindow *window, gpointer data)
67 struct SpamAssassinPage *page = (struct SpamAssassinPage *) _page;
68 SpamAssassinConfig *config;
70 /* ------------------ code made by glade -------------------- */
84 GtkWidget *receive_spam;
86 GtkObject *max_size_adj;
88 GtkWidget *save_folder;
92 table1 = gtk_table_new(6, 3, FALSE);
93 gtk_widget_show(table1);
94 gtk_table_set_row_spacings(GTK_TABLE(table1), 4);
95 gtk_table_set_col_spacings(GTK_TABLE(table1), 8);
97 label3 = gtk_label_new(_("Enable SpamAssassin Filtering"));
98 gtk_widget_show(label3);
99 gtk_table_attach(GTK_TABLE(table1), label3, 0, 1, 0, 1,
100 (GtkAttachOptions) (GTK_FILL),
101 (GtkAttachOptions) (0), 0, 0);
102 gtk_misc_set_alignment(GTK_MISC(label3), 0, 0.5);
104 label4 = gtk_label_new(_("SpamAssassin Server (spamd)"));
105 gtk_widget_show(label4);
106 gtk_table_attach(GTK_TABLE(table1), label4, 0, 1, 1, 2,
107 (GtkAttachOptions) (GTK_FILL),
108 (GtkAttachOptions) (0), 0, 0);
109 gtk_misc_set_alignment(GTK_MISC(label4), 0, 0.5);
111 hbox1 = gtk_hbox_new(FALSE, 0);
112 gtk_widget_show(hbox1);
113 gtk_table_attach(GTK_TABLE(table1), hbox1, 1, 2, 1, 2,
114 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
115 (GtkAttachOptions) (GTK_FILL), 0, 0);
117 hostname = gtk_entry_new();
118 gtk_widget_show(hostname);
119 gtk_box_pack_start(GTK_BOX(hbox1), hostname, TRUE, TRUE, 0);
121 label5 = gtk_label_new(":");
122 gtk_widget_show(label5);
123 gtk_box_pack_start(GTK_BOX(hbox1), label5, FALSE, FALSE, 0);
124 gtk_misc_set_padding(GTK_MISC(label5), 8, 0);
126 port_adj = gtk_adjustment_new(783, 1, 65535, 1, 10, 10);
128 gtk_spin_button_new(GTK_ADJUSTMENT(port_adj), 1, 0);
129 gtk_widget_show(port);
130 gtk_box_pack_start(GTK_BOX(hbox1), port, FALSE, TRUE, 0);
131 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(port), TRUE);
133 label6 = gtk_label_new(_("Maximum Message Size"));
134 gtk_widget_show(label6);
135 gtk_table_attach(GTK_TABLE(table1), label6, 0, 1, 2, 3,
136 (GtkAttachOptions) (GTK_FILL),
137 (GtkAttachOptions) (0), 0, 0);
138 gtk_misc_set_alignment(GTK_MISC(label6), 0, 0.5);
140 hbox2 = gtk_hbox_new (FALSE, 0);
141 gtk_widget_show (hbox2);
142 gtk_table_attach (GTK_TABLE (table1), hbox2, 1, 2, 2, 3,
143 (GtkAttachOptions) (GTK_FILL),
144 (GtkAttachOptions) (GTK_FILL), 0, 0);
146 max_size_adj = gtk_adjustment_new (250, 0, 10000, 10, 10, 10);
147 max_size = gtk_spin_button_new (GTK_ADJUSTMENT (max_size_adj), 1, 0);
148 gtk_widget_show (max_size);
149 gtk_box_pack_start (GTK_BOX (hbox2), max_size, FALSE, FALSE, 0);
151 label11 = gtk_label_new ("kB");
152 gtk_widget_show (label11);
153 gtk_box_pack_start (GTK_BOX (hbox2), label11, FALSE, FALSE, 0);
155 label8 = gtk_label_new(_("Folder for saved Spam"));
156 gtk_widget_show(label8);
157 gtk_table_attach(GTK_TABLE(table1), label8, 0, 1, 4, 5,
158 (GtkAttachOptions) (GTK_FILL),
159 (GtkAttachOptions) (0), 0, 0);
160 gtk_label_set_justify(GTK_LABEL(label8), GTK_JUSTIFY_LEFT);
161 gtk_misc_set_alignment(GTK_MISC(label8), 0, 0.5);
163 label9 = gtk_label_new(_("Receive Spam"));
164 gtk_widget_show(label9);
165 gtk_table_attach(GTK_TABLE(table1), label9, 0, 1, 3, 4,
166 (GtkAttachOptions) (GTK_FILL),
167 (GtkAttachOptions) (0), 0, 0);
168 gtk_misc_set_alignment(GTK_MISC(label9), 0, 0.5);
170 enable = gtk_check_button_new_with_label("");
171 gtk_widget_show(enable);
172 gtk_table_attach(GTK_TABLE(table1), enable, 1, 2, 0, 1,
173 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
174 (GtkAttachOptions) (0), 0, 0);
176 receive_spam = gtk_check_button_new_with_label("");
177 gtk_widget_show(receive_spam);
178 gtk_table_attach(GTK_TABLE(table1), receive_spam, 1, 2, 3, 4,
179 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
180 (GtkAttachOptions) (0), 0, 0);
184 ("Leave empty to use the default trash folder"));
185 gtk_widget_show(label10);
186 gtk_table_attach(GTK_TABLE(table1), label10, 1, 2, 5, 6,
187 (GtkAttachOptions) (GTK_FILL),
188 (GtkAttachOptions) (0), 0, 0);
189 gtk_label_set_justify(GTK_LABEL(label10), GTK_JUSTIFY_RIGHT);
190 gtk_misc_set_alignment(GTK_MISC(label10), 1, 0.5);
192 save_folder = gtk_entry_new();
193 gtk_widget_show(save_folder);
194 gtk_table_attach(GTK_TABLE(table1), save_folder, 1, 2, 4, 5,
195 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
196 (GtkAttachOptions) (0), 0, 0);
198 button4 = gtk_button_new_with_label("...");
199 gtk_widget_show(button4);
200 gtk_table_attach(GTK_TABLE(table1), button4, 2, 3, 4, 5,
201 (GtkAttachOptions) (GTK_SHRINK | GTK_FILL),
202 (GtkAttachOptions) (0), 0, 0);
203 /* --------------------------------------------------------- */
205 config = spamassassin_get_config();
207 gtk_widget_set_usize(GTK_WIDGET(port), 64, -1);
208 gtk_signal_connect(GTK_OBJECT(button4), "released", GTK_SIGNAL_FUNC(foldersel_cb), page);
210 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable), config->enable);
211 if (config->hostname != NULL)
212 gtk_entry_set_text(GTK_ENTRY(hostname), config->hostname);
213 gtk_spin_button_set_value(GTK_SPIN_BUTTON(port), (float) config->port);
214 gtk_spin_button_set_value(GTK_SPIN_BUTTON(max_size), (float) config->max_size);
215 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(receive_spam), config->receive_spam);
216 if (config->save_folder != NULL)
217 gtk_entry_set_text(GTK_ENTRY(save_folder), config->save_folder);
219 page->enable = enable;
220 page->hostname = hostname;
222 page->max_size = max_size;
223 page->receive_spam = receive_spam;
224 page->save_folder = save_folder;
226 page->page.widget = table1;
229 static void spamassassin_destroy_widget_func(PrefsPage *_page)
231 debug_print("Destroying SpamAssassin widget\n");
234 static void spamassassin_save_func(PrefsPage *_page)
236 struct SpamAssassinPage *page = (struct SpamAssassinPage *) _page;
237 SpamAssassinConfig *config;
239 debug_print("Saving SpamAssassin Page\n");
241 config = spamassassin_get_config();
244 config->enable = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable));
247 g_free(config->hostname);
248 config->hostname = gtk_editable_get_chars(GTK_EDITABLE(page->hostname), 0, -1);
251 config->port = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->port));
254 config->max_size = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->max_size));
257 config->receive_spam = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->receive_spam));
260 g_free(config->save_folder);
261 config->save_folder = gtk_editable_get_chars(GTK_EDITABLE(page->save_folder), 0, -1);
263 spamassassin_save_config();
266 static struct SpamAssassinPage spamassassin_page;
268 gint plugin_init(gchar **error)
270 spamassassin_page.page.path = "Filtering/SpamAssassin";
271 spamassassin_page.page.create_widget = spamassassin_create_widget_func;
272 spamassassin_page.page.destroy_widget = spamassassin_destroy_widget_func;
273 spamassassin_page.page.save_page = spamassassin_save_func;
275 prefs_gtk_register_page((PrefsPage *) &spamassassin_page);
277 debug_print("SpamAssassin GTK plugin loaded\n");
281 void plugin_done(void)
283 prefs_gtk_unregister_page((PrefsPage *) &spamassassin_page);
285 debug_print("SpamAssassin GTK plugin unloaded\n");
288 const gchar *plugin_name(void)
290 return "SpamAssassin GTK";
293 const gchar *plugin_desc(void)
295 return "This plugin provides a Preferences page for the SpamAssassin "
298 "You will find the options in the Other Preferences window "
299 "under Filtering/SpamAssassin.\n"
301 "With this plugin you can enable the filtering, change the "
302 "SpamAssassin server host and port, set the maximum size of "
303 "messages to be checked, (if the message is larger it will "
304 "not be checked), configure whether spam mail should be received "
305 "(default: Yes) and select the folder where spam mail will be "
309 const gchar *plugin_type(void)