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