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,
69 struct SpamAssassinPage *page = (struct SpamAssassinPage *) _page;
70 SpamAssassinConfig *config;
88 GtkWidget *receive_spam;
90 GtkWidget *save_folder;
94 GtkObject *max_size_adj;
97 table1 = gtk_table_new(6, 3, FALSE);
98 gtk_widget_show(table1);
99 gtk_container_set_border_width(GTK_CONTAINER(table1), 8);
100 gtk_table_set_row_spacings(GTK_TABLE(table1), 4);
101 gtk_table_set_col_spacings(GTK_TABLE(table1), 8);
103 label3 = gtk_label_new(_("Enable SpamAssassin Filtering"));
104 gtk_widget_show(label3);
105 gtk_table_attach(GTK_TABLE(table1), label3, 0, 1, 0, 1,
106 (GtkAttachOptions) (GTK_FILL),
107 (GtkAttachOptions) (0), 0, 0);
108 gtk_misc_set_alignment(GTK_MISC(label3), 0, 0.5);
110 label4 = gtk_label_new(_("SpamAssassin Server (spamd)"));
111 gtk_widget_show(label4);
112 gtk_table_attach(GTK_TABLE(table1), label4, 0, 1, 1, 2,
113 (GtkAttachOptions) (GTK_FILL),
114 (GtkAttachOptions) (0), 0, 0);
115 gtk_misc_set_alignment(GTK_MISC(label4), 0, 0.5);
117 label6 = gtk_label_new(_("Maximum Message Size"));
118 gtk_widget_show(label6);
119 gtk_table_attach(GTK_TABLE(table1), label6, 0, 1, 2, 3,
120 (GtkAttachOptions) (GTK_FILL),
121 (GtkAttachOptions) (0), 0, 0);
122 gtk_misc_set_alignment(GTK_MISC(label6), 0, 0.5);
124 label8 = gtk_label_new(_("Folder for saved Spam"));
125 gtk_widget_show(label8);
126 gtk_table_attach(GTK_TABLE(table1), label8, 0, 1, 4, 5,
127 (GtkAttachOptions) (GTK_FILL),
128 (GtkAttachOptions) (0), 0, 0);
129 gtk_label_set_justify(GTK_LABEL(label8), GTK_JUSTIFY_LEFT);
130 gtk_misc_set_alignment(GTK_MISC(label8), 0, 0.5);
132 label9 = gtk_label_new(_("Receive Spam"));
133 gtk_widget_show(label9);
134 gtk_table_attach(GTK_TABLE(table1), label9, 0, 1, 3, 4,
135 (GtkAttachOptions) (GTK_FILL),
136 (GtkAttachOptions) (0), 0, 0);
137 gtk_misc_set_alignment(GTK_MISC(label9), 0, 0.5);
139 hbox1 = gtk_hbox_new(FALSE, 0);
140 gtk_widget_show(hbox1);
141 gtk_table_attach(GTK_TABLE(table1), hbox1, 1, 2, 1, 2,
142 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
143 (GtkAttachOptions) (GTK_FILL), 0, 0);
145 hostname = gtk_entry_new();
146 gtk_widget_show(hostname);
147 gtk_box_pack_start(GTK_BOX(hbox1), hostname, TRUE, TRUE, 0);
149 label5 = gtk_label_new(_(":"));
150 gtk_widget_show(label5);
151 gtk_box_pack_start(GTK_BOX(hbox1), label5, FALSE, FALSE, 0);
152 gtk_misc_set_padding(GTK_MISC(label5), 8, 0);
154 port_adj = gtk_adjustment_new(783, 1, 65535, 1, 10, 10);
155 port = gtk_spin_button_new(GTK_ADJUSTMENT(port_adj), 1, 0);
156 gtk_widget_show(port);
157 gtk_box_pack_end(GTK_BOX(hbox1), port, FALSE, TRUE, 0);
158 gtk_widget_set_usize(port, 64, -2);
159 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(port), TRUE);
161 enable = gtk_check_button_new_with_label("");
162 gtk_widget_show(enable);
163 gtk_table_attach(GTK_TABLE(table1), enable, 1, 2, 0, 1,
164 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
165 (GtkAttachOptions) (0), 0, 0);
167 receive_spam = gtk_check_button_new_with_label("");
168 gtk_widget_show(receive_spam);
169 gtk_table_attach(GTK_TABLE(table1), receive_spam, 1, 2, 3, 4,
170 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
171 (GtkAttachOptions) (0), 0, 0);
175 ("Leave empty to use the default trash folder"));
176 gtk_widget_show(label10);
177 gtk_table_attach(GTK_TABLE(table1), label10, 1, 2, 5, 6,
178 (GtkAttachOptions) (GTK_FILL),
179 (GtkAttachOptions) (0), 0, 0);
180 gtk_label_set_justify(GTK_LABEL(label10), GTK_JUSTIFY_RIGHT);
181 gtk_misc_set_alignment(GTK_MISC(label10), 1, 0.5);
183 save_folder = gtk_entry_new();
184 gtk_widget_show(save_folder);
185 gtk_table_attach(GTK_TABLE(table1), save_folder, 1, 2, 4, 5,
186 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
187 (GtkAttachOptions) (0), 0, 0);
189 button4 = gtk_button_new_with_label(_("..."));
190 gtk_widget_show(button4);
191 gtk_table_attach(GTK_TABLE(table1), button4, 2, 3, 4, 5,
192 (GtkAttachOptions) (GTK_SHRINK | GTK_FILL),
193 (GtkAttachOptions) (0), 0, 0);
195 label11 = gtk_label_new(_("kB"));
196 gtk_widget_show(label11);
197 gtk_table_attach(GTK_TABLE(table1), label11, 2, 3, 2, 3,
198 (GtkAttachOptions) (GTK_FILL),
199 (GtkAttachOptions) (0), 0, 0);
200 gtk_misc_set_alignment(GTK_MISC(label11), 0, 0.5);
202 hbox3 = gtk_hbox_new(FALSE, 0);
203 gtk_widget_show(hbox3);
204 gtk_table_attach(GTK_TABLE(table1), hbox3, 1, 2, 2, 3,
205 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
206 (GtkAttachOptions) (GTK_FILL), 0, 0);
208 max_size_adj = gtk_adjustment_new(250, 0, 10000, 10, 10, 10);
209 max_size = gtk_spin_button_new(GTK_ADJUSTMENT(max_size_adj), 1, 0);
210 gtk_widget_show(max_size);
211 gtk_box_pack_end(GTK_BOX(hbox3), max_size, FALSE, TRUE, 0);
212 gtk_widget_set_usize(max_size, 64, -2);
213 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(max_size), TRUE);
218 config = spamassassin_get_config();
220 gtk_signal_connect(GTK_OBJECT(button4), "released", GTK_SIGNAL_FUNC(foldersel_cb), page);
222 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable), config->enable);
223 if (config->hostname != NULL)
224 gtk_entry_set_text(GTK_ENTRY(hostname), config->hostname);
225 gtk_spin_button_set_value(GTK_SPIN_BUTTON(port), (float) config->port);
226 gtk_spin_button_set_value(GTK_SPIN_BUTTON(max_size), (float) config->max_size);
227 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(receive_spam), config->receive_spam);
228 if (config->save_folder != NULL)
229 gtk_entry_set_text(GTK_ENTRY(save_folder), config->save_folder);
231 page->enable = enable;
232 page->hostname = hostname;
234 page->max_size = max_size;
235 page->receive_spam = receive_spam;
236 page->save_folder = save_folder;
238 page->page.widget = table1;
241 static void spamassassin_destroy_widget_func(PrefsPage *_page)
243 debug_print("Destroying SpamAssassin widget\n");
246 static void spamassassin_save_func(PrefsPage *_page)
248 struct SpamAssassinPage *page = (struct SpamAssassinPage *) _page;
249 SpamAssassinConfig *config;
251 debug_print("Saving SpamAssassin Page\n");
253 config = spamassassin_get_config();
256 config->enable = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable));
259 g_free(config->hostname);
260 config->hostname = gtk_editable_get_chars(GTK_EDITABLE(page->hostname), 0, -1);
263 config->port = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->port));
266 config->max_size = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->max_size));
269 config->receive_spam = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->receive_spam));
272 g_free(config->save_folder);
273 config->save_folder = gtk_editable_get_chars(GTK_EDITABLE(page->save_folder), 0, -1);
275 spamassassin_save_config();
278 static struct SpamAssassinPage spamassassin_page;
280 gint plugin_init(gchar **error)
282 spamassassin_page.page.path = "Filtering/SpamAssassin";
283 spamassassin_page.page.create_widget = spamassassin_create_widget_func;
284 spamassassin_page.page.destroy_widget = spamassassin_destroy_widget_func;
285 spamassassin_page.page.save_page = spamassassin_save_func;
287 prefs_gtk_register_page((PrefsPage *) &spamassassin_page);
289 debug_print("SpamAssassin GTK plugin loaded\n");
293 void plugin_done(void)
295 prefs_gtk_unregister_page((PrefsPage *) &spamassassin_page);
297 debug_print("SpamAssassin GTK plugin unloaded\n");
300 const gchar *plugin_name(void)
302 return _("SpamAssassin GTK");
305 const gchar *plugin_desc(void)
307 return _("This plugin provides a Preferences page for the SpamAssassin "
310 "You will find the options in the Other Preferences window "
311 "under Filtering/SpamAssassin.\n"
313 "With this plugin you can enable the filtering, change the "
314 "SpamAssassin server host and port, set the maximum size of "
315 "messages to be checked, (if the message is larger it will "
316 "not be checked), configure whether spam mail should be received "
317 "(default: Yes) and select the folder where spam mail will be "
321 const gchar *plugin_type(void)