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