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