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