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