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