bcd7d4587b80a5603a65d4d7e90d0de52cfbc013
[claws.git] / src / prefs_folder_item.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
4  *
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 3 of the License, or
8  * (at your option) any later version.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 /* alfons - all folder item specific settings should migrate into 
21  * folderlist.xml!!! the old folderitemrc file will only serve for a few 
22  * versions (for compatibility) */
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27
28 #include "defs.h"
29
30 #include <glib.h>
31 #include <glib/gi18n.h>
32 #include "folder.h"
33 #include "alertpanel.h"
34 #include "prefs_folder_item.h"
35 #include "folderview.h"
36 #include "folder.h"
37 #include "summaryview.h"
38 #include "menu.h"
39 #include "account.h"
40 #include "prefs_gtk.h"
41 #include "manage_window.h"
42 #include "utils.h"
43 #include "addr_compl.h"
44 #include "prefs_common.h"
45 #include "gtkutils.h"
46 #include "filtering.h"
47 #include "folder_item_prefs.h"
48 #include "gtk/colorsel.h"
49 #include "string_match.h"
50 #include "quote_fmt.h"
51 #include "combobox.h"
52
53 #if USE_ASPELL
54 #include "gtkaspell.h"
55 #endif
56
57 #define ASSIGN_STRING(string, value) \
58         { \
59                 g_free(string); \
60                 string = (value); \
61         }
62
63 typedef struct _FolderItemGeneralPage FolderItemGeneralPage;
64 typedef struct _FolderItemComposePage FolderItemComposePage;
65 typedef struct _FolderItemTemplatesPage FolderItemTemplatesPage;
66 static gboolean can_save = TRUE;
67
68 struct _FolderItemGeneralPage
69 {
70         PrefsPage page;
71
72         FolderItem *item;
73
74         GtkWidget *table;
75         GtkWidget *no_save_warning;
76         GtkWidget *folder_type;
77         GtkWidget *checkbtn_simplify_subject;
78         GtkWidget *entry_simplify_subject;
79         GtkWidget *entry_regexp_test_string;
80         GtkWidget *entry_regexp_test_result;
81         GtkWidget *checkbtn_folder_chmod;
82         GtkWidget *entry_folder_chmod;
83         GtkWidget *folder_color_btn;
84         GtkWidget *checkbtn_enable_processing;
85         GtkWidget *checkbtn_newmailcheck;
86         GtkWidget *checkbtn_offlinesync;
87         GtkWidget *label_offlinesync;
88         GtkWidget *entry_offlinesync;
89         GtkWidget *label_end_offlinesync;
90         GtkWidget *checkbtn_remove_old_offlinesync;
91         
92         /* apply to sub folders */
93         GtkWidget *simplify_subject_rec_checkbtn;
94         GtkWidget *folder_chmod_rec_checkbtn;
95         GtkWidget *folder_color_rec_checkbtn;
96         GtkWidget *enable_processing_rec_checkbtn;
97         GtkWidget *newmailcheck_rec_checkbtn;
98         GtkWidget *offlinesync_rec_checkbtn;
99
100         gint       folder_color;
101 };
102
103 struct _FolderItemComposePage
104 {
105         PrefsPage page;
106
107         FolderItem *item;
108
109         GtkWidget *window;
110         GtkWidget *table;
111         GtkWidget *no_save_warning;
112         GtkWidget *checkbtn_request_return_receipt;
113         GtkWidget *checkbtn_save_copy_to_folder;
114         GtkWidget *checkbtn_default_to;
115         GtkWidget *entry_default_to;
116         GtkWidget *checkbtn_default_reply_to;
117         GtkWidget *entry_default_reply_to;
118         GtkWidget *checkbtn_enable_default_account;
119         GtkWidget *optmenu_default_account;
120 #if USE_ASPELL
121         GtkWidget *checkbtn_enable_default_dictionary;
122         GtkWidget *checkbtn_enable_default_alt_dictionary;
123         GtkWidget *optmenu_default_dictionary;
124         GtkWidget *optmenu_default_alt_dictionary;
125 #endif
126
127         /* apply to sub folders */
128         GtkWidget *request_return_receipt_rec_checkbtn;
129         GtkWidget *save_copy_to_folder_rec_checkbtn;
130         GtkWidget *default_to_rec_checkbtn;
131         GtkWidget *default_reply_to_rec_checkbtn;
132         GtkWidget *default_account_rec_checkbtn;
133 #if USE_ASPELL
134         GtkWidget *default_dictionary_rec_checkbtn;
135         GtkWidget *default_alt_dictionary_rec_checkbtn;
136 #endif
137 };
138
139 struct _FolderItemTemplatesPage
140 {
141         PrefsPage page;
142
143         FolderItem *item;
144
145         GtkWidget *window;
146         GtkWidget *table;
147         GtkWidget *checkbtn_compose_with_format;
148         GtkWidget *compose_subject_format;
149         GtkWidget *compose_body_format;
150         GtkWidget *checkbtn_reply_with_format;
151         GtkWidget *reply_quotemark;
152         GtkWidget *reply_body_format;
153         GtkWidget *checkbtn_forward_with_format;
154         GtkWidget *forward_quotemark;
155         GtkWidget *forward_body_format;
156
157         /* apply to sub folders */
158         GtkWidget *new_msg_format_rec_checkbtn;
159         GtkWidget *reply_format_rec_checkbtn;
160         GtkWidget *forward_format_rec_checkbtn;
161 };
162
163
164 static void general_save_folder_prefs(FolderItem *folder, FolderItemGeneralPage *page);
165 static void compose_save_folder_prefs(FolderItem *folder, FolderItemComposePage *page);
166 static void templates_save_folder_prefs(FolderItem *folder, FolderItemTemplatesPage *page);
167
168 static gboolean general_save_recurse_func(GNode *node, gpointer data);
169 static gboolean compose_save_recurse_func(GNode *node, gpointer data);
170 static gboolean templates_save_recurse_func(GNode *node, gpointer data);
171
172 static gint prefs_folder_item_chmod_mode                (gchar *folder_chmod);
173
174 static void folder_color_set_dialog(GtkWidget *widget, gpointer data);
175 static void clean_cache_cb(GtkWidget *widget, gpointer data);
176 static void folder_regexp_test_cb(GtkWidget *widget, gpointer data);
177 static void folder_regexp_set_subject_example_cb(GtkWidget *widget, gpointer data);
178
179 #define SAFE_STRING(str) \
180         (str) ? (str) : ""
181
182 static void prefs_folder_item_general_create_widget_func(PrefsPage * page_,
183                                                    GtkWindow * window,
184                                                    gpointer data)
185 {
186         FolderItemGeneralPage *page = (FolderItemGeneralPage *) page_;
187         FolderItem *item = (FolderItem *) data;
188         guint rowcount;
189
190         GtkWidget *table;
191         GtkWidget *hbox, *hbox2, *hbox_spc;
192         GtkWidget *label;
193         
194         GtkListStore *folder_type_menu;
195         GtkWidget *folder_type;
196         GtkTreeIter iter;
197         GtkWidget *dummy_checkbtn, *clean_cache_btn;
198         SpecialFolderItemType type;
199         
200         GtkWidget *no_save_warning = NULL;
201         GtkWidget *checkbtn_simplify_subject;
202         GtkWidget *entry_simplify_subject;
203         GtkWidget *hbox_regexp;
204         GtkWidget *label_regexp_test;
205         GtkWidget *entry_regexp_test_string;
206         GtkWidget *left_arrow;
207         GtkWidget *entry_regexp_test_result;
208
209         GtkWidget *checkbtn_folder_chmod;
210         GtkWidget *entry_folder_chmod;
211         GtkWidget *folder_color;
212         GtkWidget *folder_color_btn;
213         GtkWidget *checkbtn_enable_processing;
214         GtkWidget *checkbtn_newmailcheck;
215         GtkWidget *checkbtn_offlinesync;
216         GtkWidget *label_offlinesync;
217         GtkWidget *entry_offlinesync;
218         GtkWidget *label_end_offlinesync;
219         GtkWidget *checkbtn_remove_old_offlinesync;
220
221         GtkWidget *simplify_subject_rec_checkbtn;
222         GtkWidget *folder_chmod_rec_checkbtn;
223         GtkWidget *folder_color_rec_checkbtn;
224         GtkWidget *enable_processing_rec_checkbtn;
225         GtkWidget *newmailcheck_rec_checkbtn;
226         GtkWidget *offlinesync_rec_checkbtn;
227         GtkTooltips *tooltips;
228
229         tooltips = gtk_tooltips_new();
230         page->item         = item;
231
232         /* Table */
233         table = gtk_table_new(10, 4, FALSE);
234         gtk_container_set_border_width (GTK_CONTAINER (table), VBOX_BORDER);
235         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
236         gtk_table_set_col_spacings(GTK_TABLE(table), 4);
237         rowcount = 0;
238
239         if (!can_save) {
240                 no_save_warning = gtk_label_new(
241                         _("<i>These preferences will not be saved as this folder "
242                         "is a top-level one. However you can use them to set them "
243                         "to the whole mailbox tree using \"Apply to subfolders\".</i>"));
244                 gtk_label_set_use_markup(GTK_LABEL(no_save_warning), TRUE);
245                 gtk_label_set_line_wrap(GTK_LABEL(no_save_warning), TRUE);
246                 gtk_misc_set_alignment(GTK_MISC(no_save_warning), 0.0, 0.5);
247                 gtk_table_attach(GTK_TABLE(table), no_save_warning, 0, 4,
248                          rowcount, rowcount + 1, GTK_FILL, 0, 0, 0);
249                 rowcount++;
250         }
251         
252         /* Apply to subfolders */
253         label = gtk_label_new(_("Apply to\nsubfolders"));
254         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
255         gtk_table_attach(GTK_TABLE(table), label, 3, 4,
256                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
257         rowcount++;
258
259         /* folder_type */
260         folder_type = gtkut_sc_combobox_create(NULL, FALSE);
261         gtk_widget_show (folder_type);
262
263         type = F_NORMAL;
264         if (item->stype == F_INBOX)
265                 type = F_INBOX;
266         else if (folder_has_parent_of_type(item, F_OUTBOX))
267                 type = F_OUTBOX;
268         else if (folder_has_parent_of_type(item, F_DRAFT))
269                 type = F_DRAFT;
270         else if (folder_has_parent_of_type(item, F_QUEUE))
271                 type = F_QUEUE;
272         else if (folder_has_parent_of_type(item, F_TRASH))
273                 type = F_TRASH;
274
275         folder_type_menu = GTK_LIST_STORE(gtk_combo_box_get_model(
276                                 GTK_COMBO_BOX(folder_type)));
277
278         COMBOBOX_ADD (folder_type_menu, _("Normal"),  F_NORMAL);
279         COMBOBOX_ADD (folder_type_menu, _("Inbox"),  F_INBOX);
280         COMBOBOX_ADD (folder_type_menu, _("Outbox"),  F_OUTBOX);
281         COMBOBOX_ADD (folder_type_menu, _("Drafts"),  F_DRAFT);
282         COMBOBOX_ADD (folder_type_menu, _("Queue"),  F_QUEUE);
283         COMBOBOX_ADD (folder_type_menu, _("Trash"),  F_TRASH);
284
285         combobox_select_by_data(GTK_COMBO_BOX(folder_type), type);
286
287         dummy_checkbtn = gtk_check_button_new();
288         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dummy_checkbtn), type != F_INBOX);
289         gtk_widget_set_sensitive(dummy_checkbtn, FALSE);
290
291         if (type == item->stype && type == F_NORMAL)
292                 gtk_widget_set_sensitive(folder_type, TRUE);
293         else
294                 gtk_widget_set_sensitive(folder_type, FALSE);
295
296         label = gtk_label_new(_("Folder type"));
297         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
298         gtk_table_attach(GTK_TABLE(table), label, 0, 1, 
299                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
300         gtk_table_attach(GTK_TABLE(table), folder_type, 1, 2, 
301                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
302         gtk_table_attach(GTK_TABLE(table), dummy_checkbtn, 3, 4, 
303                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
304
305         rowcount++;
306
307         /* Simplify Subject */
308         checkbtn_simplify_subject = gtk_check_button_new_with_label(_("Simplify Subject RegExp"));
309         gtk_table_attach(GTK_TABLE(table), checkbtn_simplify_subject, 0, 1, 
310                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
311         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_simplify_subject), 
312                                      item->prefs->enable_simplify_subject);
313
314         g_signal_connect(G_OBJECT(checkbtn_simplify_subject), "toggled",
315                         G_CALLBACK(folder_regexp_set_subject_example_cb), page);
316
317         entry_simplify_subject = gtk_entry_new();
318         gtk_table_attach(GTK_TABLE(table), entry_simplify_subject, 1, 3, 
319                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
320         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_simplify_subject);
321         gtk_entry_set_text(GTK_ENTRY(entry_simplify_subject), 
322                            SAFE_STRING(item->prefs->simplify_subject_regexp));
323
324         g_signal_connect(G_OBJECT(entry_simplify_subject), "changed",
325                         G_CALLBACK(folder_regexp_test_cb), page);
326
327         simplify_subject_rec_checkbtn = gtk_check_button_new();
328         gtk_table_attach(GTK_TABLE(table), simplify_subject_rec_checkbtn, 3, 4, 
329                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
330
331         rowcount++;
332
333         /* Test RegExp */
334         label_regexp_test = gtk_label_new(_("Test RegExp"));
335         gtk_misc_set_alignment(GTK_MISC(label_regexp_test), 0, 0.5);
336         gtk_table_attach(GTK_TABLE(table), label_regexp_test, 0, 1, 
337                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
338         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, label_regexp_test);
339
340         entry_regexp_test_string = gtk_entry_new();
341         gtk_table_attach(GTK_TABLE(table), entry_regexp_test_string, 1, 2, 
342                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
343         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_regexp_test_string);
344
345         g_signal_connect(G_OBJECT(entry_regexp_test_string), "changed",
346                         G_CALLBACK(folder_regexp_test_cb), page);
347
348         hbox_regexp = gtk_hbox_new (FALSE, 4);
349         gtk_widget_show (hbox_regexp);
350         gtk_table_attach(GTK_TABLE(table), hbox_regexp, 2, 3, 
351                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
352
353         left_arrow = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_OUT);
354         gtk_widget_show(left_arrow);
355         gtk_box_pack_start (GTK_BOX(hbox_regexp), left_arrow, FALSE, FALSE, 0);
356         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, left_arrow);
357
358         entry_regexp_test_result = gtk_entry_new();
359         gtk_box_pack_end (GTK_BOX(hbox_regexp), entry_regexp_test_result, TRUE, TRUE, 0);
360         SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_regexp_test_result);
361         gtk_entry_set_editable(GTK_ENTRY(entry_regexp_test_result), FALSE);
362
363         rowcount++;
364
365         /* Folder chmod */
366         checkbtn_folder_chmod = gtk_check_button_new_with_label(_("Folder chmod"));
367         gtk_table_attach(GTK_TABLE(table), checkbtn_folder_chmod, 0, 1, 
368                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
369
370         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_folder_chmod), 
371                                      item->prefs->enable_folder_chmod);
372
373         entry_folder_chmod = gtk_entry_new();
374         gtk_table_attach(GTK_TABLE(table), entry_folder_chmod, 1, 2, 
375                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
376         SET_TOGGLE_SENSITIVITY(checkbtn_folder_chmod, entry_folder_chmod);
377         if (item->prefs->folder_chmod) {
378                 gchar *buf;
379
380                 buf = g_strdup_printf("%o", item->prefs->folder_chmod);
381                 gtk_entry_set_text(GTK_ENTRY(entry_folder_chmod), buf);
382                 g_free(buf);
383         }
384         
385         folder_chmod_rec_checkbtn = gtk_check_button_new();
386         gtk_table_attach(GTK_TABLE(table), folder_chmod_rec_checkbtn, 3, 4, 
387                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
388
389         rowcount++;
390         
391         /* Folder color */
392         folder_color = gtk_label_new(_("Folder color"));
393         gtk_misc_set_alignment(GTK_MISC(folder_color), 0, 0.5);
394         gtk_table_attach(GTK_TABLE(table), folder_color, 0, 1, 
395                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
396
397         hbox = gtk_hbox_new(FALSE, 0);
398         gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 
399                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
400
401         folder_color_btn = gtk_button_new_with_label("");
402         gtk_widget_set_size_request(folder_color_btn, 36, 26);
403         gtk_box_pack_start (GTK_BOX(hbox), folder_color_btn, FALSE, FALSE, 0);
404         gtk_tooltips_set_tip(tooltips, folder_color_btn,
405                              _("Pick color for folder"), NULL);
406
407         page->folder_color = item->prefs->color;
408
409         g_signal_connect(G_OBJECT(folder_color_btn), "clicked",
410                          G_CALLBACK(folder_color_set_dialog),
411                          page);
412
413         gtkut_set_widget_bgcolor_rgb(folder_color_btn, item->prefs->color);
414
415         folder_color_rec_checkbtn = gtk_check_button_new();
416         gtk_table_attach(GTK_TABLE(table), folder_color_rec_checkbtn, 3, 4, 
417                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
418
419         rowcount++;
420
421         /* Enable processing at startup */
422         checkbtn_enable_processing = gtk_check_button_new_with_label(_("Process at start-up"));
423         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_processing, 0, 2, 
424                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
425
426         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_processing), 
427                                      item->prefs->enable_processing);
428
429         enable_processing_rec_checkbtn = gtk_check_button_new();
430         gtk_table_attach(GTK_TABLE(table), enable_processing_rec_checkbtn, 3, 4, 
431                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
432         
433         rowcount++;
434
435         /* Check folder for new mail */
436         checkbtn_newmailcheck = gtk_check_button_new_with_label(_("Scan for new mail"));
437         gtk_tooltips_set_tip(tooltips, checkbtn_newmailcheck,
438                              _("Turn this option on if mail is delivered directly "
439                                "to this folder by server side filtering on IMAP or "
440                                "by an external application"), NULL);
441         gtk_table_attach(GTK_TABLE(table), checkbtn_newmailcheck, 0, 2,
442                          rowcount, rowcount+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
443         
444         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_newmailcheck),
445                                                                  item->prefs->newmailcheck);
446         newmailcheck_rec_checkbtn = gtk_check_button_new();
447         gtk_table_attach(GTK_TABLE(table), newmailcheck_rec_checkbtn, 3, 4, 
448                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
449
450         rowcount++;
451
452         /* Synchronise folder for offline use */
453         checkbtn_offlinesync = gtk_check_button_new_with_label(_("Synchronise for offline use"));
454         gtk_table_attach(GTK_TABLE(table), checkbtn_offlinesync, 0, 2,
455                          rowcount, rowcount+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
456         
457         offlinesync_rec_checkbtn = gtk_check_button_new();
458         gtk_table_attach(GTK_TABLE(table), offlinesync_rec_checkbtn, 3, 4, 
459                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
460
461         rowcount++;
462
463         hbox = gtk_hbox_new (FALSE, 8);
464         gtk_widget_show (hbox);
465         gtk_table_attach(GTK_TABLE(table), hbox, 0, 4,
466                          rowcount, rowcount+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
467         rowcount++;
468
469         hbox_spc = gtk_hbox_new (FALSE, 0);
470         gtk_widget_show (hbox_spc);
471         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
472         gtk_widget_set_size_request (hbox_spc, 12, -1);
473
474         label_offlinesync = gtk_label_new(_("Fetch message bodies from the last"));
475         gtk_widget_show (label_offlinesync);
476         gtk_box_pack_start (GTK_BOX (hbox), label_offlinesync, FALSE, FALSE, 0);
477
478         entry_offlinesync = gtk_entry_new();
479         gtk_widget_set_size_request (entry_offlinesync, 64, -1);
480         gtk_widget_show (entry_offlinesync);
481         gtk_tooltips_set_tip(tooltips, entry_offlinesync, _("0: all bodies"), NULL);
482         gtk_box_pack_start (GTK_BOX (hbox), entry_offlinesync, FALSE, FALSE, 0);
483
484         label_end_offlinesync = gtk_label_new(_("days"));
485         gtk_widget_show (label_end_offlinesync);
486         gtk_box_pack_start (GTK_BOX (hbox), label_end_offlinesync, FALSE, FALSE, 0);
487
488         checkbtn_remove_old_offlinesync = gtk_check_button_new_with_label(
489                                                 _("Remove older messages bodies"));
490
491         hbox2 = gtk_hbox_new (FALSE, 8);
492         gtk_widget_show (hbox2);
493         gtk_table_attach(GTK_TABLE(table), hbox2, 0, 4,
494                          rowcount, rowcount+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
495         rowcount++;
496
497         hbox_spc = gtk_hbox_new (FALSE, 0);
498         gtk_widget_show (hbox_spc);
499         gtk_box_pack_start (GTK_BOX (hbox2), hbox_spc, FALSE, FALSE, 0);
500         gtk_widget_set_size_request (hbox_spc, 12, -1);
501         gtk_box_pack_start (GTK_BOX (hbox2), checkbtn_remove_old_offlinesync, FALSE, FALSE, 0);
502
503         SET_TOGGLE_SENSITIVITY (checkbtn_offlinesync, hbox);
504         SET_TOGGLE_SENSITIVITY (checkbtn_offlinesync, hbox2);
505         
506         clean_cache_btn = gtk_button_new_with_label(_("Discard folder cache"));
507         gtk_widget_show (clean_cache_btn);
508         gtk_table_attach(GTK_TABLE(table), clean_cache_btn, 0, 1,
509                          rowcount, rowcount+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
510         g_signal_connect(G_OBJECT(clean_cache_btn), "clicked",
511                          G_CALLBACK(clean_cache_cb),
512                          page);
513
514         gtk_widget_show_all(table);
515
516         if (item->folder && (item->folder->klass->type != F_IMAP && 
517             item->folder->klass->type != F_NEWS)) {
518                 item->prefs->offlinesync = TRUE;
519                 item->prefs->offlinesync_days = 0;
520                 item->prefs->remove_old_bodies = FALSE;
521
522                 gtk_widget_set_sensitive(GTK_WIDGET(checkbtn_offlinesync),
523                                                                  FALSE);
524                 gtk_widget_set_sensitive(GTK_WIDGET(offlinesync_rec_checkbtn),
525                                                                  FALSE);
526                 gtk_widget_hide(GTK_WIDGET(checkbtn_offlinesync));
527                 gtk_widget_hide(GTK_WIDGET(hbox));
528                 gtk_widget_hide(GTK_WIDGET(hbox2));
529                 gtk_widget_hide(GTK_WIDGET(offlinesync_rec_checkbtn));
530                 gtk_widget_hide(GTK_WIDGET(clean_cache_btn));
531         
532         }
533         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_offlinesync),
534                                                                  item->prefs->offlinesync);
535         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_remove_old_offlinesync),
536                                                                  item->prefs->remove_old_bodies);
537         gtk_entry_set_text(GTK_ENTRY(entry_offlinesync), itos(item->prefs->offlinesync_days));
538
539         page->table = table;
540         page->folder_type = folder_type;
541         page->no_save_warning = no_save_warning;
542         page->checkbtn_simplify_subject = checkbtn_simplify_subject;
543         page->entry_simplify_subject = entry_simplify_subject;
544         page->entry_regexp_test_string = entry_regexp_test_string;
545         page->entry_regexp_test_result = entry_regexp_test_result;
546         page->checkbtn_folder_chmod = checkbtn_folder_chmod;
547         page->entry_folder_chmod = entry_folder_chmod;
548         page->folder_color_btn = folder_color_btn;
549         page->checkbtn_enable_processing = checkbtn_enable_processing;
550         page->checkbtn_newmailcheck = checkbtn_newmailcheck;
551         page->checkbtn_offlinesync = checkbtn_offlinesync;
552         page->label_offlinesync = label_offlinesync;
553         page->entry_offlinesync = entry_offlinesync;
554         page->label_end_offlinesync = label_end_offlinesync;
555         page->checkbtn_remove_old_offlinesync = checkbtn_remove_old_offlinesync;
556
557         page->simplify_subject_rec_checkbtn  = simplify_subject_rec_checkbtn;
558         page->folder_chmod_rec_checkbtn      = folder_chmod_rec_checkbtn;
559         page->folder_color_rec_checkbtn      = folder_color_rec_checkbtn;
560         page->enable_processing_rec_checkbtn = enable_processing_rec_checkbtn;
561         page->newmailcheck_rec_checkbtn      = newmailcheck_rec_checkbtn;
562         page->offlinesync_rec_checkbtn       = offlinesync_rec_checkbtn;
563
564         page->page.widget = table;
565
566         folder_regexp_set_subject_example_cb(NULL, page);
567 }
568
569 static void prefs_folder_item_general_destroy_widget_func(PrefsPage *page_) 
570 {
571         /* FolderItemGeneralPage *page = (FolderItemGeneralPage *) page_; */
572 }
573
574 /** \brief  Save the prefs in page to folder.
575  *
576  *  If the folder is not the one  specified in page->item, then only those properties 
577  *  that have the relevant 'apply to sub folders' button checked are saved
578  */
579 static void general_save_folder_prefs(FolderItem *folder, FolderItemGeneralPage *page)
580 {
581         FolderItemPrefs *prefs = folder->prefs;
582         gchar *buf;
583         gboolean all = FALSE;
584         SpecialFolderItemType type = F_NORMAL;
585
586         if (folder->path == NULL)
587                 return;
588
589         g_return_if_fail(prefs != NULL);
590
591         if (page->item == folder) 
592                 all = TRUE;
593
594         type = combobox_get_active_data(GTK_COMBO_BOX(page->folder_type));
595         if (all && folder->stype != type) {
596                 folder_item_change_type(folder, type);
597         }
598
599         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->simplify_subject_rec_checkbtn))) {
600                 prefs->enable_simplify_subject =
601                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_simplify_subject));
602                 ASSIGN_STRING(prefs->simplify_subject_regexp,
603                               gtk_editable_get_chars(GTK_EDITABLE(page->entry_simplify_subject), 0, -1));
604         }
605         
606         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_chmod_rec_checkbtn))) {
607                 prefs->enable_folder_chmod = 
608                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_folder_chmod));
609                 buf = gtk_editable_get_chars(GTK_EDITABLE(page->entry_folder_chmod), 0, -1);
610                 prefs->folder_chmod = prefs_folder_item_chmod_mode(buf);
611                 g_free(buf);
612         }
613
614         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_color_rec_checkbtn))) {
615                 int old_color = prefs->color;
616                 prefs->color = page->folder_color;
617         
618                 /* update folder view */
619                 if (prefs->color != old_color)
620                         folder_item_update(folder, F_ITEM_UPDATE_MSGCNT);
621         }
622
623         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_processing_rec_checkbtn))) {
624                 prefs->enable_processing = 
625                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_processing));
626         }
627
628         if (all ||  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->newmailcheck_rec_checkbtn))) {
629                 prefs->newmailcheck = 
630                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_newmailcheck));
631         }
632
633         if (all ||  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->offlinesync_rec_checkbtn))) {
634                 prefs->offlinesync = 
635                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_offlinesync));
636                 prefs->offlinesync_days = 
637                         atoi(gtk_entry_get_text(GTK_ENTRY(page->entry_offlinesync)));
638                 prefs->remove_old_bodies =
639                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_remove_old_offlinesync));
640         }
641
642         folder_item_prefs_save_config(folder);
643 }       
644
645 static gboolean general_save_recurse_func(GNode *node, gpointer data)
646 {
647         FolderItem *item = (FolderItem *) node->data;
648         FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
649
650         g_return_val_if_fail(item != NULL, TRUE);
651         g_return_val_if_fail(page != NULL, TRUE);
652
653         general_save_folder_prefs(item, page);
654
655         /* optimise by not continuing if none of the 'apply to sub folders'
656            check boxes are selected - and optimise the checking by only doing
657            it once */
658         if ((node == page->item->node) &&
659             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->simplify_subject_rec_checkbtn)) ||
660               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_chmod_rec_checkbtn)) ||
661               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_color_rec_checkbtn)) ||
662               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_processing_rec_checkbtn)) ||
663               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->newmailcheck_rec_checkbtn)) ||
664               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->offlinesync_rec_checkbtn))))
665                 return TRUE;
666         else 
667                 return FALSE;
668 }
669
670 static void prefs_folder_item_general_save_func(PrefsPage *page_) 
671 {
672         FolderItemGeneralPage *page = (FolderItemGeneralPage *) page_;
673
674         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
675                         -1, general_save_recurse_func, page);
676         
677         main_window_set_menu_sensitive(mainwindow_get_mainwindow());
678
679 }
680
681 static RecvProtocol item_protocol(FolderItem *item)
682 {
683         if (!item)
684                 return A_NONE;
685         if (!item->folder)
686                 return A_NONE;
687         if (!item->folder->account)
688                 return A_NONE;
689         return item->folder->account->protocol;
690 }
691
692 static void prefs_folder_item_compose_create_widget_func(PrefsPage * page_,
693                                                    GtkWindow * window,
694                                                    gpointer data)
695 {
696         FolderItemComposePage *page = (FolderItemComposePage *) page_;
697         FolderItem *item = (FolderItem *) data;
698         guint rowcount;
699
700         GtkWidget *table;
701         GtkWidget *label;
702         
703         GtkWidget *no_save_warning = NULL;
704         GtkWidget *checkbtn_request_return_receipt = NULL;
705         GtkWidget *checkbtn_save_copy_to_folder = NULL;
706         GtkWidget *checkbtn_default_to = NULL;
707         GtkWidget *entry_default_to = NULL;
708         GtkWidget *checkbtn_default_reply_to = NULL;
709         GtkWidget *entry_default_reply_to = NULL;
710         GtkWidget *checkbtn_enable_default_account = NULL;
711         GtkWidget *optmenu_default_account = NULL;
712         GtkListStore *optmenu_default_account_menu = NULL;
713         GtkTreeIter iter;
714 #if USE_ASPELL
715         GtkWidget *checkbtn_enable_default_dictionary = NULL;
716         GtkWidget *optmenu_default_dictionary = NULL;
717         GtkWidget *checkbtn_enable_default_alt_dictionary = NULL;
718         GtkWidget *optmenu_default_alt_dictionary = NULL;
719         GtkWidget *default_dictionary_rec_checkbtn = NULL;
720         GtkWidget *default_alt_dictionary_rec_checkbtn = NULL;
721         gchar *dictionary;
722         GtkOptionMenu *optmenu;
723         GtkWidget *menu;
724         GtkWidget *menuitem;
725 #endif
726         GtkWidget *request_return_receipt_rec_checkbtn = NULL;
727         GtkWidget *save_copy_to_folder_rec_checkbtn = NULL;
728         GtkWidget *default_to_rec_checkbtn = NULL;
729         GtkWidget *default_reply_to_rec_checkbtn = NULL;
730         GtkWidget *default_account_rec_checkbtn = NULL;
731
732         GList *cur_ac;
733         GList *account_list;
734         PrefsAccount *ac_prefs;
735         gboolean default_account_set = FALSE;
736
737         page->item         = item;
738
739         /* Table */
740 #if USE_ASPELL
741 # define TABLEHEIGHT 7
742 #else
743 # define TABLEHEIGHT 6
744 #endif
745         table = gtk_table_new(TABLEHEIGHT, 3, FALSE);
746         gtk_container_set_border_width (GTK_CONTAINER (table), VBOX_BORDER);
747         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
748         gtk_table_set_col_spacings(GTK_TABLE(table), 4);
749         rowcount = 0;
750
751         if (!can_save) {
752                 no_save_warning = gtk_label_new(
753                         _("<i>These preferences will not be saved as this folder "
754                         "is a top-level one. However you can use them to set them "
755                         "to the whole mailbox tree using \"Apply to subfolders\".</i>"));
756                 gtk_label_set_use_markup(GTK_LABEL(no_save_warning), TRUE);
757                 gtk_label_set_line_wrap(GTK_LABEL(no_save_warning), TRUE);
758                 gtk_misc_set_alignment(GTK_MISC(no_save_warning), 0.0, 0.5);
759                 gtk_table_attach(GTK_TABLE(table), no_save_warning, 0, 3,
760                          rowcount, rowcount + 1, GTK_FILL, 0, 0, 0);
761                 rowcount++;
762         }
763         
764         /* Apply to subfolders */
765         label = gtk_label_new(_("Apply to\nsubfolders"));
766         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
767         gtk_table_attach(GTK_TABLE(table), label, 2, 3,
768                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
769         rowcount++;
770
771         if (item_protocol(item) != A_NNTP) {
772                 /* Request Return Receipt */
773                 checkbtn_request_return_receipt = gtk_check_button_new_with_label
774                         (_("Request Return Receipt"));
775                 gtk_table_attach(GTK_TABLE(table), checkbtn_request_return_receipt, 
776                                  0, 2, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, 
777                                  GTK_FILL, 0, 0);
778                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_request_return_receipt),
779                                              item->ret_rcpt ? TRUE : FALSE);
780
781                 request_return_receipt_rec_checkbtn = gtk_check_button_new();
782                 gtk_table_attach(GTK_TABLE(table), request_return_receipt_rec_checkbtn, 2, 3, 
783                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
784
785                 rowcount++;
786
787                 /* Save Copy to Folder */
788                 checkbtn_save_copy_to_folder = gtk_check_button_new_with_label
789                         (_("Save copy of outgoing messages to this folder instead of Sent"));
790                 gtk_table_attach(GTK_TABLE(table), checkbtn_save_copy_to_folder, 0, 2, 
791                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
792                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_save_copy_to_folder),
793                                              item->prefs->save_copy_to_folder ? TRUE : FALSE);
794
795                 save_copy_to_folder_rec_checkbtn = gtk_check_button_new();
796                 gtk_table_attach(GTK_TABLE(table), save_copy_to_folder_rec_checkbtn, 2, 3, 
797                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
798
799                 rowcount++;
800
801                 /* Default To */
802                 checkbtn_default_to = gtk_check_button_new_with_label(_("Default To:"));
803                 gtk_table_attach(GTK_TABLE(table), checkbtn_default_to, 0, 1, 
804                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
805                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_to), 
806                                              item->prefs->enable_default_to);
807
808                 entry_default_to = gtk_entry_new();
809                 gtk_table_attach(GTK_TABLE(table), entry_default_to, 1, 2,
810                                  rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
811                 SET_TOGGLE_SENSITIVITY(checkbtn_default_to, entry_default_to);
812                 gtk_entry_set_text(GTK_ENTRY(entry_default_to), SAFE_STRING(item->prefs->default_to));
813                 address_completion_register_entry(GTK_ENTRY(entry_default_to),
814                                 TRUE);
815
816                 default_to_rec_checkbtn = gtk_check_button_new();
817                 gtk_table_attach(GTK_TABLE(table), default_to_rec_checkbtn, 2, 3, 
818                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
819
820                 rowcount++;
821
822                 /* Default address to reply to */
823                 checkbtn_default_reply_to = gtk_check_button_new_with_label(_("Default To: for replies"));
824                 gtk_table_attach(GTK_TABLE(table), checkbtn_default_reply_to, 0, 1, 
825                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
826                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_reply_to), 
827                                              item->prefs->enable_default_reply_to);
828
829                 entry_default_reply_to = gtk_entry_new();
830                 gtk_table_attach(GTK_TABLE(table), entry_default_reply_to, 1, 2,
831                                  rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
832                 SET_TOGGLE_SENSITIVITY(checkbtn_default_reply_to, entry_default_reply_to);
833                 gtk_entry_set_text(GTK_ENTRY(entry_default_reply_to), SAFE_STRING(item->prefs->default_reply_to));
834                 address_completion_register_entry(
835                                 GTK_ENTRY(entry_default_reply_to), TRUE);
836
837                 default_reply_to_rec_checkbtn = gtk_check_button_new();
838                 gtk_table_attach(GTK_TABLE(table), default_reply_to_rec_checkbtn, 2, 3, 
839                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
840
841                 rowcount++;
842         }
843         /* Default account */
844         checkbtn_enable_default_account = gtk_check_button_new_with_label(_("Default account"));
845         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_account, 0, 1, 
846                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
847         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_account), 
848                                      item->prefs->enable_default_account);
849
850         optmenu_default_account = gtkut_sc_combobox_create(NULL, FALSE);
851         gtk_table_attach(GTK_TABLE(table), optmenu_default_account, 1, 2, 
852                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
853         optmenu_default_account_menu = GTK_LIST_STORE(
854                         gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu_default_account)));
855
856         account_list = account_get_list();
857         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
858                 ac_prefs = (PrefsAccount *)cur_ac->data;
859                 if (item->folder->account &&
860                     ( (item_protocol(item) == A_NNTP && ac_prefs->protocol != A_NNTP)
861                     ||(item_protocol(item) != A_NNTP && ac_prefs->protocol == A_NNTP))) 
862                         continue;
863
864                 if (item->folder->klass->type != F_NEWS && ac_prefs->protocol == A_NNTP)
865                         continue;
866
867                 COMBOBOX_ADD (optmenu_default_account_menu,
868                                         ac_prefs->account_name?ac_prefs->account_name : _("Untitled"),
869                                         ac_prefs->account_id);
870
871                 /* Set combobox to current default account id */
872                 if (ac_prefs->account_id == item->prefs->default_account) {
873                         combobox_select_by_data(GTK_COMBO_BOX(optmenu_default_account),
874                                         ac_prefs->account_id);
875                         default_account_set = TRUE;
876                 }
877         }
878
879         /* If nothing has been set (folder doesn't have a default account set),
880          * pre-select global default account, since that's what actually used
881          * anyway. We don't want nothing selected in combobox. */
882         if( !default_account_set )
883                 combobox_select_by_data(GTK_COMBO_BOX(optmenu_default_account),
884                                 account_get_default()->account_id);
885
886         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_account, optmenu_default_account);
887
888         default_account_rec_checkbtn = gtk_check_button_new();
889         gtk_table_attach(GTK_TABLE(table), default_account_rec_checkbtn, 2, 3, 
890                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
891         rowcount++;
892
893 #if USE_ASPELL
894         /* Default dictionary */
895         checkbtn_enable_default_dictionary = gtk_check_button_new_with_label(_("Default dictionary"));
896         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_dictionary, 0, 1,
897                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
898         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_dictionary),
899                                      item->prefs->enable_default_dictionary);
900
901         optmenu_default_dictionary = gtk_option_menu_new();
902         gtk_table_attach(GTK_TABLE(table), optmenu_default_dictionary, 1, 2,
903                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
904
905         gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu_default_dictionary), 
906                                  gtkaspell_dictionary_option_menu_new(
907                                          prefs_common.aspell_path));
908
909         dictionary = item->prefs->default_dictionary;
910
911         optmenu = GTK_OPTION_MENU(optmenu_default_dictionary);
912
913         menu = gtk_option_menu_get_menu(optmenu);
914         if (dictionary)
915                 gtkaspell_set_dictionary_menu_active_item(optmenu_default_dictionary, dictionary);
916         menuitem = gtk_menu_get_active(GTK_MENU(menu));
917         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
918
919         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_dictionary, optmenu_default_dictionary);
920
921         default_dictionary_rec_checkbtn = gtk_check_button_new();
922         gtk_table_attach(GTK_TABLE(table), default_dictionary_rec_checkbtn, 2, 3, 
923                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
924         
925         rowcount++;
926
927         /* Default dictionary */
928         checkbtn_enable_default_alt_dictionary = gtk_check_button_new_with_label(_("Default alternate dictionary"));
929         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_alt_dictionary, 0, 1,
930                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
931         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_alt_dictionary),
932                                      item->prefs->enable_default_alt_dictionary);
933
934         optmenu_default_alt_dictionary = gtk_option_menu_new();
935         gtk_table_attach(GTK_TABLE(table), optmenu_default_alt_dictionary, 1, 2,
936                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
937
938         gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu_default_alt_dictionary), 
939                                  gtkaspell_dictionary_option_menu_new_with_refresh(
940                                          prefs_common.aspell_path, FALSE));
941
942         dictionary = item->prefs->default_alt_dictionary;
943
944         optmenu = GTK_OPTION_MENU(optmenu_default_alt_dictionary);
945
946         menu = gtk_option_menu_get_menu(optmenu);
947         if (dictionary)
948                 gtkaspell_set_dictionary_menu_active_item(optmenu_default_alt_dictionary, dictionary);
949         menuitem = gtk_menu_get_active(GTK_MENU(menu));
950         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
951
952         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_alt_dictionary, optmenu_default_alt_dictionary);
953
954         default_alt_dictionary_rec_checkbtn = gtk_check_button_new();
955         gtk_table_attach(GTK_TABLE(table), default_alt_dictionary_rec_checkbtn, 2, 3, 
956                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
957         
958         rowcount++;
959 #endif
960
961         gtk_widget_show_all(table);
962
963         page->window = GTK_WIDGET(window);
964         page->table = table;
965         page->no_save_warning = no_save_warning;
966         page->checkbtn_request_return_receipt = checkbtn_request_return_receipt;
967         page->checkbtn_save_copy_to_folder = checkbtn_save_copy_to_folder;
968         page->checkbtn_default_to = checkbtn_default_to;
969         page->entry_default_to = entry_default_to;
970         page->checkbtn_default_reply_to = checkbtn_default_reply_to;
971         page->entry_default_reply_to = entry_default_reply_to;
972         page->checkbtn_enable_default_account = checkbtn_enable_default_account;
973         page->optmenu_default_account = optmenu_default_account;
974 #ifdef USE_ASPELL
975         page->checkbtn_enable_default_dictionary = checkbtn_enable_default_dictionary;
976         page->optmenu_default_dictionary = optmenu_default_dictionary;
977         page->checkbtn_enable_default_alt_dictionary = checkbtn_enable_default_alt_dictionary;
978         page->optmenu_default_alt_dictionary = optmenu_default_alt_dictionary;
979 #endif
980
981         page->request_return_receipt_rec_checkbtn = request_return_receipt_rec_checkbtn;
982         page->save_copy_to_folder_rec_checkbtn    = save_copy_to_folder_rec_checkbtn;
983         page->default_to_rec_checkbtn             = default_to_rec_checkbtn;
984         page->default_reply_to_rec_checkbtn       = default_reply_to_rec_checkbtn;
985         page->default_account_rec_checkbtn        = default_account_rec_checkbtn;
986 #if USE_ASPELL
987         page->default_dictionary_rec_checkbtn = default_dictionary_rec_checkbtn;
988         page->default_alt_dictionary_rec_checkbtn = default_alt_dictionary_rec_checkbtn;
989 #endif
990
991         address_completion_start(page->window);
992
993         page->page.widget = table;
994 }
995
996 static void prefs_folder_item_compose_destroy_widget_func(PrefsPage *page_) 
997 {
998         FolderItemComposePage *page = (FolderItemComposePage *) page_;
999
1000         if (page->entry_default_to)
1001                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_to));
1002         if (page->entry_default_reply_to)
1003                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_reply_to));
1004         address_completion_end(page->window);
1005 }
1006
1007 /** \brief  Save the prefs in page to folder.
1008  *
1009  *  If the folder is not the one  specified in page->item, then only those properties 
1010  *  that have the relevant 'apply to sub folders' button checked are saved
1011  */
1012 static void compose_save_folder_prefs(FolderItem *folder, FolderItemComposePage *page)
1013 {
1014         FolderItemPrefs *prefs = folder->prefs;
1015 #if USE_ASPELL
1016         GtkWidget *menu;
1017 #endif
1018         gboolean all = FALSE;
1019
1020         if (folder->path == NULL)
1021                 return;
1022
1023         if (page->item == folder) 
1024                 all = TRUE;
1025
1026         g_return_if_fail(prefs != NULL);
1027
1028         if (item_protocol(folder) != A_NNTP) {
1029                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->request_return_receipt_rec_checkbtn))) {
1030                         prefs->request_return_receipt = 
1031                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_request_return_receipt));
1032                         /* MIGRATION */    
1033                         folder->ret_rcpt = prefs->request_return_receipt;
1034                 }
1035
1036                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_copy_to_folder_rec_checkbtn))) {
1037                         prefs->save_copy_to_folder = 
1038                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_save_copy_to_folder));
1039                 }
1040
1041                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_to_rec_checkbtn))) {
1042
1043                         prefs->enable_default_to = 
1044                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_to));
1045                         ASSIGN_STRING(prefs->default_to,
1046                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_to), 0, -1));
1047                 }
1048
1049                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_reply_to_rec_checkbtn))) {
1050                         prefs->enable_default_reply_to = 
1051                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_reply_to));
1052                         ASSIGN_STRING(prefs->default_reply_to,
1053                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_reply_to), 0, -1));
1054                 }
1055         } else {
1056                 prefs->request_return_receipt = FALSE;
1057                 prefs->save_copy_to_folder = FALSE;
1058                 prefs->enable_default_to = FALSE;
1059                 prefs->enable_default_reply_to = FALSE;
1060         }
1061
1062         if (all || gtk_toggle_button_get_active(
1063                                 GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn))) {
1064                 prefs->enable_default_account = 
1065                         gtk_toggle_button_get_active(
1066                                         GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_account));
1067                 prefs->default_account = combobox_get_active_data(
1068                                 GTK_COMBO_BOX(page->optmenu_default_account));
1069         }
1070
1071 #if USE_ASPELL
1072         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn))) {
1073                 prefs->enable_default_dictionary =
1074                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_dictionary));
1075                 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_default_dictionary));
1076                 ASSIGN_STRING(prefs->default_dictionary,
1077                               gtkaspell_get_dictionary_menu_active_item(menu));
1078         }
1079         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_alt_dictionary_rec_checkbtn))) {
1080                 prefs->enable_default_alt_dictionary =
1081                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_alt_dictionary));
1082                 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_default_alt_dictionary));
1083                 ASSIGN_STRING(prefs->default_alt_dictionary,
1084                               gtkaspell_get_dictionary_menu_active_item(menu));
1085         }
1086 #endif
1087
1088         folder_item_prefs_save_config(folder);
1089 }       
1090
1091 static gboolean compose_save_recurse_func(GNode *node, gpointer data)
1092 {
1093         FolderItem *item = (FolderItem *) node->data;
1094         FolderItemComposePage *page = (FolderItemComposePage *) data;
1095
1096         g_return_val_if_fail(item != NULL, TRUE);
1097         g_return_val_if_fail(page != NULL, TRUE);
1098
1099         compose_save_folder_prefs(item, page);
1100
1101         /* optimise by not continuing if none of the 'apply to sub folders'
1102            check boxes are selected - and optimise the checking by only doing
1103            it once */
1104         if ((node == page->item->node) && item_protocol(item) != A_NNTP &&
1105             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->request_return_receipt_rec_checkbtn)) ||
1106               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_copy_to_folder_rec_checkbtn)) ||
1107               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_to_rec_checkbtn)) ||
1108               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn)) ||
1109 #if USE_ASPELL
1110               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn)) ||
1111               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_alt_dictionary_rec_checkbtn)) ||
1112 #endif
1113               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_reply_to_rec_checkbtn))))
1114                 return TRUE;
1115         else if ((node == page->item->node) && item_protocol(item) == A_NNTP &&
1116             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn)) 
1117 #if USE_ASPELL
1118               || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn))
1119               || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_alt_dictionary_rec_checkbtn))
1120 #endif
1121                     ))
1122                 return TRUE;
1123         else 
1124                 return FALSE;
1125 }
1126
1127 static void prefs_folder_item_compose_save_func(PrefsPage *page_) 
1128 {
1129         FolderItemComposePage *page = (FolderItemComposePage *) page_;
1130
1131         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
1132                         -1, compose_save_recurse_func, page);
1133
1134 }
1135
1136 static void prefs_folder_item_templates_create_widget_func(PrefsPage * page_,
1137                                                    GtkWindow * window,
1138                                                    gpointer data)
1139 {
1140         FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) page_;
1141         FolderItem *item = (FolderItem *) data;
1142
1143         GtkWidget *notebook;
1144         GtkWidget *vbox;
1145         GtkWidget *page_vbox;
1146         GtkWidget *new_msg_format_rec_checkbtn;
1147         GtkWidget *reply_format_rec_checkbtn;
1148         GtkWidget *forward_format_rec_checkbtn;
1149
1150         page->item = item;
1151
1152         page_vbox = gtk_vbox_new (FALSE, 0);
1153         gtk_widget_show (page_vbox);
1154         
1155         /* Notebook */
1156         notebook = gtk_notebook_new();
1157         gtk_widget_show(notebook);
1158         gtk_notebook_set_homogeneous_tabs(GTK_NOTEBOOK(notebook), TRUE);
1159         gtk_box_pack_start(GTK_BOX(page_vbox), notebook, TRUE, TRUE, 0);
1160
1161         /* compose format */
1162         vbox = gtk_vbox_new (FALSE, VSPACING);
1163         gtk_widget_show (vbox);
1164         gtk_container_set_border_width (GTK_CONTAINER (vbox), VBOX_BORDER);
1165
1166         quotefmt_create_new_msg_fmt_widgets(
1167                                 window,
1168                                 vbox,
1169                                 &page->checkbtn_compose_with_format,
1170                                 &page->compose_subject_format,
1171                                 &page->compose_body_format,
1172                                 FALSE);
1173
1174         new_msg_format_rec_checkbtn = gtk_check_button_new_with_label(
1175                         _("Apply to subfolders"));
1176         gtk_box_pack_end (GTK_BOX(vbox), new_msg_format_rec_checkbtn, FALSE, FALSE, 0);
1177         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, gtk_label_new(_("Compose")));
1178
1179         /* reply format */
1180         vbox = gtk_vbox_new (FALSE, VSPACING);
1181         gtk_widget_show (vbox);
1182         gtk_container_set_border_width (GTK_CONTAINER (vbox), VBOX_BORDER);
1183
1184         quotefmt_create_reply_fmt_widgets(
1185                                 window,
1186                                 vbox,
1187                                 &page->checkbtn_reply_with_format,
1188                                 &page->reply_quotemark,
1189                                 &page->reply_body_format,
1190                                 FALSE);
1191
1192         reply_format_rec_checkbtn = gtk_check_button_new_with_label(
1193                         _("Apply to subfolders"));
1194         gtk_box_pack_end (GTK_BOX(vbox), reply_format_rec_checkbtn, FALSE, FALSE, 0);
1195         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, gtk_label_new(_("Reply")));
1196
1197         /* forward format */
1198         vbox = gtk_vbox_new (FALSE, VSPACING);
1199         gtk_widget_show (vbox);
1200         gtk_container_set_border_width (GTK_CONTAINER (vbox), VBOX_BORDER);
1201
1202         quotefmt_create_forward_fmt_widgets(
1203                                 window,
1204                                 vbox,
1205                                 &page->checkbtn_forward_with_format,
1206                                 &page->forward_quotemark,
1207                                 &page->forward_body_format,
1208                                 FALSE);
1209
1210         forward_format_rec_checkbtn = gtk_check_button_new_with_label(
1211                         _("Apply to subfolders"));
1212         gtk_box_pack_end (GTK_BOX(vbox), forward_format_rec_checkbtn, FALSE, FALSE, 0);
1213         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, gtk_label_new(_("Forward")));
1214
1215         /* information button */
1216         quotefmt_add_info_button(window, page_vbox);
1217
1218         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->checkbtn_compose_with_format),
1219                         item->prefs->compose_with_format);
1220         pref_set_entry_from_pref(GTK_ENTRY(page->compose_subject_format),
1221                         item->prefs->compose_subject_format);
1222         pref_set_textview_from_pref(GTK_TEXT_VIEW(page->compose_body_format),
1223                         item->prefs->compose_body_format);
1224
1225         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->checkbtn_reply_with_format),
1226                         item->prefs->reply_with_format);
1227         pref_set_entry_from_pref(GTK_ENTRY(page->reply_quotemark),
1228                         item->prefs->reply_quotemark);
1229         pref_set_textview_from_pref(GTK_TEXT_VIEW(page->reply_body_format),
1230                         item->prefs->reply_body_format);
1231
1232         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_with_format),
1233                         item->prefs->forward_with_format);
1234         pref_set_entry_from_pref(GTK_ENTRY(page->forward_quotemark),
1235                         item->prefs->forward_quotemark);
1236         pref_set_textview_from_pref(GTK_TEXT_VIEW(page->forward_body_format),
1237                         item->prefs->forward_body_format);
1238
1239         gtk_widget_show_all(page_vbox);
1240
1241         page->window = GTK_WIDGET(window);
1242
1243         page->new_msg_format_rec_checkbtn = new_msg_format_rec_checkbtn;
1244         page->reply_format_rec_checkbtn = reply_format_rec_checkbtn;
1245         page->forward_format_rec_checkbtn = forward_format_rec_checkbtn;
1246
1247         page->page.widget = page_vbox;
1248 }
1249
1250 static void prefs_folder_item_templates_destroy_widget_func(PrefsPage *page_) 
1251 {
1252         /* FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) page_; */
1253 }
1254
1255 /** \brief  Save the prefs in page to folder.
1256  *
1257  *  If the folder is not the one  specified in page->item, then only those properties 
1258  *  that have the relevant 'apply to sub folders' button checked are saved
1259  */
1260 static void templates_save_folder_prefs(FolderItem *folder, FolderItemTemplatesPage *page)
1261 {
1262         FolderItemPrefs *prefs = folder->prefs;
1263         gboolean all = FALSE;
1264
1265         if (folder->path == NULL)
1266                 return;
1267
1268         if (page->item == folder) 
1269                 all = TRUE;
1270
1271         g_return_if_fail(prefs != NULL);
1272
1273         /* save and check formats */
1274
1275         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->new_msg_format_rec_checkbtn))) {
1276                 prefs->compose_with_format =
1277                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_compose_with_format));
1278                 prefs->compose_subject_format = pref_get_pref_from_entry(
1279                                 GTK_ENTRY(page->compose_subject_format));
1280                 prefs->compose_body_format = pref_get_pref_from_textview(
1281                                 GTK_TEXT_VIEW(page->compose_body_format));
1282                 quotefmt_check_new_msg_formats(prefs->compose_with_format,
1283                                                                                 prefs->compose_subject_format,
1284                                                                                 prefs->compose_body_format);
1285         }
1286
1287         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->reply_format_rec_checkbtn))) {
1288                 prefs->reply_with_format =
1289                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_reply_with_format));
1290                 prefs->reply_quotemark = gtk_editable_get_chars(
1291                                 GTK_EDITABLE(page->reply_quotemark), 0, -1);
1292                 prefs->reply_body_format = pref_get_pref_from_textview(
1293                                 GTK_TEXT_VIEW(page->reply_body_format));
1294                 quotefmt_check_reply_formats(prefs->reply_with_format,
1295                                                                                 prefs->reply_quotemark,
1296                                                                                 prefs->reply_body_format);
1297         }
1298
1299         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->forward_format_rec_checkbtn))) {
1300                 prefs->forward_with_format =
1301                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_with_format));
1302                 prefs->forward_quotemark = gtk_editable_get_chars(
1303                                 GTK_EDITABLE(page->forward_quotemark), 0, -1);
1304                 prefs->forward_body_format = pref_get_pref_from_textview(
1305                                 GTK_TEXT_VIEW(page->forward_body_format));
1306                 quotefmt_check_forward_formats(prefs->forward_with_format,
1307                                                                                 prefs->forward_quotemark,
1308                                                                                 prefs->forward_body_format);
1309         }
1310
1311         folder_item_prefs_save_config(folder);
1312 }       
1313
1314 static gboolean templates_save_recurse_func(GNode *node, gpointer data)
1315 {
1316         FolderItem *item = (FolderItem *) node->data;
1317         FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) data;
1318
1319         g_return_val_if_fail(item != NULL, TRUE);
1320         g_return_val_if_fail(page != NULL, TRUE);
1321
1322         templates_save_folder_prefs(item, page);
1323
1324         /* optimise by not continuing if none of the 'apply to sub folders'
1325            check boxes are selected - and optimise the checking by only doing
1326            it once */
1327         if ((node == page->item->node) &&
1328             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->new_msg_format_rec_checkbtn)) ||
1329               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->reply_format_rec_checkbtn)) ||
1330               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->forward_format_rec_checkbtn))))
1331                 return TRUE;
1332         else 
1333                 return FALSE;
1334
1335         return FALSE;
1336 }
1337
1338 static void prefs_folder_item_templates_save_func(PrefsPage *page_) 
1339 {
1340         FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) page_;
1341
1342         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
1343                         -1, templates_save_recurse_func, page);
1344
1345 }
1346
1347 static gint prefs_folder_item_chmod_mode(gchar *folder_chmod) 
1348 {
1349         gint newmode = 0;
1350         gchar *tmp;
1351
1352         if (folder_chmod) {
1353                 newmode = strtol(folder_chmod, &tmp, 8);
1354                 if (!(*(folder_chmod) && !(*tmp)))
1355                         newmode = 0;
1356         }
1357
1358         return newmode;
1359 }
1360
1361 static void folder_color_set_dialog(GtkWidget *widget, gpointer data)
1362 {
1363         FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
1364         gint rgbcolor;
1365
1366         rgbcolor = colorsel_select_color_rgb(_("Pick color for folder"), 
1367                                              page->folder_color);
1368         gtkut_set_widget_bgcolor_rgb(page->folder_color_btn, rgbcolor);
1369         page->folder_color = rgbcolor;
1370 }
1371
1372 static void clean_cache_cb(GtkWidget *widget, gpointer data)
1373 {
1374         FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
1375         FolderItem *item = page->item;
1376         gboolean was_open = FALSE;
1377         FolderView *folderview = NULL;
1378
1379         if (alertpanel_full(_("Discard cache"), 
1380                             _("Do you really want to discard the local cached "
1381                               "data for this folder?"),
1382                                  GTK_STOCK_CANCEL, _("+Discard"), NULL, FALSE,
1383                                  NULL, ALERT_WARNING, G_ALERTDEFAULT)
1384                 != G_ALERTALTERNATE)
1385                 return;
1386         
1387         if (mainwindow_get_mainwindow())
1388                 folderview = mainwindow_get_mainwindow()->folderview;
1389
1390         if (folderview && item->opened) {
1391                 folderview_close_opened(folderview);
1392                 was_open = TRUE;
1393         }
1394         folder_item_discard_cache(item);
1395         if (was_open)
1396                 folderview_select(folderview,item);
1397 }
1398
1399 static regex_t *summary_compile_simplify_regexp(gchar *simplify_subject_regexp)
1400 {
1401         int err;
1402         gchar buf[BUFFSIZE];
1403         regex_t *preg = NULL;
1404
1405         preg = g_new0(regex_t, 1);
1406
1407         err = string_match_precompile(simplify_subject_regexp, 
1408                                       preg, REG_EXTENDED);
1409         if (err) {
1410                 regerror(err, preg, buf, BUFFSIZE);
1411                 g_free(preg);
1412                 preg = NULL;
1413         }
1414
1415         return preg;
1416 }
1417
1418 static void folder_regexp_test_cb(GtkWidget *widget, gpointer data)
1419 {
1420         static GdkColor red;
1421         static gboolean colors_initialised = FALSE;
1422         static gchar buf[BUFFSIZE];
1423         FolderItemGeneralPage *page = (FolderItemGeneralPage *)data;
1424         gchar *test_string, *regexp;
1425         regex_t *preg;
1426
1427         regexp = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->entry_simplify_subject)));
1428         test_string = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->entry_regexp_test_string)));
1429
1430         if (!regexp || !regexp[0]) {
1431                 gtk_widget_modify_base(page->entry_simplify_subject,
1432                                 GTK_STATE_NORMAL, NULL);
1433                 if (test_string) {
1434                         gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_result), test_string);
1435                         g_free(test_string);
1436                 }
1437                 return;
1438         }
1439
1440         if (!test_string || !test_string[0]) {
1441                 g_free(regexp);
1442                 return;
1443         }
1444
1445         if (!colors_initialised) {
1446                 gdk_color_parse("#ff7070", &red);
1447                 colors_initialised = gdk_colormap_alloc_color(
1448                         gdk_colormap_get_system(), &red, FALSE, TRUE);
1449         }
1450
1451         preg = summary_compile_simplify_regexp(regexp);
1452         if (colors_initialised) {
1453                 gtk_widget_modify_base(page->entry_simplify_subject,
1454                                 GTK_STATE_NORMAL, preg ? NULL : &red);
1455         }
1456
1457         if (preg != NULL) {
1458                 string_remove_match(buf, BUFFSIZE, test_string, preg);
1459
1460                 gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_result), buf);
1461
1462                 regfree(preg);
1463                 g_free(preg);
1464         }
1465
1466         g_free(test_string);
1467         g_free(regexp);
1468 }
1469
1470 static gchar *folder_regexp_get_subject_example(void)
1471 {
1472         MsgInfo *msginfo_selected;
1473         SummaryView *summaryview = NULL;
1474
1475         if (!mainwindow_get_mainwindow())
1476                 return NULL;
1477         summaryview = mainwindow_get_mainwindow()->summaryview;
1478
1479         msginfo_selected = summary_get_selected_msg(summaryview);
1480         return msginfo_selected ? g_strdup(msginfo_selected->subject) : NULL;
1481 }
1482
1483 static void folder_regexp_set_subject_example_cb(GtkWidget *widget, gpointer data)
1484 {
1485         FolderItemGeneralPage *page = (FolderItemGeneralPage *)data;
1486
1487         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_simplify_subject))) {
1488                 gchar *subject = folder_regexp_get_subject_example();
1489                 if (subject) {
1490                         gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_string), subject);
1491                         g_free(subject);
1492                 }
1493         }
1494 }
1495
1496 static void register_general_page()
1497 {
1498         static gchar *pfi_general_path[2];
1499         static FolderItemGeneralPage folder_item_general_page;
1500
1501         pfi_general_path[0] = _("General");
1502         pfi_general_path[1] = NULL;
1503
1504         folder_item_general_page.page.path = pfi_general_path;
1505         folder_item_general_page.page.create_widget = prefs_folder_item_general_create_widget_func;
1506         folder_item_general_page.page.destroy_widget = prefs_folder_item_general_destroy_widget_func;
1507         folder_item_general_page.page.save_page = prefs_folder_item_general_save_func;
1508         
1509         prefs_folder_item_register_page((PrefsPage *) &folder_item_general_page);
1510 }
1511
1512
1513 static void register_compose_page(void)
1514 {
1515         static gchar *pfi_compose_path[2];
1516         static FolderItemComposePage folder_item_compose_page;
1517
1518         pfi_compose_path[0] = _("Compose");
1519         pfi_compose_path[1] = NULL;
1520
1521         folder_item_compose_page.page.path = pfi_compose_path;
1522         folder_item_compose_page.page.create_widget = prefs_folder_item_compose_create_widget_func;
1523         folder_item_compose_page.page.destroy_widget = prefs_folder_item_compose_destroy_widget_func;
1524         folder_item_compose_page.page.save_page = prefs_folder_item_compose_save_func;
1525         
1526         prefs_folder_item_register_page((PrefsPage *) &folder_item_compose_page);
1527 }
1528
1529 static void register_templates_page(void)
1530 {
1531         static gchar *pfi_templates_path[2];
1532         static FolderItemTemplatesPage folder_item_templates_page;
1533
1534         pfi_templates_path[0] = _("Templates");
1535         pfi_templates_path[1] = NULL;
1536
1537         folder_item_templates_page.page.path = pfi_templates_path;
1538         folder_item_templates_page.page.create_widget = prefs_folder_item_templates_create_widget_func;
1539         folder_item_templates_page.page.destroy_widget = prefs_folder_item_templates_destroy_widget_func;
1540         folder_item_templates_page.page.save_page = prefs_folder_item_templates_save_func;
1541         
1542         prefs_folder_item_register_page((PrefsPage *) &folder_item_templates_page);
1543 }
1544
1545 static GSList *prefs_pages = NULL;
1546
1547 void prefs_folder_item_open(FolderItem *item)
1548 {
1549         gchar *id, *title;
1550         if (prefs_pages == NULL) {
1551                 register_general_page();
1552                 register_compose_page();
1553                 register_templates_page();
1554         }
1555
1556         if (item->path) {
1557                 id = folder_item_get_identifier (item);
1558                 can_save = TRUE;
1559         } else {
1560                 id = g_strdup(item->name);
1561                 can_save = FALSE;
1562         }
1563         title = g_strdup_printf (_("Properties for folder %s"), id);
1564         g_free (id);
1565         prefswindow_open(title, prefs_pages, item,
1566                         &prefs_common.folderitemwin_width, &prefs_common.folderitemwin_height);
1567         
1568         g_free (title);
1569 }
1570
1571 void prefs_folder_item_register_page(PrefsPage *page)
1572 {
1573         prefs_pages = g_slist_append(prefs_pages, page);
1574 }
1575
1576 void prefs_folder_item_unregister_page(PrefsPage *page)
1577 {
1578         prefs_pages = g_slist_remove(prefs_pages, page);
1579 }