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
48 GtkWidget *receive_spam;
49 GtkWidget *save_folder;
52 static void foldersel_cb(GtkWidget *widget, gpointer data)
54 struct SpamAssassinPage *page = (struct SpamAssassinPage *) data;
59 item = foldersel_folder_sel(NULL, FOLDER_SEL_MOVE, NULL);
60 if (item && (item_id = folder_item_get_identifier(item)) != NULL) {
61 gtk_editable_delete_text(GTK_EDITABLE(page->save_folder), 0, -1);
62 gtk_editable_insert_text(GTK_EDITABLE(page->save_folder), item_id, strlen(item_id), &newpos);
67 static void spamassassin_create_widget_func(PrefsPage * _page,
71 struct SpamAssassinPage *page = (struct SpamAssassinPage *) _page;
72 SpamAssassinConfig *config;
90 GtkWidget *receive_spam;
92 GtkWidget *save_folder;
96 GtkObject *max_size_adj;
99 table1 = gtk_table_new(6, 3, FALSE);
100 gtk_widget_show(table1);
101 gtk_container_set_border_width(GTK_CONTAINER(table1), 8);
102 gtk_table_set_row_spacings(GTK_TABLE(table1), 4);
103 gtk_table_set_col_spacings(GTK_TABLE(table1), 8);
105 label3 = gtk_label_new(_("Enable SpamAssassin Filtering"));
106 gtk_widget_show(label3);
107 gtk_table_attach(GTK_TABLE(table1), label3, 0, 1, 0, 1,
108 (GtkAttachOptions) (GTK_FILL),
109 (GtkAttachOptions) (0), 0, 0);
110 gtk_misc_set_alignment(GTK_MISC(label3), 0, 0.5);
112 label4 = gtk_label_new(_("SpamAssassin Server (spamd)"));
113 gtk_widget_show(label4);
114 gtk_table_attach(GTK_TABLE(table1), label4, 0, 1, 1, 2,
115 (GtkAttachOptions) (GTK_FILL),
116 (GtkAttachOptions) (0), 0, 0);
117 gtk_misc_set_alignment(GTK_MISC(label4), 0, 0.5);
119 label6 = gtk_label_new(_("Maximum Message Size"));
120 gtk_widget_show(label6);
121 gtk_table_attach(GTK_TABLE(table1), label6, 0, 1, 2, 3,
122 (GtkAttachOptions) (GTK_FILL),
123 (GtkAttachOptions) (0), 0, 0);
124 gtk_misc_set_alignment(GTK_MISC(label6), 0, 0.5);
126 label8 = gtk_label_new(_("Folder for saved Spam"));
127 gtk_widget_show(label8);
128 gtk_table_attach(GTK_TABLE(table1), label8, 0, 1, 4, 5,
129 (GtkAttachOptions) (GTK_FILL),
130 (GtkAttachOptions) (0), 0, 0);
131 gtk_label_set_justify(GTK_LABEL(label8), GTK_JUSTIFY_LEFT);
132 gtk_misc_set_alignment(GTK_MISC(label8), 0, 0.5);
134 label9 = gtk_label_new(_("Receive Spam"));
135 gtk_widget_show(label9);
136 gtk_table_attach(GTK_TABLE(table1), label9, 0, 1, 3, 4,
137 (GtkAttachOptions) (GTK_FILL),
138 (GtkAttachOptions) (0), 0, 0);
139 gtk_misc_set_alignment(GTK_MISC(label9), 0, 0.5);
141 hbox1 = gtk_hbox_new(FALSE, 0);
142 gtk_widget_show(hbox1);
143 gtk_table_attach(GTK_TABLE(table1), hbox1, 1, 2, 1, 2,
144 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
145 (GtkAttachOptions) (GTK_FILL), 0, 0);
147 hostname = gtk_entry_new();
148 gtk_widget_show(hostname);
149 gtk_box_pack_start(GTK_BOX(hbox1), hostname, TRUE, TRUE, 0);
151 label5 = gtk_label_new(_(":"));
152 gtk_widget_show(label5);
153 gtk_box_pack_start(GTK_BOX(hbox1), label5, FALSE, FALSE, 0);
154 gtk_misc_set_padding(GTK_MISC(label5), 8, 0);
156 port_adj = gtk_adjustment_new(783, 1, 65535, 1, 10, 10);
157 port = gtk_spin_button_new(GTK_ADJUSTMENT(port_adj), 1, 0);
158 gtk_widget_show(port);
159 gtk_box_pack_end(GTK_BOX(hbox1), port, FALSE, TRUE, 0);
160 gtk_widget_set_usize(port, 64, -2);
161 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(port), TRUE);
163 enable = gtk_check_button_new_with_label("");
164 gtk_widget_show(enable);
165 gtk_table_attach(GTK_TABLE(table1), enable, 1, 2, 0, 1,
166 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
167 (GtkAttachOptions) (0), 0, 0);
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, 3, 4,
172 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
173 (GtkAttachOptions) (0), 0, 0);
177 ("Leave empty to use the default trash folder"));
178 gtk_widget_show(label10);
179 gtk_table_attach(GTK_TABLE(table1), label10, 1, 2, 5, 6,
180 (GtkAttachOptions) (GTK_FILL),
181 (GtkAttachOptions) (0), 0, 0);
182 gtk_label_set_justify(GTK_LABEL(label10), GTK_JUSTIFY_RIGHT);
183 gtk_misc_set_alignment(GTK_MISC(label10), 1, 0.5);
185 save_folder = gtk_entry_new();
186 gtk_widget_show(save_folder);
187 gtk_table_attach(GTK_TABLE(table1), save_folder, 1, 2, 4, 5,
188 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
189 (GtkAttachOptions) (0), 0, 0);
191 button4 = gtk_button_new_with_label(_("..."));
192 gtk_widget_show(button4);
193 gtk_table_attach(GTK_TABLE(table1), button4, 2, 3, 4, 5,
194 (GtkAttachOptions) (GTK_SHRINK | GTK_FILL),
195 (GtkAttachOptions) (0), 0, 0);
197 label11 = gtk_label_new(_("kB"));
198 gtk_widget_show(label11);
199 gtk_table_attach(GTK_TABLE(table1), label11, 2, 3, 2, 3,
200 (GtkAttachOptions) (GTK_FILL),
201 (GtkAttachOptions) (0), 0, 0);
202 gtk_misc_set_alignment(GTK_MISC(label11), 0, 0.5);
204 hbox3 = gtk_hbox_new(FALSE, 0);
205 gtk_widget_show(hbox3);
206 gtk_table_attach(GTK_TABLE(table1), hbox3, 1, 2, 2, 3,
207 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
208 (GtkAttachOptions) (GTK_FILL), 0, 0);
210 max_size_adj = gtk_adjustment_new(250, 0, 10000, 10, 10, 10);
211 max_size = gtk_spin_button_new(GTK_ADJUSTMENT(max_size_adj), 1, 0);
212 gtk_widget_show(max_size);
213 gtk_box_pack_end(GTK_BOX(hbox3), max_size, FALSE, TRUE, 0);
214 gtk_widget_set_usize(max_size, 64, -2);
215 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(max_size), TRUE);
220 config = spamassassin_get_config();
222 gtk_signal_connect(GTK_OBJECT(button4), "released", GTK_SIGNAL_FUNC(foldersel_cb), page);
224 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable), config->enable);
225 if (config->hostname != NULL)
226 gtk_entry_set_text(GTK_ENTRY(hostname), config->hostname);
227 gtk_spin_button_set_value(GTK_SPIN_BUTTON(port), (float) config->port);
228 gtk_spin_button_set_value(GTK_SPIN_BUTTON(max_size), (float) config->max_size);
229 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(receive_spam), config->receive_spam);
230 if (config->save_folder != NULL)
231 gtk_entry_set_text(GTK_ENTRY(save_folder), config->save_folder);
233 page->enable = enable;
234 page->hostname = hostname;
236 page->max_size = max_size;
237 page->receive_spam = receive_spam;
238 page->save_folder = save_folder;
240 page->page.widget = table1;
243 static void spamassassin_destroy_widget_func(PrefsPage *_page)
245 debug_print("Destroying SpamAssassin widget\n");
248 static void spamassassin_save_func(PrefsPage *_page)
250 struct SpamAssassinPage *page = (struct SpamAssassinPage *) _page;
251 SpamAssassinConfig *config;
253 debug_print("Saving SpamAssassin Page\n");
255 config = spamassassin_get_config();
258 config->enable = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable));
261 g_free(config->hostname);
262 config->hostname = gtk_editable_get_chars(GTK_EDITABLE(page->hostname), 0, -1);
265 config->port = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->port));
268 config->max_size = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->max_size));
271 config->receive_spam = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->receive_spam));
274 g_free(config->save_folder);
275 config->save_folder = gtk_editable_get_chars(GTK_EDITABLE(page->save_folder), 0, -1);
277 spamassassin_save_config();
280 static struct SpamAssassinPage spamassassin_page;
282 gint plugin_init(gchar **error)
284 if ((sylpheed_get_version() > VERSION_NUMERIC)) {
285 *error = g_strdup("Your sylpheed version is newer than the version the plugin was built with");
289 if ((sylpheed_get_version() < MAKE_NUMERIC_VERSION(0, 9, 3, 86))) {
290 *error = g_strdup("Your sylpheed version is too old");
294 spamassassin_page.page.path = _("Filtering/SpamAssassin");
295 spamassassin_page.page.create_widget = spamassassin_create_widget_func;
296 spamassassin_page.page.destroy_widget = spamassassin_destroy_widget_func;
297 spamassassin_page.page.save_page = spamassassin_save_func;
298 spamassassin_page.page.weight = 35.0;
300 prefs_gtk_register_page((PrefsPage *) &spamassassin_page);
302 debug_print("SpamAssassin GTK plugin loaded\n");
306 void plugin_done(void)
308 prefs_gtk_unregister_page((PrefsPage *) &spamassassin_page);
310 debug_print("SpamAssassin GTK plugin unloaded\n");
313 const gchar *plugin_name(void)
315 return _("SpamAssassin GTK");
318 const gchar *plugin_desc(void)
320 return _("This plugin provides a Preferences page for the SpamAssassin "
323 "You will find the options in the Other Preferences window "
324 "under Filtering/SpamAssassin.\n"
326 "With this plugin you can enable the filtering, change the "
327 "SpamAssassin server host and port, set the maximum size of "
328 "messages to be checked, (if the message is larger it will "
329 "not be checked), configure whether spam mail should be received "
330 "(default: Yes) and select the folder where spam mail will be "
334 const gchar *plugin_type(void)