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;
69 /* ------------------ code made by glade -------------------- */
82 GtkWidget *receive_spam;
84 GtkObject *max_size_adj;
86 GtkWidget *save_folder;
90 table1 = gtk_table_new(6, 3, FALSE);
91 gtk_widget_show(table1);
92 gtk_table_set_row_spacings(GTK_TABLE(table1), 4);
93 gtk_table_set_col_spacings(GTK_TABLE(table1), 8);
95 label3 = gtk_label_new(_("Enable SpamAssassin Filtering"));
96 gtk_widget_show(label3);
97 gtk_table_attach(GTK_TABLE(table1), label3, 0, 1, 0, 1,
98 (GtkAttachOptions) (GTK_FILL),
99 (GtkAttachOptions) (0), 0, 0);
100 gtk_misc_set_alignment(GTK_MISC(label3), 0, 0.5);
102 label4 = gtk_label_new(_("SpamAssassin Server (spamd)"));
103 gtk_widget_show(label4);
104 gtk_table_attach(GTK_TABLE(table1), label4, 0, 1, 1, 2,
105 (GtkAttachOptions) (GTK_FILL),
106 (GtkAttachOptions) (0), 0, 0);
107 gtk_misc_set_alignment(GTK_MISC(label4), 0, 0.5);
109 label6 = gtk_label_new(_("Maximum Message Size"));
110 gtk_widget_show(label6);
111 gtk_table_attach(GTK_TABLE(table1), label6, 0, 1, 2, 3,
112 (GtkAttachOptions) (GTK_FILL),
113 (GtkAttachOptions) (0), 0, 0);
114 gtk_misc_set_alignment(GTK_MISC(label6), 0, 0.5);
116 label8 = gtk_label_new(_("Folder for saved Spam"));
117 gtk_widget_show(label8);
118 gtk_table_attach(GTK_TABLE(table1), label8, 0, 1, 4, 5,
119 (GtkAttachOptions) (GTK_FILL),
120 (GtkAttachOptions) (0), 0, 0);
121 gtk_label_set_justify(GTK_LABEL(label8), GTK_JUSTIFY_LEFT);
122 gtk_misc_set_alignment(GTK_MISC(label8), 0, 0.5);
124 label9 = gtk_label_new(_("Receive Spam"));
125 gtk_widget_show(label9);
126 gtk_table_attach(GTK_TABLE(table1), label9, 0, 1, 3, 4,
127 (GtkAttachOptions) (GTK_FILL),
128 (GtkAttachOptions) (0), 0, 0);
129 gtk_misc_set_alignment(GTK_MISC(label9), 0, 0.5);
131 hbox1 = gtk_hbox_new(FALSE, 0);
132 gtk_widget_show(hbox1);
133 gtk_table_attach(GTK_TABLE(table1), hbox1, 1, 2, 1, 2,
134 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
135 (GtkAttachOptions) (GTK_FILL), 0, 0);
137 hostname = gtk_entry_new();
138 gtk_widget_show(hostname);
139 gtk_box_pack_start(GTK_BOX(hbox1), hostname, TRUE, TRUE, 0);
141 label5 = gtk_label_new(":");
142 gtk_widget_show(label5);
143 gtk_box_pack_start(GTK_BOX(hbox1), label5, FALSE, FALSE, 0);
144 gtk_misc_set_padding(GTK_MISC(label5), 8, 0);
146 port_adj = gtk_adjustment_new(783, 1, 65535, 1, 10, 10);
148 gtk_spin_button_new(GTK_ADJUSTMENT(port_adj), 1, 0);
149 gtk_widget_show(port);
150 gtk_box_pack_start(GTK_BOX(hbox1), port, FALSE, TRUE, 0);
151 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(port), TRUE);
153 enable = gtk_check_button_new_with_label("");
154 gtk_widget_show(enable);
155 gtk_table_attach(GTK_TABLE(table1), enable, 1, 2, 0, 1,
156 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
157 (GtkAttachOptions) (0), 0, 0);
159 receive_spam = gtk_check_button_new_with_label("");
160 gtk_widget_show(receive_spam);
161 gtk_table_attach(GTK_TABLE(table1), receive_spam, 1, 2, 3, 4,
162 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
163 (GtkAttachOptions) (0), 0, 0);
167 ("Leave empty to use the default trash folder"));
168 gtk_widget_show(label10);
169 gtk_table_attach(GTK_TABLE(table1), label10, 1, 2, 5, 6,
170 (GtkAttachOptions) (GTK_FILL),
171 (GtkAttachOptions) (0), 0, 0);
172 gtk_label_set_justify(GTK_LABEL(label10), GTK_JUSTIFY_RIGHT);
173 gtk_misc_set_alignment(GTK_MISC(label10), 1, 0.5);
175 max_size_adj = gtk_adjustment_new(250, 0, 10000, 10, 10, 10);
176 max_size = gtk_spin_button_new(GTK_ADJUSTMENT(max_size_adj), 1, 0);
177 gtk_widget_show(max_size);
178 gtk_table_attach(GTK_TABLE(table1), max_size, 1, 2, 2, 3,
179 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
180 (GtkAttachOptions) (0), 0, 0);
182 save_folder = gtk_entry_new();
183 gtk_widget_show(save_folder);
184 gtk_table_attach(GTK_TABLE(table1), save_folder, 1, 2, 4, 5,
185 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
186 (GtkAttachOptions) (0), 0, 0);
188 button4 = gtk_button_new_with_label("...");
189 gtk_widget_show(button4);
190 gtk_table_attach(GTK_TABLE(table1), button4, 2, 3, 4, 5,
191 (GtkAttachOptions) (GTK_SHRINK | GTK_FILL),
192 (GtkAttachOptions) (0), 0, 0);
194 label11 = gtk_label_new(_("kB"));
195 gtk_widget_show(label11);
196 gtk_table_attach(GTK_TABLE(table1), label11, 2, 3, 2, 3,
197 (GtkAttachOptions) (GTK_FILL),
198 (GtkAttachOptions) (0), 0, 0);
199 gtk_misc_set_alignment(GTK_MISC(label11), 0, 0.5);
200 /* --------------------------------------------------------- */
202 gtk_widget_set_usize(GTK_WIDGET(port), 64, -1);
203 gtk_signal_connect(GTK_OBJECT(button4), "released", GTK_SIGNAL_FUNC(foldersel_cb), page);
205 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable), spamassassin_enable);
206 gtk_entry_set_text(GTK_ENTRY(hostname), spamassassin_hostname);
207 gtk_spin_button_set_value(GTK_SPIN_BUTTON(port), (float) spamassassin_port);
208 gtk_spin_button_set_value(GTK_SPIN_BUTTON(max_size), (float) spamassassin_max_size);
209 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(receive_spam), spamassassin_receive_spam);
210 gtk_entry_set_text(GTK_ENTRY(save_folder), spamassassin_save_folder);
212 page->enable = enable;
213 page->hostname = hostname;
215 page->max_size = max_size;
216 page->receive_spam = receive_spam;
217 page->save_folder = save_folder;
219 page->page.widget = table1;
222 static void spamassassin_destroy_widget_func(PrefsPage *_page)
224 debug_print("Destroying SpamAssassin widget\n");
227 static void spamassassin_save_func(PrefsPage *_page)
229 struct SpamAssassinPage *page = (struct SpamAssassinPage *) _page;
232 debug_print("Saving SpamAssassin Page\n");
234 spamassassin_enable = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable));
235 if (spamassassin_hostname)
236 g_free(spamassassin_hostname);
237 spamassassin_hostname = gtk_editable_get_chars(GTK_EDITABLE(page->hostname), 0, -1);
238 tmp = gtk_editable_get_chars(GTK_EDITABLE(page->port), 0, -1);
239 spamassassin_port = atoi(tmp);
241 spamassassin_max_size = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->max_size));
242 spamassassin_receive_spam = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->receive_spam));
243 if (spamassassin_save_folder)
244 g_free(spamassassin_save_folder);
245 spamassassin_save_folder = gtk_editable_get_chars(GTK_EDITABLE(page->save_folder), 0, -1);
247 spamassassin_save_config();
250 static struct SpamAssassinPage *spamassassin_page;
252 gint plugin_init(gchar **error)
254 struct SpamAssassinPage *page;
256 page = g_new0(struct SpamAssassinPage, 1);
257 page->page.path = _("Filtering/SpamAssassin");
258 page->page.create_widget = spamassassin_create_widget_func;
259 page->page.destroy_widget = spamassassin_destroy_widget_func;
260 page->page.save_page = spamassassin_save_func;
261 prefs_gtk_register_page((PrefsPage *) page);
263 spamassassin_page = page;
265 debug_print("SpamAssassin GTK plugin loaded\n");
271 prefs_gtk_unregister_page((PrefsPage *) spamassassin_page);
272 g_free(spamassassin_page);
274 debug_print("SpamAssassin GTK plugin unloaded\n");
277 const gchar *plugin_name()
279 return "SpamAssassin GTK";
282 const gchar *plugin_desc()
284 return "This plugin provides a Preferences page for the SpamAssassin "
287 "You will find the options in the Other Preferences window "
288 "under Filtering/SpamAssassin.\n"
290 "With this plugin you can enable the filtering, change the "
291 "SpamAssassin server host and port, set the maximum size of "
292 "messages to be checked, (if the message is larger it will "
293 "not be checked), configure whether spam mail should be received "
294 "(default: Yes) and select the folder where spam mail will be "