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