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