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 -------------------- */
83 GtkWidget *receive_spam;
85 GtkObject *max_size_adj;
87 GtkWidget *save_folder;
91 table1 = gtk_table_new(6, 3, FALSE);
92 gtk_widget_show(table1);
93 gtk_table_set_row_spacings(GTK_TABLE(table1), 4);
94 gtk_table_set_col_spacings(GTK_TABLE(table1), 8);
96 label3 = gtk_label_new(_("Enable SpamAssassin Filtering"));
97 gtk_widget_show(label3);
98 gtk_table_attach(GTK_TABLE(table1), label3, 0, 1, 0, 1,
99 (GtkAttachOptions) (GTK_FILL),
100 (GtkAttachOptions) (0), 0, 0);
101 gtk_misc_set_alignment(GTK_MISC(label3), 0, 0.5);
103 label4 = gtk_label_new(_("SpamAssassin Server (spamd)"));
104 gtk_widget_show(label4);
105 gtk_table_attach(GTK_TABLE(table1), label4, 0, 1, 1, 2,
106 (GtkAttachOptions) (GTK_FILL),
107 (GtkAttachOptions) (0), 0, 0);
108 gtk_misc_set_alignment(GTK_MISC(label4), 0, 0.5);
110 label6 = gtk_label_new(_("Maximum Message Size"));
111 gtk_widget_show(label6);
112 gtk_table_attach(GTK_TABLE(table1), label6, 0, 1, 2, 3,
113 (GtkAttachOptions) (GTK_FILL),
114 (GtkAttachOptions) (0), 0, 0);
115 gtk_misc_set_alignment(GTK_MISC(label6), 0, 0.5);
117 label8 = gtk_label_new(_("Folder for saved Spam"));
118 gtk_widget_show(label8);
119 gtk_table_attach(GTK_TABLE(table1), label8, 0, 1, 4, 5,
120 (GtkAttachOptions) (GTK_FILL),
121 (GtkAttachOptions) (0), 0, 0);
122 gtk_label_set_justify(GTK_LABEL(label8), GTK_JUSTIFY_LEFT);
123 gtk_misc_set_alignment(GTK_MISC(label8), 0, 0.5);
125 label9 = gtk_label_new(_("Receive Spam"));
126 gtk_widget_show(label9);
127 gtk_table_attach(GTK_TABLE(table1), label9, 0, 1, 3, 4,
128 (GtkAttachOptions) (GTK_FILL),
129 (GtkAttachOptions) (0), 0, 0);
130 gtk_misc_set_alignment(GTK_MISC(label9), 0, 0.5);
132 hbox1 = gtk_hbox_new(FALSE, 0);
133 gtk_widget_show(hbox1);
134 gtk_table_attach(GTK_TABLE(table1), hbox1, 1, 2, 1, 2,
135 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
136 (GtkAttachOptions) (GTK_FILL), 0, 0);
138 hostname = gtk_entry_new();
139 gtk_widget_show(hostname);
140 gtk_box_pack_start(GTK_BOX(hbox1), hostname, TRUE, TRUE, 0);
142 label5 = gtk_label_new(":");
143 gtk_widget_show(label5);
144 gtk_box_pack_start(GTK_BOX(hbox1), label5, FALSE, FALSE, 0);
145 gtk_misc_set_padding(GTK_MISC(label5), 8, 0);
147 port_adj = gtk_adjustment_new(783, 1, 65535, 1, 10, 10);
149 gtk_spin_button_new(GTK_ADJUSTMENT(port_adj), 1, 0);
150 gtk_widget_show(port);
151 gtk_box_pack_start(GTK_BOX(hbox1), port, FALSE, TRUE, 0);
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);
160 receive_spam = gtk_check_button_new_with_label("");
161 gtk_widget_show(receive_spam);
162 gtk_table_attach(GTK_TABLE(table1), receive_spam, 1, 2, 3, 4,
163 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
164 (GtkAttachOptions) (0), 0, 0);
168 ("Leave empty to use the default trash folder"));
169 gtk_widget_show(label10);
170 gtk_table_attach(GTK_TABLE(table1), label10, 1, 2, 5, 6,
171 (GtkAttachOptions) (GTK_FILL),
172 (GtkAttachOptions) (0), 0, 0);
173 gtk_label_set_justify(GTK_LABEL(label10), GTK_JUSTIFY_RIGHT);
174 gtk_misc_set_alignment(GTK_MISC(label10), 1, 0.5);
176 max_size_adj = gtk_adjustment_new(250, 0, 10000, 10, 10, 10);
177 max_size = gtk_spin_button_new(GTK_ADJUSTMENT(max_size_adj), 1, 0);
178 gtk_widget_show(max_size);
179 gtk_table_attach(GTK_TABLE(table1), max_size, 1, 2, 2, 3,
180 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
181 (GtkAttachOptions) (0), 0, 0);
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);
201 /* --------------------------------------------------------- */
203 config = spamassassin_get_config();
205 gtk_widget_set_usize(GTK_WIDGET(port), 64, -1);
206 gtk_signal_connect(GTK_OBJECT(button4), "released", GTK_SIGNAL_FUNC(foldersel_cb), page);
208 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable), config->enable);
209 if (config->hostname != NULL)
210 gtk_entry_set_text(GTK_ENTRY(hostname), config->hostname);
211 gtk_spin_button_set_value(GTK_SPIN_BUTTON(port), (float) config->port);
212 gtk_spin_button_set_value(GTK_SPIN_BUTTON(max_size), (float) config->max_size);
213 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(receive_spam), config->receive_spam);
214 if (config->save_folder != NULL)
215 gtk_entry_set_text(GTK_ENTRY(save_folder), config->save_folder);
217 page->enable = enable;
218 page->hostname = hostname;
220 page->max_size = max_size;
221 page->receive_spam = receive_spam;
222 page->save_folder = save_folder;
224 page->page.widget = table1;
227 static void spamassassin_destroy_widget_func(PrefsPage *_page)
229 debug_print("Destroying SpamAssassin widget\n");
232 static void spamassassin_save_func(PrefsPage *_page)
234 struct SpamAssassinPage *page = (struct SpamAssassinPage *) _page;
235 SpamAssassinConfig *config;
237 debug_print("Saving SpamAssassin Page\n");
239 config = spamassassin_get_config();
242 config->enable = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable));
245 g_free(config->hostname);
246 config->hostname = gtk_editable_get_chars(GTK_EDITABLE(page->hostname), 0, -1);
249 config->port = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->port));
252 config->max_size = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->max_size));
255 config->receive_spam = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->receive_spam));
258 g_free(config->save_folder);
259 config->save_folder = gtk_editable_get_chars(GTK_EDITABLE(page->save_folder), 0, -1);
261 spamassassin_save_config();
264 static struct SpamAssassinPage spamassassin_page;
266 gint plugin_init(gchar **error)
268 spamassassin_page.page.path = "Filtering/SpamAssassin";
269 spamassassin_page.page.create_widget = spamassassin_create_widget_func;
270 spamassassin_page.page.destroy_widget = spamassassin_destroy_widget_func;
271 spamassassin_page.page.save_page = spamassassin_save_func;
273 prefs_gtk_register_page((PrefsPage *) &spamassassin_page);
275 debug_print("SpamAssassin GTK plugin loaded\n");
281 prefs_gtk_unregister_page((PrefsPage *) &spamassassin_page);
283 debug_print("SpamAssassin GTK plugin unloaded\n");
286 const gchar *plugin_name()
288 return "SpamAssassin GTK";
291 const gchar *plugin_desc()
293 return "This plugin provides a Preferences page for the SpamAssassin "
296 "You will find the options in the Other Preferences window "
297 "under Filtering/SpamAssassin.\n"
299 "With this plugin you can enable the filtering, change the "
300 "SpamAssassin server host and port, set the maximum size of "
301 "messages to be checked, (if the message is larger it will "
302 "not be checked), configure whether spam mail should be received "
303 "(default: Yes) and select the folder where spam mail will be "