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