287aad318eeca7061208def40e2c1a4f0f110c04
[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;
632         SpecialFolderItemType type = F_NORMAL;
633
634         if (folder->path == NULL)
635                 return;
636
637         cm_return_if_fail(prefs != NULL);
638
639         if (page->item == folder) 
640                 all = TRUE;
641
642         type = combobox_get_active_data(GTK_COMBO_BOX(page->folder_type));
643         if (all && folder->stype != type && page->item->parent_stype == F_NORMAL) {
644                 folder_item_change_type(folder, type);
645         }
646
647 #ifndef G_OS_WIN32
648         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->simplify_subject_rec_checkbtn))) {
649                 prefs->enable_simplify_subject =
650                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_simplify_subject));
651                 ASSIGN_STRING(prefs->simplify_subject_regexp,
652                               gtk_editable_get_chars(GTK_EDITABLE(page->entry_simplify_subject), 0, -1));
653         }
654 #endif  
655         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_chmod_rec_checkbtn))) {
656                 prefs->enable_folder_chmod = 
657                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_folder_chmod));
658                 buf = gtk_editable_get_chars(GTK_EDITABLE(page->entry_folder_chmod), 0, -1);
659                 prefs->folder_chmod = prefs_folder_item_chmod_mode(buf);
660                 g_free(buf);
661         }
662
663         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_color_rec_checkbtn))) {
664                 int old_color = prefs->color;
665                 prefs->color = page->folder_color;
666         
667                 /* update folder view */
668                 if (prefs->color != old_color)
669                         folder_item_update(folder, F_ITEM_UPDATE_MSGCNT);
670         }
671
672         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_processing_rec_checkbtn))) {
673                 prefs->enable_processing = 
674                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_processing));
675         }
676
677         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_processing_when_opening_rec_checkbtn))) {
678                 prefs->enable_processing_when_opening = 
679                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_processing_when_opening));
680         }
681
682         if (all ||  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->newmailcheck_rec_checkbtn))) {
683                 prefs->newmailcheck = 
684                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_newmailcheck));
685         }
686
687         if (all ||  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->offlinesync_rec_checkbtn))) {
688                 prefs->offlinesync = 
689                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_offlinesync));
690                 prefs->offlinesync_days = 
691                         atoi(gtk_entry_get_text(GTK_ENTRY(page->entry_offlinesync)));
692                 prefs->remove_old_bodies =
693                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_remove_old_offlinesync));
694         }
695
696         folder_item_prefs_save_config(folder);
697 }       
698
699 static gboolean general_save_recurse_func(GNode *node, gpointer data)
700 {
701         FolderItem *item = (FolderItem *) node->data;
702         FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
703
704         cm_return_val_if_fail(item != NULL, TRUE);
705         cm_return_val_if_fail(page != NULL, TRUE);
706
707         general_save_folder_prefs(item, page);
708
709         /* optimise by not continuing if none of the 'apply to sub folders'
710            check boxes are selected - and optimise the checking by only doing
711            it once */
712         if ((node == page->item->node) &&
713             !(
714 #ifndef G_OS_WIN32
715               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->simplify_subject_rec_checkbtn)) ||
716 #endif
717               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_chmod_rec_checkbtn)) ||
718               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->folder_color_rec_checkbtn)) ||
719               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_processing_rec_checkbtn)) ||
720               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_processing_when_opening_rec_checkbtn)) ||
721               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->newmailcheck_rec_checkbtn)) ||
722               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->offlinesync_rec_checkbtn))))
723                 return TRUE;
724         else 
725                 return FALSE;
726 }
727
728 static void prefs_folder_item_general_save_func(PrefsPage *page_) 
729 {
730         FolderItemGeneralPage *page = (FolderItemGeneralPage *) page_;
731
732         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
733                         -1, general_save_recurse_func, page);
734         
735         main_window_set_menu_sensitive(mainwindow_get_mainwindow());
736
737 }
738
739 static RecvProtocol item_protocol(FolderItem *item)
740 {
741         if (!item)
742                 return A_NONE;
743         if (!item->folder)
744                 return A_NONE;
745         if (!item->folder->account)
746                 return A_NONE;
747         return item->folder->account->protocol;
748 }
749
750 static void prefs_folder_item_compose_create_widget_func(PrefsPage * page_,
751                                                    GtkWindow * window,
752                                                    gpointer data)
753 {
754         FolderItemComposePage *page = (FolderItemComposePage *) page_;
755         FolderItem *item = (FolderItem *) data;
756         guint rowcount;
757         gchar *text = NULL;
758
759         GtkWidget *table;
760         GtkWidget *label;
761         
762         GtkWidget *no_save_warning = NULL;
763         GtkWidget *checkbtn_request_return_receipt = NULL;
764         GtkWidget *checkbtn_save_copy_to_folder = NULL;
765         GtkWidget *checkbtn_default_to = NULL;
766         GtkWidget *entry_default_to = NULL;
767         GtkWidget *checkbtn_default_reply_to = NULL;
768         GtkWidget *entry_default_reply_to = NULL;
769         GtkWidget *checkbtn_default_cc = NULL;
770         GtkWidget *entry_default_cc = NULL;
771         GtkWidget *checkbtn_default_bcc = NULL;
772         GtkWidget *entry_default_bcc = NULL;
773         GtkWidget *checkbtn_default_replyto = NULL;
774         GtkWidget *entry_default_replyto = NULL;
775         GtkWidget *checkbtn_enable_default_account = NULL;
776         GtkWidget *optmenu_default_account = NULL;
777         GtkListStore *optmenu_default_account_menu = NULL;
778         GtkTreeIter iter;
779 #if USE_ENCHANT
780         GtkWidget *checkbtn_enable_default_dictionary = NULL;
781         GtkWidget *combo_default_dictionary = NULL;
782         GtkWidget *checkbtn_enable_default_alt_dictionary = NULL;
783         GtkWidget *combo_default_alt_dictionary = NULL;
784         GtkWidget *default_dictionary_rec_checkbtn = NULL;
785         GtkWidget *default_alt_dictionary_rec_checkbtn = NULL;
786         gchar *dictionary;
787 #endif
788         GtkWidget *request_return_receipt_rec_checkbtn = NULL;
789         GtkWidget *save_copy_to_folder_rec_checkbtn = NULL;
790         GtkWidget *default_to_rec_checkbtn = NULL;
791         GtkWidget *default_reply_to_rec_checkbtn = NULL;
792         GtkWidget *default_cc_rec_checkbtn = NULL;
793         GtkWidget *default_bcc_rec_checkbtn = NULL;
794         GtkWidget *default_replyto_rec_checkbtn = NULL;
795         GtkWidget *default_account_rec_checkbtn = NULL;
796
797         GList *cur_ac;
798         GList *account_list;
799         PrefsAccount *ac_prefs;
800         gboolean default_account_set = FALSE;
801
802         page->item         = item;
803
804         /* Table */
805 #if USE_ENCHANT
806 # define TABLEHEIGHT 7
807 #else
808 # define TABLEHEIGHT 6
809 #endif
810         table = gtk_table_new(TABLEHEIGHT, 3, FALSE);
811         gtk_container_set_border_width (GTK_CONTAINER (table), VBOX_BORDER);
812         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
813         gtk_table_set_col_spacings(GTK_TABLE(table), 4);
814         rowcount = 0;
815
816         if (!can_save) {
817                 no_save_warning = gtk_label_new(
818                         _("<i>These preferences will not be saved as this folder "
819                         "is a top-level folder. However, you can set them for the "
820                         "whole mailbox tree by using \"Apply to subfolders\".</i>"));
821                 gtk_label_set_use_markup(GTK_LABEL(no_save_warning), TRUE);
822                 gtk_label_set_line_wrap(GTK_LABEL(no_save_warning), TRUE);
823                 gtk_misc_set_alignment(GTK_MISC(no_save_warning), 0.0, 0.5);
824                 gtk_table_attach(GTK_TABLE(table), no_save_warning, 0, 3,
825                          rowcount, rowcount + 1, GTK_FILL, 0, 0, 0);
826                 rowcount++;
827         }
828         
829         /* Apply to subfolders */
830         label = gtk_label_new(_("Apply to\nsubfolders"));
831         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
832         gtk_table_attach(GTK_TABLE(table), label, 2, 3,
833                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
834         rowcount++;
835
836         if (item_protocol(item) != A_NNTP) {
837                 /* Request Return Receipt */
838                 checkbtn_request_return_receipt = gtk_check_button_new_with_label
839                         (_("Request Return Receipt"));
840                 gtk_table_attach(GTK_TABLE(table), checkbtn_request_return_receipt, 
841                                  0, 2, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, 
842                                  GTK_FILL, 0, 0);
843                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_request_return_receipt),
844                                              item->ret_rcpt ? TRUE : FALSE);
845
846                 request_return_receipt_rec_checkbtn = gtk_check_button_new();
847                 gtk_table_attach(GTK_TABLE(table), request_return_receipt_rec_checkbtn, 2, 3, 
848                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
849
850                 rowcount++;
851
852                 /* Save Copy to Folder */
853                 checkbtn_save_copy_to_folder = gtk_check_button_new_with_label
854                         (_("Save copy of outgoing messages to this folder instead of Sent"));
855                 gtk_table_attach(GTK_TABLE(table), checkbtn_save_copy_to_folder, 0, 2, 
856                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
857                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_save_copy_to_folder),
858                                              item->prefs->save_copy_to_folder ? TRUE : FALSE);
859
860                 save_copy_to_folder_rec_checkbtn = gtk_check_button_new();
861                 gtk_table_attach(GTK_TABLE(table), save_copy_to_folder_rec_checkbtn, 2, 3, 
862                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
863
864                 rowcount++;
865
866                 /* Default To */
867                 text = g_strconcat(_("Default "), prefs_common_translated_header_name("To:"), NULL);
868                 checkbtn_default_to = gtk_check_button_new_with_label(text);
869                 gtk_table_attach(GTK_TABLE(table), checkbtn_default_to, 0, 1, 
870                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
871                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_to), 
872                                              item->prefs->enable_default_to);
873                 g_free(text);
874
875                 entry_default_to = gtk_entry_new();
876                 gtk_table_attach(GTK_TABLE(table), entry_default_to, 1, 2,
877                                  rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
878                 SET_TOGGLE_SENSITIVITY(checkbtn_default_to, entry_default_to);
879                 gtk_entry_set_text(GTK_ENTRY(entry_default_to), SAFE_STRING(item->prefs->default_to));
880                 address_completion_register_entry(GTK_ENTRY(entry_default_to),
881                                 TRUE);
882
883                 default_to_rec_checkbtn = gtk_check_button_new();
884                 gtk_table_attach(GTK_TABLE(table), default_to_rec_checkbtn, 2, 3, 
885                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
886
887                 rowcount++;
888
889                 /* Default address to reply to */
890                 text = g_strconcat(_("Default "), prefs_common_translated_header_name("To:"),
891                                  _(" for replies"), NULL);
892                 checkbtn_default_reply_to = gtk_check_button_new_with_label(text);
893                 gtk_table_attach(GTK_TABLE(table), checkbtn_default_reply_to, 0, 1, 
894                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
895                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_reply_to), 
896                                              item->prefs->enable_default_reply_to);
897                 g_free(text);
898
899                 entry_default_reply_to = gtk_entry_new();
900                 gtk_table_attach(GTK_TABLE(table), entry_default_reply_to, 1, 2,
901                                  rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
902                 SET_TOGGLE_SENSITIVITY(checkbtn_default_reply_to, entry_default_reply_to);
903                 gtk_entry_set_text(GTK_ENTRY(entry_default_reply_to), SAFE_STRING(item->prefs->default_reply_to));
904                 address_completion_register_entry(
905                                 GTK_ENTRY(entry_default_reply_to), TRUE);
906
907                 default_reply_to_rec_checkbtn = gtk_check_button_new();
908                 gtk_table_attach(GTK_TABLE(table), default_reply_to_rec_checkbtn, 2, 3, 
909                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
910
911                 rowcount++;
912
913                 /* Default Cc */
914                 text = g_strconcat(_("Default "), prefs_common_translated_header_name("Cc:"), NULL);
915                 checkbtn_default_cc = gtk_check_button_new_with_label(text);
916                 gtk_table_attach(GTK_TABLE(table), checkbtn_default_cc, 0, 1, 
917                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
918                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_cc), 
919                                              item->prefs->enable_default_cc);
920                 g_free(text);
921
922                 entry_default_cc = gtk_entry_new();
923                 gtk_table_attach(GTK_TABLE(table), entry_default_cc, 1, 2,
924                                  rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
925                 SET_TOGGLE_SENSITIVITY(checkbtn_default_cc, entry_default_cc);
926                 gtk_entry_set_text(GTK_ENTRY(entry_default_cc), SAFE_STRING(item->prefs->default_cc));
927                 address_completion_register_entry(GTK_ENTRY(entry_default_cc),
928                                 TRUE);
929
930                 default_cc_rec_checkbtn = gtk_check_button_new();
931                 gtk_table_attach(GTK_TABLE(table), default_cc_rec_checkbtn, 2, 3, 
932                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
933
934                 rowcount++;
935
936                 /* Default Bcc */
937                 text = g_strconcat(_("Default "), prefs_common_translated_header_name("Bcc:"), NULL);
938                 checkbtn_default_bcc = gtk_check_button_new_with_label(text);
939                 gtk_table_attach(GTK_TABLE(table), checkbtn_default_bcc, 0, 1, 
940                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
941                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_bcc), 
942                                              item->prefs->enable_default_bcc);
943                 g_free(text);
944
945                 entry_default_bcc = gtk_entry_new();
946                 gtk_table_attach(GTK_TABLE(table), entry_default_bcc, 1, 2,
947                                  rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
948                 SET_TOGGLE_SENSITIVITY(checkbtn_default_bcc, entry_default_bcc);
949                 gtk_entry_set_text(GTK_ENTRY(entry_default_bcc), SAFE_STRING(item->prefs->default_bcc));
950                 address_completion_register_entry(GTK_ENTRY(entry_default_bcc),
951                                 TRUE);
952
953                 default_bcc_rec_checkbtn = gtk_check_button_new();
954                 gtk_table_attach(GTK_TABLE(table), default_bcc_rec_checkbtn, 2, 3, 
955                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
956
957                 rowcount++;
958
959                 /* Default Reply-to */
960                 text = g_strconcat(_("Default "), prefs_common_translated_header_name("Reply-To:"), NULL);
961                 checkbtn_default_replyto = gtk_check_button_new_with_label(text);
962                 gtk_table_attach(GTK_TABLE(table), checkbtn_default_replyto, 0, 1, 
963                                  rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
964                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_replyto), 
965                                              item->prefs->enable_default_replyto);
966                 g_free(text);
967
968                 entry_default_replyto = gtk_entry_new();
969                 gtk_table_attach(GTK_TABLE(table), entry_default_replyto, 1, 2,
970                                  rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
971                 SET_TOGGLE_SENSITIVITY(checkbtn_default_replyto, entry_default_replyto);
972                 gtk_entry_set_text(GTK_ENTRY(entry_default_replyto), SAFE_STRING(item->prefs->default_replyto));
973                 address_completion_register_entry(GTK_ENTRY(entry_default_replyto),
974                                 TRUE);
975
976                 default_replyto_rec_checkbtn = gtk_check_button_new();
977                 gtk_table_attach(GTK_TABLE(table), default_replyto_rec_checkbtn, 2, 3, 
978                                  rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
979
980                 rowcount++;
981         }
982         /* Default account */
983         checkbtn_enable_default_account = gtk_check_button_new_with_label(_("Default account"));
984         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_account, 0, 1, 
985                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
986         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_account), 
987                                      item->prefs->enable_default_account);
988
989         optmenu_default_account = gtkut_sc_combobox_create(NULL, FALSE);
990         gtk_table_attach(GTK_TABLE(table), optmenu_default_account, 1, 2, 
991                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
992         optmenu_default_account_menu = GTK_LIST_STORE(
993                         gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu_default_account)));
994
995         account_list = account_get_list();
996         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
997                 ac_prefs = (PrefsAccount *)cur_ac->data;
998                 if (item->folder->account &&
999                     ( (item_protocol(item) == A_NNTP && ac_prefs->protocol != A_NNTP)
1000                     ||(item_protocol(item) != A_NNTP && ac_prefs->protocol == A_NNTP))) 
1001                         continue;
1002
1003                 if (item->folder->klass->type != F_NEWS && ac_prefs->protocol == A_NNTP)
1004                         continue;
1005
1006                 COMBOBOX_ADD_ESCAPED (optmenu_default_account_menu,
1007                                         ac_prefs->account_name?ac_prefs->account_name : _("Untitled"),
1008                                         ac_prefs->account_id);
1009
1010                 /* Set combobox to current default account id */
1011                 if (ac_prefs->account_id == item->prefs->default_account) {
1012                         combobox_select_by_data(GTK_COMBO_BOX(optmenu_default_account),
1013                                         ac_prefs->account_id);
1014                         default_account_set = TRUE;
1015                 }
1016         }
1017
1018         /* If nothing has been set (folder doesn't have a default account set),
1019          * pre-select global default account, since that's what actually used
1020          * anyway. We don't want nothing selected in combobox. */
1021         if( !default_account_set )
1022                 combobox_select_by_data(GTK_COMBO_BOX(optmenu_default_account),
1023                                 account_get_default()->account_id);
1024
1025         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_account, optmenu_default_account);
1026
1027         default_account_rec_checkbtn = gtk_check_button_new();
1028         gtk_table_attach(GTK_TABLE(table), default_account_rec_checkbtn, 2, 3, 
1029                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
1030         rowcount++;
1031
1032 #if USE_ENCHANT
1033         /* Default dictionary */
1034         checkbtn_enable_default_dictionary = gtk_check_button_new_with_label(_("Default dictionary"));
1035         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_dictionary, 0, 1,
1036                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
1037         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_dictionary),
1038                                      item->prefs->enable_default_dictionary);
1039
1040         combo_default_dictionary = gtkaspell_dictionary_combo_new(TRUE);
1041         gtk_table_attach(GTK_TABLE(table), combo_default_dictionary, 1, 2,
1042                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
1043
1044         dictionary = item->prefs->default_dictionary;
1045         if (dictionary && strrchr(dictionary, '/')) {
1046                 gchar *tmp = g_strdup(strrchr(dictionary, '/')+1);
1047                 g_free(item->prefs->default_dictionary);
1048                 item->prefs->default_dictionary = tmp;
1049                 dictionary = item->prefs->default_dictionary;
1050         }
1051         if (item->prefs->default_dictionary &&
1052             strchr(item->prefs->default_dictionary, '-')) {
1053                 *(strchr(item->prefs->default_dictionary, '-')) = '\0';
1054         }
1055         if (dictionary)
1056                 gtkaspell_set_dictionary_menu_active_item(
1057                         GTK_COMBO_BOX(combo_default_dictionary), dictionary);
1058
1059         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_dictionary, combo_default_dictionary);
1060
1061         default_dictionary_rec_checkbtn = gtk_check_button_new();
1062         gtk_table_attach(GTK_TABLE(table), default_dictionary_rec_checkbtn, 2, 3, 
1063                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
1064         
1065         rowcount++;
1066
1067         /* Default dictionary */
1068         checkbtn_enable_default_alt_dictionary = gtk_check_button_new_with_label(_("Default alternate dictionary"));
1069         gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_alt_dictionary, 0, 1,
1070                          rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
1071         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_alt_dictionary),
1072                                      item->prefs->enable_default_alt_dictionary);
1073
1074         combo_default_alt_dictionary = gtkaspell_dictionary_combo_new(FALSE);
1075         gtk_table_attach(GTK_TABLE(table), combo_default_alt_dictionary, 1, 2,
1076                          rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
1077
1078         dictionary = item->prefs->default_alt_dictionary;
1079         if (dictionary && strrchr(dictionary, '/')) {
1080                 gchar *tmp = g_strdup(strrchr(dictionary, '/')+1);
1081                 g_free(item->prefs->default_alt_dictionary);
1082                 item->prefs->default_alt_dictionary = tmp;
1083                 dictionary = item->prefs->default_alt_dictionary;
1084         }
1085         if (item->prefs->default_alt_dictionary &&
1086             strchr(item->prefs->default_alt_dictionary, '-')) {
1087                 *(strchr(item->prefs->default_alt_dictionary, '-')) = '\0';
1088         }
1089         if (dictionary)
1090                 gtkaspell_set_dictionary_menu_active_item(
1091                         GTK_COMBO_BOX(combo_default_alt_dictionary), dictionary);
1092
1093         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_alt_dictionary, combo_default_alt_dictionary);
1094
1095         default_alt_dictionary_rec_checkbtn = gtk_check_button_new();
1096         gtk_table_attach(GTK_TABLE(table), default_alt_dictionary_rec_checkbtn, 2, 3, 
1097                          rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
1098         
1099         rowcount++;
1100 #endif
1101
1102         gtk_widget_show_all(table);
1103
1104         page->window = GTK_WIDGET(window);
1105         page->table = table;
1106         page->no_save_warning = no_save_warning;
1107         page->checkbtn_request_return_receipt = checkbtn_request_return_receipt;
1108         page->checkbtn_save_copy_to_folder = checkbtn_save_copy_to_folder;
1109         page->checkbtn_default_to = checkbtn_default_to;
1110         page->entry_default_to = entry_default_to;
1111         page->checkbtn_default_reply_to = checkbtn_default_reply_to;
1112         page->entry_default_reply_to = entry_default_reply_to;
1113         page->checkbtn_default_cc = checkbtn_default_cc;
1114         page->entry_default_cc = entry_default_cc;
1115         page->checkbtn_default_bcc = checkbtn_default_bcc;
1116         page->entry_default_bcc = entry_default_bcc;
1117         page->checkbtn_default_replyto = checkbtn_default_replyto;
1118         page->entry_default_replyto = entry_default_replyto;
1119         page->checkbtn_enable_default_account = checkbtn_enable_default_account;
1120         page->optmenu_default_account = optmenu_default_account;
1121 #ifdef USE_ENCHANT
1122         page->checkbtn_enable_default_dictionary = checkbtn_enable_default_dictionary;
1123         page->combo_default_dictionary = combo_default_dictionary;
1124         page->checkbtn_enable_default_alt_dictionary = checkbtn_enable_default_alt_dictionary;
1125         page->combo_default_alt_dictionary = combo_default_alt_dictionary;
1126 #endif
1127
1128         page->request_return_receipt_rec_checkbtn = request_return_receipt_rec_checkbtn;
1129         page->save_copy_to_folder_rec_checkbtn    = save_copy_to_folder_rec_checkbtn;
1130         page->default_to_rec_checkbtn             = default_to_rec_checkbtn;
1131         page->default_reply_to_rec_checkbtn       = default_reply_to_rec_checkbtn;
1132         page->default_cc_rec_checkbtn             = default_cc_rec_checkbtn;
1133         page->default_bcc_rec_checkbtn            = default_bcc_rec_checkbtn;
1134         page->default_replyto_rec_checkbtn                = default_replyto_rec_checkbtn;
1135         page->default_account_rec_checkbtn        = default_account_rec_checkbtn;
1136 #if USE_ENCHANT
1137         page->default_dictionary_rec_checkbtn = default_dictionary_rec_checkbtn;
1138         page->default_alt_dictionary_rec_checkbtn = default_alt_dictionary_rec_checkbtn;
1139 #endif
1140
1141         page->page.widget = table;
1142 }
1143
1144 static void prefs_folder_item_compose_destroy_widget_func(PrefsPage *page_) 
1145 {
1146         FolderItemComposePage *page = (FolderItemComposePage *) page_;
1147
1148         if (page->entry_default_to)
1149                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_to));
1150         if (page->entry_default_reply_to)
1151                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_reply_to));
1152         if (page->entry_default_cc)
1153                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_cc));
1154         if (page->entry_default_bcc)
1155                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_bcc));
1156         if (page->entry_default_replyto)
1157                 address_completion_unregister_entry(GTK_ENTRY(page->entry_default_replyto));
1158 }
1159
1160 /** \brief  Save the prefs in page to folder.
1161  *
1162  *  If the folder is not the one  specified in page->item, then only those properties 
1163  *  that have the relevant 'apply to sub folders' button checked are saved
1164  */
1165 static void compose_save_folder_prefs(FolderItem *folder, FolderItemComposePage *page)
1166 {
1167         FolderItemPrefs *prefs = folder->prefs;
1168
1169         gboolean all = FALSE;
1170
1171         if (folder->path == NULL)
1172                 return;
1173
1174         if (page->item == folder) 
1175                 all = TRUE;
1176
1177         cm_return_if_fail(prefs != NULL);
1178
1179         if (item_protocol(folder) != A_NNTP) {
1180                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->request_return_receipt_rec_checkbtn))) {
1181                         prefs->request_return_receipt = 
1182                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_request_return_receipt));
1183                         /* MIGRATION */    
1184                         folder->ret_rcpt = prefs->request_return_receipt;
1185                 }
1186
1187                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_copy_to_folder_rec_checkbtn))) {
1188                         prefs->save_copy_to_folder = 
1189                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_save_copy_to_folder));
1190                 }
1191
1192                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_to_rec_checkbtn))) {
1193
1194                         prefs->enable_default_to = 
1195                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_to));
1196                         ASSIGN_STRING(prefs->default_to,
1197                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_to), 0, -1));
1198                 }
1199
1200                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_reply_to_rec_checkbtn))) {
1201                         prefs->enable_default_reply_to = 
1202                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_reply_to));
1203                         ASSIGN_STRING(prefs->default_reply_to,
1204                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_reply_to), 0, -1));
1205                 }
1206
1207                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_cc_rec_checkbtn))) {
1208
1209                         prefs->enable_default_cc = 
1210                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_cc));
1211                         ASSIGN_STRING(prefs->default_cc,
1212                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_cc), 0, -1));
1213                 }
1214
1215                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_bcc_rec_checkbtn))) {
1216
1217                         prefs->enable_default_bcc = 
1218                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_bcc));
1219                         ASSIGN_STRING(prefs->default_bcc,
1220                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_bcc), 0, -1));
1221                 }
1222
1223                 if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_replyto_rec_checkbtn))) {
1224
1225                         prefs->enable_default_replyto = 
1226                                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_default_replyto));
1227                         ASSIGN_STRING(prefs->default_replyto,
1228                                       gtk_editable_get_chars(GTK_EDITABLE(page->entry_default_replyto), 0, -1));
1229                 }
1230
1231         } else {
1232                 prefs->request_return_receipt = FALSE;
1233                 prefs->save_copy_to_folder = FALSE;
1234                 prefs->enable_default_to = FALSE;
1235                 prefs->enable_default_reply_to = FALSE;
1236                 prefs->enable_default_cc = FALSE;
1237                 prefs->enable_default_bcc = FALSE;
1238                 prefs->enable_default_replyto = FALSE;
1239         }
1240
1241         if (all || gtk_toggle_button_get_active(
1242                                 GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn))) {
1243                 prefs->enable_default_account = 
1244                         gtk_toggle_button_get_active(
1245                                         GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_account));
1246                 prefs->default_account = combobox_get_active_data(
1247                                 GTK_COMBO_BOX(page->optmenu_default_account));
1248         }
1249
1250 #if USE_ENCHANT
1251         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn))) {
1252                 prefs->enable_default_dictionary =
1253                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_dictionary));
1254                 ASSIGN_STRING(prefs->default_dictionary,
1255                               gtkaspell_get_dictionary_menu_active_item(
1256                                         GTK_COMBO_BOX(page->combo_default_dictionary)));
1257         }
1258         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_alt_dictionary_rec_checkbtn))) {
1259                 prefs->enable_default_alt_dictionary =
1260                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_enable_default_alt_dictionary));
1261                 ASSIGN_STRING(prefs->default_alt_dictionary,
1262                               gtkaspell_get_dictionary_menu_active_item(
1263                                       GTK_COMBO_BOX(page->combo_default_alt_dictionary)));
1264         }
1265 #endif
1266
1267         folder_item_prefs_save_config(folder);
1268 }       
1269
1270 static gboolean compose_save_recurse_func(GNode *node, gpointer data)
1271 {
1272         FolderItem *item = (FolderItem *) node->data;
1273         FolderItemComposePage *page = (FolderItemComposePage *) data;
1274
1275         cm_return_val_if_fail(item != NULL, TRUE);
1276         cm_return_val_if_fail(page != NULL, TRUE);
1277
1278         compose_save_folder_prefs(item, page);
1279
1280         /* optimise by not continuing if none of the 'apply to sub folders'
1281            check boxes are selected - and optimise the checking by only doing
1282            it once */
1283         if ((node == page->item->node) && item_protocol(item) != A_NNTP &&
1284             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->request_return_receipt_rec_checkbtn)) ||
1285               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_copy_to_folder_rec_checkbtn)) ||
1286               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_to_rec_checkbtn)) ||
1287               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn)) ||
1288               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_cc_rec_checkbtn)) ||
1289               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_bcc_rec_checkbtn)) ||
1290               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_replyto_rec_checkbtn)) ||
1291 #if USE_ENCHANT
1292               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn)) ||
1293               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_alt_dictionary_rec_checkbtn)) ||
1294 #endif
1295               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_reply_to_rec_checkbtn))
1296                         ))
1297                 return TRUE;
1298         else if ((node == page->item->node) && item_protocol(item) == A_NNTP &&
1299             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_account_rec_checkbtn)) 
1300 #if USE_ENCHANT
1301               || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_dictionary_rec_checkbtn))
1302               || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->default_alt_dictionary_rec_checkbtn))
1303 #endif
1304                     ))
1305                 return TRUE;
1306         else 
1307                 return FALSE;
1308 }
1309
1310 static void prefs_folder_item_compose_save_func(PrefsPage *page_) 
1311 {
1312         FolderItemComposePage *page = (FolderItemComposePage *) page_;
1313
1314         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
1315                         -1, compose_save_recurse_func, page);
1316
1317 }
1318
1319 static void prefs_folder_item_templates_create_widget_func(PrefsPage * page_,
1320                                                    GtkWindow * window,
1321                                                    gpointer data)
1322 {
1323         FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) page_;
1324         FolderItem *item = (FolderItem *) data;
1325
1326         GtkWidget *notebook;
1327         GtkWidget *vbox;
1328         GtkWidget *page_vbox;
1329         GtkWidget *no_save_warning;
1330         GtkWidget *new_msg_format_rec_checkbtn;
1331         GtkWidget *reply_format_rec_checkbtn;
1332         GtkWidget *forward_format_rec_checkbtn;
1333         GtkWidget *hbox;
1334         GtkWidget *vbox_format;
1335         
1336         page->item = item;
1337
1338         page_vbox = gtk_vbox_new (FALSE, 0);
1339         gtk_widget_show (page_vbox);
1340         
1341         if (!can_save) {
1342                 no_save_warning = gtk_label_new(
1343                         _("<i>These preferences will not be saved as this folder "
1344                         "is a top-level folder. However, you can set them for the "
1345                         "whole mailbox tree by using \"Apply to subfolders\".</i>"));
1346                 gtk_label_set_use_markup(GTK_LABEL(no_save_warning), TRUE);
1347                 gtk_label_set_line_wrap(GTK_LABEL(no_save_warning), TRUE);
1348                 gtk_misc_set_alignment(GTK_MISC(no_save_warning), 0.0, 0.5);
1349                 gtk_box_pack_start(GTK_BOX(page_vbox), no_save_warning, FALSE, FALSE, 4);
1350         }
1351
1352         /* Notebook */
1353         notebook = gtk_notebook_new();
1354         gtk_widget_show(notebook);
1355         gtk_box_pack_start(GTK_BOX(page_vbox), notebook, TRUE, TRUE, 0);
1356
1357         /* compose format */
1358         vbox = gtk_vbox_new (FALSE, VSPACING);
1359         gtk_widget_show (vbox);
1360         gtk_container_set_border_width (GTK_CONTAINER (vbox), VBOX_BORDER);
1361
1362         quotefmt_create_new_msg_fmt_widgets(
1363                                 window,
1364                                 vbox,
1365                                 &page->checkbtn_compose_with_format,
1366                                 &page->compose_override_from_format,
1367                                 &page->compose_subject_format,
1368                                 &page->compose_body_format,
1369                                 FALSE, FALSE);
1370         address_completion_register_entry(GTK_ENTRY(page->compose_override_from_format),
1371                         TRUE);
1372         
1373         vbox_format = gtk_widget_get_parent(
1374                         gtk_widget_get_parent(page->compose_body_format));
1375
1376         hbox = gtk_hbox_new (FALSE, 0);
1377         gtk_box_pack_end (GTK_BOX(vbox_format), hbox, FALSE, FALSE, 0);
1378         quotefmt_add_info_button(window, hbox);
1379         
1380         new_msg_format_rec_checkbtn = gtk_check_button_new_with_label(
1381                         _("Apply to subfolders"));
1382         gtk_box_pack_end (GTK_BOX(hbox), new_msg_format_rec_checkbtn, FALSE, FALSE, 0);
1383         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, gtk_label_new(_("Compose")));
1384
1385         /* reply format */
1386         vbox = gtk_vbox_new (FALSE, VSPACING);
1387         gtk_widget_show (vbox);
1388         gtk_container_set_border_width (GTK_CONTAINER (vbox), VBOX_BORDER);
1389
1390         quotefmt_create_reply_fmt_widgets(
1391                                 window,
1392                                 vbox,
1393                                 &page->checkbtn_reply_with_format,
1394                                 &page->reply_override_from_format,
1395                                 &page->reply_quotemark,
1396                                 &page->reply_body_format,
1397                                 FALSE, FALSE);
1398         address_completion_register_entry(GTK_ENTRY(page->reply_override_from_format),
1399                         TRUE);
1400
1401         vbox_format = gtk_widget_get_parent(
1402                         gtk_widget_get_parent(page->reply_body_format));
1403
1404         hbox = gtk_hbox_new (FALSE, 0);
1405         gtk_box_pack_end (GTK_BOX(vbox_format), hbox, FALSE, FALSE, 0);
1406         quotefmt_add_info_button(window, hbox);
1407
1408         reply_format_rec_checkbtn = gtk_check_button_new_with_label(
1409                         _("Apply to subfolders"));
1410         gtk_box_pack_end (GTK_BOX(hbox), reply_format_rec_checkbtn, FALSE, FALSE, 0);
1411         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, gtk_label_new(_("Reply")));
1412
1413         /* forward format */
1414         vbox = gtk_vbox_new (FALSE, VSPACING);
1415         gtk_widget_show (vbox);
1416         gtk_container_set_border_width (GTK_CONTAINER (vbox), VBOX_BORDER);
1417
1418         quotefmt_create_forward_fmt_widgets(
1419                                 window,
1420                                 vbox,
1421                                 &page->checkbtn_forward_with_format,
1422                                 &page->forward_override_from_format,
1423                                 &page->forward_quotemark,
1424                                 &page->forward_body_format,
1425                                 FALSE, FALSE);
1426         address_completion_register_entry(GTK_ENTRY(page->forward_override_from_format),
1427                         TRUE);
1428
1429         vbox_format = gtk_widget_get_parent(
1430                         gtk_widget_get_parent(page->forward_body_format));
1431
1432         hbox = gtk_hbox_new (FALSE, 0);
1433         gtk_box_pack_end (GTK_BOX(vbox_format), hbox, FALSE, FALSE, 0);
1434         quotefmt_add_info_button(window, hbox);
1435
1436         forward_format_rec_checkbtn = gtk_check_button_new_with_label(
1437                         _("Apply to subfolders"));
1438         gtk_box_pack_end (GTK_BOX(hbox), forward_format_rec_checkbtn, FALSE, FALSE, 0);
1439         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, gtk_label_new(_("Forward")));
1440
1441         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->checkbtn_compose_with_format),
1442                         item->prefs->compose_with_format);
1443         pref_set_entry_from_pref(GTK_ENTRY(page->compose_override_from_format),
1444                         item->prefs->compose_override_from_format);
1445         pref_set_entry_from_pref(GTK_ENTRY(page->compose_subject_format),
1446                         item->prefs->compose_subject_format);
1447         pref_set_textview_from_pref(GTK_TEXT_VIEW(page->compose_body_format),
1448                         item->prefs->compose_body_format);
1449
1450         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->checkbtn_reply_with_format),
1451                         item->prefs->reply_with_format);
1452         pref_set_entry_from_pref(GTK_ENTRY(page->reply_quotemark),
1453                         item->prefs->reply_quotemark);
1454         pref_set_entry_from_pref(GTK_ENTRY(page->reply_override_from_format),
1455                         item->prefs->reply_override_from_format);
1456         pref_set_textview_from_pref(GTK_TEXT_VIEW(page->reply_body_format),
1457                         item->prefs->reply_body_format);
1458
1459         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_with_format),
1460                         item->prefs->forward_with_format);
1461         pref_set_entry_from_pref(GTK_ENTRY(page->forward_quotemark),
1462                         item->prefs->forward_quotemark);
1463         pref_set_entry_from_pref(GTK_ENTRY(page->forward_override_from_format),
1464                         item->prefs->forward_override_from_format);
1465         pref_set_textview_from_pref(GTK_TEXT_VIEW(page->forward_body_format),
1466                         item->prefs->forward_body_format);
1467
1468         gtk_widget_show_all(page_vbox);
1469
1470         page->window = GTK_WIDGET(window);
1471
1472         page->new_msg_format_rec_checkbtn = new_msg_format_rec_checkbtn;
1473         page->reply_format_rec_checkbtn = reply_format_rec_checkbtn;
1474         page->forward_format_rec_checkbtn = forward_format_rec_checkbtn;
1475
1476         page->page.widget = page_vbox;
1477 }
1478
1479 static void prefs_folder_item_templates_destroy_widget_func(PrefsPage *page_) 
1480 {
1481         FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) page_;
1482
1483         if (page->compose_override_from_format)
1484                 address_completion_unregister_entry(GTK_ENTRY(page->compose_override_from_format));             
1485         if (page->reply_override_from_format)
1486                 address_completion_unregister_entry(GTK_ENTRY(page->reply_override_from_format));               
1487         if (page->forward_override_from_format)
1488                 address_completion_unregister_entry(GTK_ENTRY(page->forward_override_from_format));             
1489 }
1490
1491 /** \brief  Save the prefs in page to folder.
1492  *
1493  *  If the folder is not the one  specified in page->item, then only those properties 
1494  *  that have the relevant 'apply to sub folders' button checked are saved
1495  */
1496 static void templates_save_folder_prefs(FolderItem *folder, FolderItemTemplatesPage *page)
1497 {
1498         FolderItemPrefs *prefs = folder->prefs;
1499         gboolean all = FALSE;
1500
1501         if (folder->path == NULL)
1502                 return;
1503
1504         if (page->item == folder) 
1505                 all = TRUE;
1506
1507         cm_return_if_fail(prefs != NULL);
1508
1509         /* save and check formats */
1510
1511         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->new_msg_format_rec_checkbtn))) {
1512                 
1513                 prefs->compose_with_format =
1514                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_compose_with_format));
1515                 prefs->compose_override_from_format = pref_get_pref_from_entry(
1516                                 GTK_ENTRY(page->compose_override_from_format));
1517                 prefs->compose_subject_format = pref_get_pref_from_entry(
1518                                 GTK_ENTRY(page->compose_subject_format));
1519                 prefs->compose_body_format = pref_get_pref_from_textview(
1520                                 GTK_TEXT_VIEW(page->compose_body_format));
1521                 quotefmt_check_new_msg_formats(prefs->compose_with_format,
1522                                                 prefs->compose_override_from_format,
1523                                                 prefs->compose_subject_format,
1524                                                 prefs->compose_body_format);
1525         }
1526
1527         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->reply_format_rec_checkbtn))) {
1528                 prefs->reply_with_format =
1529                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_reply_with_format));
1530                 prefs->reply_quotemark = gtk_editable_get_chars(
1531                                 GTK_EDITABLE(page->reply_quotemark), 0, -1);
1532                 prefs->reply_override_from_format = pref_get_pref_from_entry(
1533                                 GTK_ENTRY(page->reply_override_from_format));
1534                 prefs->reply_body_format = pref_get_pref_from_textview(
1535                                 GTK_TEXT_VIEW(page->reply_body_format));
1536                 quotefmt_check_reply_formats(prefs->reply_with_format,
1537                                                                                 prefs->reply_override_from_format,
1538                                                                                 prefs->reply_quotemark,
1539                                                                                 prefs->reply_body_format);
1540         }
1541
1542         if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->forward_format_rec_checkbtn))) {
1543                 prefs->forward_with_format =
1544                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_forward_with_format));
1545                 prefs->forward_quotemark = gtk_editable_get_chars(
1546                                 GTK_EDITABLE(page->forward_quotemark), 0, -1);
1547                 prefs->forward_override_from_format = pref_get_pref_from_entry(
1548                                 GTK_ENTRY(page->forward_override_from_format));
1549                 prefs->forward_body_format = pref_get_pref_from_textview(
1550                                 GTK_TEXT_VIEW(page->forward_body_format));
1551                 quotefmt_check_forward_formats(prefs->forward_with_format,
1552                                                                                 prefs->forward_override_from_format,
1553                                                                                 prefs->forward_quotemark,
1554                                                                                 prefs->forward_body_format);
1555         }
1556
1557         folder_item_prefs_save_config(folder);
1558 }       
1559
1560 static gboolean templates_save_recurse_func(GNode *node, gpointer data)
1561 {
1562         FolderItem *item = (FolderItem *) node->data;
1563         FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) data;
1564
1565         cm_return_val_if_fail(item != NULL, TRUE);
1566         cm_return_val_if_fail(page != NULL, TRUE);
1567
1568         templates_save_folder_prefs(item, page);
1569
1570         /* optimise by not continuing if none of the 'apply to sub folders'
1571            check boxes are selected - and optimise the checking by only doing
1572            it once */
1573         if ((node == page->item->node) &&
1574             !(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->new_msg_format_rec_checkbtn)) ||
1575               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->reply_format_rec_checkbtn)) ||
1576               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->forward_format_rec_checkbtn))))
1577                 return TRUE;
1578         else 
1579                 return FALSE;
1580
1581         return FALSE;
1582 }
1583
1584 static void prefs_folder_item_templates_save_func(PrefsPage *page_) 
1585 {
1586         FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) page_;
1587
1588         g_node_traverse(page->item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
1589                         -1, templates_save_recurse_func, page);
1590
1591 }
1592
1593 static gint prefs_folder_item_chmod_mode(gchar *folder_chmod) 
1594 {
1595         gint newmode = 0;
1596         gchar *tmp;
1597
1598         if (folder_chmod) {
1599                 newmode = strtol(folder_chmod, &tmp, 8);
1600                 if (!(*(folder_chmod) && !(*tmp)))
1601                         newmode = 0;
1602         }
1603
1604         return newmode;
1605 }
1606
1607 static void folder_color_set_dialog(GtkWidget *widget, gpointer data)
1608 {
1609         FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
1610         gint rgbcolor;
1611
1612         rgbcolor = colorsel_select_color_rgb(_("Pick color for folder"), 
1613                                              page->folder_color);
1614         gtkut_set_widget_bgcolor_rgb(page->folder_color_btn, rgbcolor);
1615         page->folder_color = rgbcolor;
1616 }
1617
1618 static void clean_cache_cb(GtkWidget *widget, gpointer data)
1619 {
1620         FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
1621         FolderItem *item = page->item;
1622         gboolean was_open = FALSE;
1623         FolderView *folderview = NULL;
1624
1625         if (alertpanel_full(_("Discard cache"), 
1626                             _("Do you really want to discard the local cached "
1627                               "data for this folder?"),
1628                                  GTK_STOCK_CANCEL, _("+Discard"), NULL, FALSE,
1629                                  NULL, ALERT_WARNING, G_ALERTDEFAULT)
1630                 != G_ALERTALTERNATE)
1631                 return;
1632         
1633         if (mainwindow_get_mainwindow())
1634                 folderview = mainwindow_get_mainwindow()->folderview;
1635
1636         if (folderview && item->opened) {
1637                 folderview_close_opened(folderview);
1638                 was_open = TRUE;
1639         }
1640         folder_item_discard_cache(item);
1641         if (was_open)
1642                 folderview_select(folderview,item);
1643 }
1644
1645 #ifndef G_OS_WIN32
1646 static regex_t *summary_compile_simplify_regexp(gchar *simplify_subject_regexp)
1647 {
1648         int err;
1649         gchar buf[BUFFSIZE];
1650         regex_t *preg = NULL;
1651
1652         preg = g_new0(regex_t, 1);
1653
1654         err = string_match_precompile(simplify_subject_regexp, 
1655                                       preg, REG_EXTENDED);
1656         if (err) {
1657                 regerror(err, preg, buf, BUFFSIZE);
1658                 g_free(preg);
1659                 preg = NULL;
1660         }
1661
1662         return preg;
1663 }
1664
1665 static void folder_regexp_test_cb(GtkWidget *widget, gpointer data)
1666 {
1667 #if !GTK_CHECK_VERSION(3, 0, 0)
1668         static GdkColor red;
1669         static gboolean colors_initialised = FALSE;
1670 #else
1671         static GdkColor red = { (guint32)0, (guint16)0xff, (guint16)0x70, (guint16)0x70 };
1672 #endif
1673         static gchar buf[BUFFSIZE];
1674         FolderItemGeneralPage *page = (FolderItemGeneralPage *)data;
1675         gchar *test_string, *regexp;
1676         regex_t *preg;
1677
1678         regexp = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->entry_simplify_subject)));
1679         test_string = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->entry_regexp_test_string)));
1680
1681         if (!regexp || !regexp[0]) {
1682                 gtk_widget_modify_base(page->entry_simplify_subject,
1683                                 GTK_STATE_NORMAL, NULL);
1684                 if (test_string)
1685                         gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_result), test_string);
1686                         
1687                 g_free(test_string);
1688                 g_free(regexp);
1689                 return;
1690         }
1691
1692         if (!test_string || !test_string[0]) {
1693                 g_free(test_string);
1694                 g_free(regexp);
1695                 return;
1696         }
1697
1698 #if !GTK_CHECK_VERSION(3, 0, 0)
1699         if (!colors_initialised) {
1700                 gdk_color_parse("#ff7070", &red);
1701                 colors_initialised = gdk_colormap_alloc_color(
1702                         gdk_colormap_get_system(), &red, FALSE, TRUE);
1703         }
1704 #endif
1705
1706         preg = summary_compile_simplify_regexp(regexp);
1707 #if !GTK_CHECK_VERSION(3, 0, 0)
1708         if (colors_initialised)
1709                 gtk_widget_modify_base(page->entry_simplify_subject,
1710                                 GTK_STATE_NORMAL, preg ? NULL : &red);
1711 #endif
1712
1713         if (preg != NULL) {
1714                 string_remove_match(buf, BUFFSIZE, test_string, preg);
1715
1716                 gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_result), buf);
1717
1718                 regfree(preg);
1719                 g_free(preg);
1720         }
1721
1722         g_free(test_string);
1723         g_free(regexp);
1724 }
1725
1726 static gchar *folder_regexp_get_subject_example(void)
1727 {
1728         MsgInfo *msginfo_selected;
1729         SummaryView *summaryview = NULL;
1730
1731         if (!mainwindow_get_mainwindow())
1732                 return NULL;
1733         summaryview = mainwindow_get_mainwindow()->summaryview;
1734
1735         msginfo_selected = summary_get_selected_msg(summaryview);
1736         return msginfo_selected ? g_strdup(msginfo_selected->subject) : NULL;
1737 }
1738
1739 static void folder_regexp_set_subject_example_cb(GtkWidget *widget, gpointer data)
1740 {
1741         FolderItemGeneralPage *page = (FolderItemGeneralPage *)data;
1742
1743         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_simplify_subject))) {
1744                 gchar *subject = folder_regexp_get_subject_example();
1745                 if (subject) {
1746                         gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_string), subject);
1747                         g_free(subject);
1748                 }
1749         }
1750 }
1751 #endif
1752 static void register_general_page()
1753 {
1754         static gchar *pfi_general_path[3];
1755         static FolderItemGeneralPage folder_item_general_page;
1756
1757         pfi_general_path[0] = _("Folder");
1758         pfi_general_path[1] = _("General");
1759         pfi_general_path[2] = NULL;
1760
1761         folder_item_general_page.page.path = pfi_general_path;
1762         folder_item_general_page.page.create_widget = prefs_folder_item_general_create_widget_func;
1763         folder_item_general_page.page.destroy_widget = prefs_folder_item_general_destroy_widget_func;
1764         folder_item_general_page.page.save_page = prefs_folder_item_general_save_func;
1765         
1766         prefs_folder_item_register_page((PrefsPage *) &folder_item_general_page);
1767 }
1768
1769
1770 static void register_compose_page(void)
1771 {
1772         static gchar *pfi_compose_path[3];
1773         static FolderItemComposePage folder_item_compose_page;
1774
1775         pfi_compose_path[0] = _("Folder");
1776         pfi_compose_path[1] = _("Compose");
1777         pfi_compose_path[2] = NULL;
1778
1779         folder_item_compose_page.page.path = pfi_compose_path;
1780         folder_item_compose_page.page.create_widget = prefs_folder_item_compose_create_widget_func;
1781         folder_item_compose_page.page.destroy_widget = prefs_folder_item_compose_destroy_widget_func;
1782         folder_item_compose_page.page.save_page = prefs_folder_item_compose_save_func;
1783         
1784         prefs_folder_item_register_page((PrefsPage *) &folder_item_compose_page);
1785 }
1786
1787 static void register_templates_page(void)
1788 {
1789         static gchar *pfi_templates_path[3];
1790         static FolderItemTemplatesPage folder_item_templates_page;
1791
1792         pfi_templates_path[0] = _("Folder");
1793         pfi_templates_path[1] = _("Templates");
1794         pfi_templates_path[2] = NULL;
1795
1796         folder_item_templates_page.page.path = pfi_templates_path;
1797         folder_item_templates_page.page.create_widget = prefs_folder_item_templates_create_widget_func;
1798         folder_item_templates_page.page.destroy_widget = prefs_folder_item_templates_destroy_widget_func;
1799         folder_item_templates_page.page.save_page = prefs_folder_item_templates_save_func;
1800         
1801         prefs_folder_item_register_page((PrefsPage *) &folder_item_templates_page);
1802 }
1803
1804 static GSList *prefs_pages = NULL;
1805
1806 static void prefs_folder_item_address_completion_start(GtkWindow * window)
1807 {
1808         address_completion_start(GTK_WIDGET(window));
1809 }
1810
1811 static void prefs_folder_item_address_completion_end(GtkWindow * window)
1812 {
1813         address_completion_end(GTK_WIDGET(window));
1814 }
1815
1816 void prefs_folder_item_open(FolderItem *item)
1817 {
1818         gchar *id, *title;
1819         if (prefs_pages == NULL) {
1820                 register_general_page();
1821                 register_compose_page();
1822                 register_templates_page();
1823         }
1824
1825         if (item->path) {
1826                 id = folder_item_get_identifier (item);
1827                 can_save = TRUE;
1828         } else {
1829                 id = g_strdup(item->name);
1830                 can_save = FALSE;
1831         }
1832         title = g_strdup_printf (_("Properties for folder %s"), id);
1833         g_free (id);
1834         prefswindow_open(title, prefs_pages, item,
1835                         &prefs_common.folderitemwin_width, &prefs_common.folderitemwin_height,
1836                         prefs_folder_item_address_completion_start,
1837                         prefs_folder_item_address_completion_end);
1838
1839         g_free (title);
1840 }
1841
1842 static void prefs_folder_item_register_page(PrefsPage *page)
1843 {
1844         prefs_pages = g_slist_append(prefs_pages, page);
1845 }