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